diff options
author | Joseph Myers <josmyers@redhat.com> | 2024-09-20 23:24:02 +0000 |
---|---|---|
committer | Arjun Shankar <arjun@redhat.com> | 2024-09-27 17:25:43 +0200 |
commit | 3edc0f22a620fdda6eda69cfd47d96142132943f (patch) | |
tree | 81c26bcca7f293b3c80ba9fdcd500d77a1240be0 | |
parent | 988de945389e22460a2f75e677d55ac5f96408f3 (diff) | |
download | glibc-3edc0f22a620fdda6eda69cfd47d96142132943f.tar.gz glibc-3edc0f22a620fdda6eda69cfd47d96142132943f.tar.xz glibc-3edc0f22a620fdda6eda69cfd47d96142132943f.zip |
Add more tests of strtod end pointer
Although there are some tests in tst-strtod2 and tst-strtod3 for the end pointer provided by strtod when it doesn't parse the whole string, they aren't very thorough. Add tests of more such cases to tst-strtod2. Tested for x86_64. (cherry picked from commit b5d3737b305525315e0c7c93ca49eadc868eabd5)
-rw-r--r-- | stdlib/tst-strtod2.c | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/stdlib/tst-strtod2.c b/stdlib/tst-strtod2.c index 2cb0953fa9..c84bd792c1 100644 --- a/stdlib/tst-strtod2.c +++ b/stdlib/tst-strtod2.c @@ -1,3 +1,4 @@ +#include <math.h> #include <stdio.h> #include <stdlib.h> @@ -17,10 +18,46 @@ struct test_strto ## FSUF \ { "0x.0y", 0.0 ## LSUF, 4 }, \ { ".y", 0.0 ## LSUF, 0 }, \ { "0.y", 0.0 ## LSUF, 2 }, \ - { ".0y", 0.0 ## LSUF, 2 } \ + { ".0y", 0.0 ## LSUF, 2 }, \ + { "1.0e", 1.0 ## LSUF, 3 }, \ + { "1.0e+", 1.0 ## LSUF, 3 }, \ + { "1.0e-", 1.0 ## LSUF, 3 }, \ + { "1.0ex", 1.0 ## LSUF, 3 }, \ + { "1.0e+x", 1.0 ## LSUF, 3 }, \ + { "1.0e-x", 1.0 ## LSUF, 3 }, \ + { "0x1p", 1.0 ## LSUF, 3 }, \ + { "0x1p+", 1.0 ## LSUF, 3 }, \ + { "0x1p-", 1.0 ## LSUF, 3 }, \ + { "0x1px", 1.0 ## LSUF, 3 }, \ + { "0x1p+x", 1.0 ## LSUF, 3 }, \ + { "0x1p-x", 1.0 ## LSUF, 3 }, \ + { "INFx", INFINITY, 3 }, \ + { "infx", INFINITY, 3 }, \ + { "INFINITx", INFINITY, 3 }, \ + { "infinitx", INFINITY, 3 }, \ + { "INFINITYY", INFINITY, 8 }, \ + { "infinityy", INFINITY, 8 }, \ + { "NANx", NAN, 3 }, \ + { "nanx", NAN, 3 }, \ + { "NAN(", NAN, 3 }, \ + { "nan(", NAN, 3 }, \ + { "NAN(x", NAN, 3 }, \ + { "nan(x", NAN, 3 }, \ + { "NAN(x)y", NAN, 6 }, \ + { "nan(x)y", NAN, 6 }, \ + { "NAN(*)y", NAN, 3 }, \ + { "nan(*)y", NAN, 3 } \ }; \ \ static int \ +compare_strto ## FSUF (FTYPE x, FTYPE y) \ +{ \ + if (isnan (x) && isnan (y)) \ + return 1; \ + return x == y; \ +} \ + \ +static int \ test_strto ## FSUF (void) \ { \ int status = 0; \ @@ -30,7 +67,7 @@ test_strto ## FSUF (void) \ { \ char *ep; \ FTYPE r = strto ## FSUF (tests_strto ## FSUF[i].str, &ep); \ - if (r != tests_strto ## FSUF[i].result) \ + if (!compare_strto ## FSUF (r, tests_strto ## FSUF[i].result)) \ { \ char buf1[FSTRLENMAX], buf2[FSTRLENMAX]; \ FTOSTR (buf1, sizeof (buf1), "%g", r); \ |