Hacker News new | past | comments | ask | show | jobs | submit login

Your fix requires a lot of mental CPU cycles on the part of whoever reads the code. Are you sure it wouldn't have been better to do it the simple, obvious way?

   double a = *(double *) dpa;   
   double b = *(double *) dpb;

   if (a > b) return 1;
   if (b < a) return -1;
   return 0;



Oh my gosh ... the fortran computed goto is back ... See http://www.lahey.com/docs/lfprohelp/F95ARComputed_GOTOStmt.h...


Yup I think you are right -- the (fixed) code is very obscure now.


I think it's actually quite elegant. The issue is that it always does two comparisons, even when one would suffice.


Depending on how the compiler computes a>b, it may be branchless, though, and I expect that to be more important on modern CPUs.


That code returns 0 for all NaN inputs.


True enough, but if you're passing NaNs to qsort(), something has already gone wrong in your professional life.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: