Package: manpages-dev Version: 2.22-1 Severity: wishlist Tags: upstream patch
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; assert(x==y); return 0; } int main(int argc, char *argv[]) { int i; double *fp; if (argc==1) { fprintf(stderr, "Usage: %s <val>...\n", argv[0]); exit(EXIT_FAILURE); } else if ((fp=malloc((argc-1)*sizeof(*fp)))==NULL) { perror("malloc"); exit(EXIT_FAILURE); } for (i=1; i<argc; i++) fp[i-1]=strtod(argv[i], NULL); qsort(fp, argc-1, sizeof(*fp), &fpcomp); for (i=0; i<argc-1; i++) printf("%lf\n", fp[i]); free(fp); exit(EXIT_SUCCESS); } -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]