bug#78985: sort-float failure on ppc64, LDBL_MIN fraction part too long for test command to parse

Paul Eggert <[email protected]>
Newsgroups gmane.comp.gnu.core-utils.bugs
Organization UCLA Computer Science Department
Message-ID <[email protected]>
On 2025-07-11 04:28, C. Neidahl wrote:
> The LDBL_MIN fraction is longer than the DBL_MIN fraction, so it appears 
> as a bigger number to test/expr

Oh, right. Thanks. I installed the attached further patch to fix that. 
This is cleaner anyway.
0001-tests-fix-fraction-comparison-in-sort-float.patch (text/x-patch, 2.2 KB)
From 3a9ec02138984004719c02da8d3e13665215049f Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Fri, 11 Jul 2025 14:43:32 -0700
Subject: [PATCH] tests: fix fraction comparison in sort-float

Problem reported by Cosima Neidahl <https://bugs.gnu.org/78985#13>.
* tests/sort/sort-float.sh: At top level, use C locale at first.
(dbl_minima_order): Assume C locale.
Use string comparison for the fractional parts.

2025-07-10  Paul Eggert  <[email protected]>

tests: fix integer overflow in sort-float
Problem reported by Cosima Neidahl <https://bugs.gnu.org/78985>.
* tests/sort/sort-float.sh (dbl_minima_order):
Use expr instead of test, to avoid problems with integers
too large for the shell.
---
 tests/sort/sort-float.sh | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/tests/sort/sort-float.sh b/tests/sort/sort-float.sh
index 318ba48fb..433a21970 100755
--- a/tests/sort/sort-float.sh
+++ b/tests/sort/sort-float.sh
@@ -35,7 +35,7 @@ print_ver_ sort
 
 dbl_minima_order()
 {
-  LC_ALL=C getlimits_
+  getlimits_
   set -- $(echo $LDBL_MIN | tr .e- '   ')
   local ldbl_whole=$1 ldbl_frac=$2 ldbl_exp=$3
 
@@ -46,17 +46,23 @@ dbl_minima_order()
   test "$ldbl_exp"   -lt "$dbl_exp"    && return 1
   test "$ldbl_whole" -lt "$dbl_whole"  && return 0
   test "$dbl_whole"  -lt "$ldbl_whole" && return 1
-  # Use 'expr' not 'test', as these integers may be large.
-  expr "$ldbl_frac" '<=' "$dbl_frac" >/dev/null && return 0
-  return 1
+
+  # Use string comparison with leading '.', not 'test',
+  # as the fractions may be large integers or may differ in length.
+  test ".$dbl_frac"  '<' ".$ldbl_frac" && return 0
+  test ".$ldbl_frac" '<' ".$dbl_frac"  && return 1
+
+  return 0
 }
 
 # On some systems, DBL_MIN < LDBL_MIN.  Detect that.
+export LC_ALL=C
 dbl_minima_order; reversed=$?
 
 for LOC in C $LOCALE_FR; do
 
-  LC_ALL=$LOC getlimits_
+  export LC_ALL=$LOC
+  getlimits_
 
   # If DBL_MIN happens to be smaller than LDBL_MIN, swap them,
   # so that out expected output is sorted.
@@ -83,7 +89,7 @@ $LDBL_MAX
 " |
   grep '^[0-9.,e+-]*$' > exp # restrict to numeric just in case
 
-  tac exp | LC_ALL=$LOC sort -sg > out || fail=1
+  tac exp | sort -sg > out || fail=1
 
   compare exp out || fail=1
 done
-- 
2.48.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.