Floating Point Sort Order
Floating Point Sort Order

Order records by converting the text to floating point values and comparing the resulting values.


Import xstrtod()
Imported declaration
Segment Source
  37: #include "xstrtod.h"
  38: 

Declare general numeric ordering field (general_numeric)
Field declaration
Segment Source
 116:   int general_numeric;          /* Flag for general, numeric comparison.
 117:                                    Handle numbers in exponential notation. */

Insert user message text
Text insertion
Segment Source
 225:   -g               compare according to general numerical value, imply -b\n\

Define general_numcompare()
Function definition
Segment Source
 937: static int
 938: general_numcompare (const char *sa, const char *sb)
 939: {
 940:   double a, b;
 941:   /* FIXME: add option to warn about failed conversions.  */
 942:   /* FIXME: maybe add option to try expensive FP conversion
 943:      only if A and B can't be compared more cheaply/accurately.  */
 944:   if (xstrtod (sa, NULL, &a))
 945:     {
 946:       a = 0;
 947:     }
 948:   if (xstrtod (sb, NULL, &b))
 949:     {
 950:       b = 0;
 951:     }
 952:   return a == b ? 0 : a < b ? -1 : 1;
 953: }
 954: 

Dispatch numeric comparison
Code insertion
Segment Source
1066:       else if (key->general_numeric)
1067:         {
1068:           if (*lima || *limb)
1069:             {
1070:               char savea = *lima, saveb = *limb;
1071: 
1072:               *lima = *limb = '\0';
1073:               diff = general_numcompare (texta, textb);
1074:               *lima = savea, *limb = saveb;
1075:             }
1076:           else
1077:             diff = general_numcompare (texta, textb);
1078: 
1079:           if (diff)
1080:             return key->reverse ? -diff : diff;
1081:           continue;
1082:         }

Parse FltOrder option (-g)
Code insertion
Segment Source
1685:         case 'g':
1686:           key->general_numeric = 1;
1687:           break;

Establish global sort options
Code insertion
Segment Source
1773:   gkey.numeric =  gkey.general_numeric = gkey.month = gkey.reverse = 0;

Propogate global sort options
Code insertion
Segment Element
Code insertion

2033:         && !key->general_numeric)

Segment Element
Code insertion

2041:         key->general_numeric = gkey.general_numeric;

Segment Element
Code insertion

2047:                         || gkey.general_numeric))