2 # Ensure sort -g sorts floating point limits correctly
4 # Copyright (C) 2010-2011 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 .
"${srcdir=.}/init.sh"; path_prepend_ ..
/src
22 # Return 0 if LDBL_MIN is smaller than DBL_MIN, else 1.
23 # Dissect numbers like these, comparing first exponent, then
24 # whole part of mantissa, then fraction, until finding enough
25 # of a difference to determine the relative order of the numbers.
26 # These are "reversed":
27 # $ ./getlimits |grep DBL_MIN
28 # DBL_MIN=2.225074e-308
29 # LDBL_MIN=2.004168e-292
31 # These are in the expected order:
32 # $ ./getlimits|grep DBL_MIN
33 # DBL_MIN=2.225074e-308
34 # LDBL_MIN=3.362103e-4932
39 set -- $
(echo $LDBL_MIN |
tr .e-
' ')
40 local ldbl_whole
=$1 ldbl_frac
=$2 ldbl_exp
=$3
42 set -- $
(echo $DBL_MIN |
tr .e-
' ')
43 local dbl_whole
=$1 dbl_frac
=$2 dbl_exp
=$3
45 test "$dbl_exp" -lt "$ldbl_exp" && return 0
46 test "$ldbl_exp" -lt "$dbl_exp" && return 1
47 test "$ldbl_whole" -lt "$dbl_whole" && return 0
48 test "$dbl_whole" -lt "$ldbl_whole" && return 1
49 test "$ldbl_frac" -le "$dbl_frac" && return 0
53 # On some systems, DBL_MIN < LDBL_MIN. Detect that.
54 dbl_minima_order
; reversed
=$?
56 for LOC
in C
$LOCALE_FR; do
58 LC_ALL
=$LOC getlimits_
60 # See if sort should be using long doubles
61 grep '^#define HAVE_C99_STRTOLD 1' $CONFIG_HEADER > /dev
/null ||
62 { LDBL_MAX
="$DBL_MAX"; LDBL_MIN
="$DBL_MIN"; }
64 # If DBL_MIN happens to be smaller than LDBL_MIN, swap them,
65 # so that out expected output is sorted.
66 if test $reversed = 1; then
87 grep '^[0-9.,e+-]*$' > exp
# restrict to numeric just in case
89 tac exp | LC_ALL
=$LOC sort -sg > out || fail
=1
91 compare exp out || fail
=1