Justin,

> > What man page is this intended for?
> qsort()
> 
> > > Included is a sample program that demonstrates how to sort IEEE
> > > floating point values, including NAN and friends, in a useful way;
> > > please consider including it.
> > > 
> > > // make CFLAGS='-W -Wall -O3 -g -std=gnu99' LDFLAGS=-lm fpnansort
> > > #include <math.h>
> > > #include <stdlib.h>
> > > #include <stdio.h>
> > > #include <assert.h>
> > > 
> > > int fpcomp(const void *a, const void *b)
> > > {
> > >         double x=*(double *)a,
> > >                y=*(double *)b;
> > > 
> > >         if (x<y) return -1;
> > >         else if (x>y) return 1;
> > >         // The not-normal values will be grouped together, but
> > >         // otherwise unordered:
> > >         else if (!isnormal(x)) return 1;
> > >         else if (!isnormal(y)) return -1;
> > 
> > Why isnormal()?  
> "Why not" ?
> 
> Seriously, I want all the IEEE special number foo to get out of my
> way, and this does wha tI want.

Do you realise that "!isnormal(0.0) == 1"?
What happens when you compare 0.0 with 0.0?

> > >         assert(x==y);
> > 
> > What is assert doing here?
> Well, the current qsort() example uses assert() on argc, so why not?

The context is different: one kills the program because it
got bad arguments.  The other kills the quicksort because
the comparison function encountered a case that it didn't expect.
It just looks a bit strange is all.

> Seriously, I *think* that x==y is guaranteed, since x and y are both
> "normal" values, but there might be other special cases of which I'm
> not even aware; this is as way of checking for them, and at the same
> time indicating my intent.  (Actually, "subnormal" may just be that
> case .. will think about it.)

I'm *not at all* convinced that including an example like this is 
appropriate for the qsort man page: it isn't the place to teach
about floating point numbers.

Cheers,

Michael

-- 
Michael Kerrisk
maintainer of Linux man pages Sections 2, 3, 4, 5, and 7 

Want to help with man page maintenance?  
Grab the latest tarball at
ftp://ftp.win.tue.nl/pub/linux-local/manpages/, 
read the HOWTOHELP file and grep the source 
files for 'FIXME'.


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to