Mail Archives: djgpp/2000/01/25/10:56:58
Hans-Bernhard Broeker wrote:
> > 2) did a "fuzzy" sort with a "fuzzy" comparison function.
>
> But that wouldn't be 'sorting' any longer. Not even to mention that
> anno domini 1989, I don't think the 'fuzzy' hype had already
> happened...
By "fuzzy" I mean that the order of two elements in the sorted array is
unspecified if they are close to the same value, but properly-sorted
otherwise.
> Just some minor comments regarding that comparison function you show:
>
> > x = atof((const char *) a);
> > y = atof((const char *) b);
>
> Bad idea. atof()ing the same string more than once is a waste of time
> and effort.
I agree that it's suboptimal from the standpoint of execution time, but it
avoids having to declare a separate array to hold the floating-point
values.
> And, of course, the potential of getting the comparison wrong would
> become smaller without the atof() calls, too.
According to the ANSI standard (as far as I can tell), neither approach
would be guaranteed to work. I may bring this up in comp.std.c, because I
can't see any way to write a strictly-conforming routine that uses qsort
to sort floating-point values.
However, over the weekend I found that the current DJGPP qsort works just
fine even in the presence of an inexact comparison routine. (See my other
posting in this thread.)
-Eric Rudd
rudd AT cyberoptics DOT com
- Raw text -