summaryrefslogtreecommitdiff
path: root/tests/misc/sort-float
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2010-10-16 20:18:19 +0200
committerJim Meyering <meyering@redhat.com>2010-10-17 09:18:57 +0200
commit766ec503f7916dd73486a658b4da5307eaf4cd60 (patch)
treea5acf1bb669a7c1a02a7305b5eb52473bbacb2d4 /tests/misc/sort-float
parent9c589e694f3c235d723ae80533f3bf09a5ac3702 (diff)
downloadcoreutils-766ec503f7916dd73486a658b4da5307eaf4cd60.tar.xz
tests: sort-float: avoid spurious test failure on ppc/ppc64
* tests/misc/sort-float: On systems with DBL_MIN < LDBL_MIN, this test would fail because the expected output was not sorted. Detect that case, and if needed, reverse those two values.
Diffstat (limited to 'tests/misc/sort-float')
-rwxr-xr-xtests/misc/sort-float42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/misc/sort-float b/tests/misc/sort-float
index 639cd7eae..04071598f 100755
--- a/tests/misc/sort-float
+++ b/tests/misc/sort-float
@@ -23,6 +23,40 @@ fi
. $srcdir/test-lib.sh
+# Return 0 if LDBL_MIN is smaller than DBL_MIN, else 1.
+# Dissect numbers like these, comparing first exponent, then
+# whole part of mantissa, then fraction, until finding enough
+# of a difference to determine the relative order of the numbers.
+# These are "reversed":
+# $ ./getlimits |grep DBL_MIN
+# DBL_MIN=2.225074e-308
+# LDBL_MIN=2.004168e-292
+#
+# These are in the expected order:
+# $ ./getlimits|grep DBL_MIN
+# DBL_MIN=2.225074e-308
+# LDBL_MIN=3.362103e-4932
+
+dbl_minima_order()
+{
+ LC_ALL=C getlimits_
+ set -- $(echo $LDBL_MIN | tr .e- ' ')
+ local ldbl_whole=$1 ldbl_frac=$2 ldbl_exp=$3
+
+ set -- $(echo $DBL_MIN |tr .e- ' ')
+ local dbl_whole=$1 dbl_frac=$2 dbl_exp=$3
+
+ test "$dbl_exp" -lt "$ldbl_exp" && return 0
+ test "$ldbl_exp" -lt "$dbl_exp" && return 1
+ test "$ldbl_whole" -lt "$dbl_whole" && return 0
+ test "$dbl_whole" -lt "$ldbl_whole" && return 1
+ test "$ldbl_frac" -le "$dbl_frac" && return 0
+ return 1
+}
+
+# On some systems, DBL_MIN < LDBL_MIN. Detect that.
+dbl_minima_order; reversed=$?
+
for LOC in C $LOCALE_FR; do
LC_ALL=$LOC getlimits_
@@ -31,6 +65,14 @@ for LOC in C $LOCALE_FR; do
grep '^#define HAVE_C99_STRTOLD 1' $CONFIG_HEADER > /dev/null ||
{ LDBL_MAX="$DBL_MAX"; LDBL_MIN="$DBL_MIN"; }
+ # If DBL_MIN happens to be smaller than LDBL_MIN, swap them,
+ # so that out expected output is sorted.
+ if test $reversed = 1; then
+ t=$LDBL_MIN
+ LDBL_MIN=$DBL_MIN
+ DBL_MIN=$t
+ fi
+
printf -- "\
-$LDBL_MAX
-$DBL_MAX