| 2124 | } |
| 2125 | |
| 2126 | static int |
| 2127 | general_numcompare (char const *sa, char const *sb) |
| 2128 | { |
| 2129 | /* FIXME: maybe add option to try expensive FP conversion |
| 2130 | only if A and B can't be compared more cheaply/accurately. */ |
| 2131 | |
| 2132 | char *ea; |
| 2133 | char *eb; |
| 2134 | long double a = strtold (sa, &ea); |
| 2135 | long double b = strtold (sb, &eb); |
| 2136 | |
| 2137 | /* Put conversion errors at the start of the collating sequence. */ |
| 2138 | if (sa == ea) |
| 2139 | return sb == eb ? 0 : -1; |
| 2140 | if (sb == eb) |
| 2141 | return 1; |
| 2142 | |
| 2143 | /* Sort numbers in the usual way, where -0 == +0. Put NaNs after |
| 2144 | conversion errors but before numbers; sort them by internal |
| 2145 | bit-pattern, for lack of a more portable alternative. */ |
| 2146 | return (a < b ? -1 |
| 2147 | : a > b ? 1 |
| 2148 | : a == b ? 0 |
| 2149 | : b == b ? -1 |
| 2150 | : a == a ? 1 |
| 2151 | : nan_compare (a, b)); |
| 2152 | } |
| 2153 | |
| 2154 | /* Return an integer in 1..12 of the month name MONTH. |
| 2155 | Return 0 if the name in S is not recognized. */ |
no test coverage detected