bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

strtod, strtold tests: avoid test failure on AIX 7.2


From: Bruno Haible
Subject: strtod, strtold tests: avoid test failure on AIX 7.2
Date: Fri, 13 Dec 2019 00:35:07 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-166-generic; KDE/5.18.0; x86_64; ; )

On AIX 7.2, I'm seeing test failures of
  test-strtod1.sh
  test-strtold1.sh

The reason is that on this system, in a French locale, both "1,5" and "1.5"
are parsed with return value 1.5. This is allowed by POSIX [1], which says
  "In other than the C or POSIX locale, additional locale-specific subject
   sequence forms may be accepted."

Note that such a behaviour of strtod() does not fix all internationalization
problems around number parsing. Namely, there is also the grouping delimiter.
For example, in Germany, the number
  20.000,45
is the same as
  20000,45
So, while strtod("20.000") may return 20, a correct internationalized
parsing of "20.000" MUST return 20000, not 20 !

[1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/strtod.html


2019-12-12  Bruno Haible  <address@hidden>

        strtod, strtold tests: Avoid test failure on AIX 7.2.
        * tests/test-strtod1.c (main): Allow implementations in which ',' and
        '.' both are radix characters.
        * tests/test-strtold1.c (main): Likewise.

diff --git a/tests/test-strtod1.c b/tests/test-strtod1.c
index 75200cc..26b96be 100644
--- a/tests/test-strtod1.c
+++ b/tests/test-strtod1.c
@@ -68,8 +68,10 @@ main (int argc, char *argv[])
     double result;
     errno = 0;
     result = strtod (input, &ptr);
-    ASSERT (result == 1.0);
-    ASSERT (ptr == input + 1);
+    /* On AIX 7.2, in the French locale, '.' is recognized as an alternate
+       radix character.  */
+    ASSERT ((ptr == input + 1 && result == 1.0)
+            || (ptr == input + 3 && result == 1.5));
     ASSERT (errno == 0);
   }
   {
@@ -78,8 +80,10 @@ main (int argc, char *argv[])
     double result;
     errno = 0;
     result = strtod (input, &ptr);
-    ASSERT (result == 123.0);
-    ASSERT (ptr == input + 3);
+    /* On AIX 7.2, in the French locale, '.' is recognized as an alternate
+       radix character.  */
+    ASSERT ((ptr == input + 3 && result == 123.0)
+            || (ptr == input + 7 && result > 123.45 && result < 123.46));
     ASSERT (errno == 0);
   }
   {
diff --git a/tests/test-strtold1.c b/tests/test-strtold1.c
index 3a2f533..e58174b 100644
--- a/tests/test-strtold1.c
+++ b/tests/test-strtold1.c
@@ -68,8 +68,10 @@ main (int argc, char *argv[])
     long double result;
     errno = 0;
     result = strtold (input, &ptr);
-    ASSERT (result == 1.0L);
-    ASSERT (ptr == input + 1);
+    /* On AIX 7.2, in the French locale, '.' is recognized as an alternate
+       radix character.  */
+    ASSERT ((ptr == input + 1 && result == 1.0L)
+            || (ptr == input + 3 && result == 1.5L));
     ASSERT (errno == 0);
   }
   {
@@ -78,8 +80,10 @@ main (int argc, char *argv[])
     long double result;
     errno = 0;
     result = strtold (input, &ptr);
-    ASSERT (result == 123.0L);
-    ASSERT (ptr == input + 3);
+    /* On AIX 7.2, in the French locale, '.' is recognized as an alternate
+       radix character.  */
+    ASSERT ((ptr == input + 3 && result == 123.0L)
+            || (ptr == input + 7 && result > 123.45L && result < 123.46L));
     ASSERT (errno == 0);
   }
   {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]