summaryrefslogtreecommitdiffstats
path: root/tools/regression/lib
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2008-09-03 07:35:14 +0000
committerdas <das@FreeBSD.org>2008-09-03 07:35:14 +0000
commitca999bfaa6ab9ea681a256ef5a391596759c5598 (patch)
tree81833acb01487c24aa210a166742d4283d4006ce /tools/regression/lib
parent65b5df780e46482cb390f068a30dd18da539fa2e (diff)
downloadFreeBSD-src-ca999bfaa6ab9ea681a256ef5a391596759c5598.zip
FreeBSD-src-ca999bfaa6ab9ea681a256ef5a391596759c5598.tar.gz
Regression tests for bugs in gdtoa.
Diffstat (limited to 'tools/regression/lib')
-rw-r--r--tools/regression/lib/libc/stdio/test-scanfloat.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/tools/regression/lib/libc/stdio/test-scanfloat.c b/tools/regression/lib/libc/stdio/test-scanfloat.c
index 6ab63c8..7e1a550 100644
--- a/tools/regression/lib/libc/stdio/test-scanfloat.c
+++ b/tools/regression/lib/libc/stdio/test-scanfloat.c
@@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$");
#include <locale.h>
#include <math.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#define eq(type, a, b) _eq(type##_EPSILON, (a), (b))
@@ -187,15 +188,8 @@ main(int argc, char *argv[])
assert(f != f);
assert(d != d);
assert(ld != ld);
-#if 0
- /*
- * POSIX says we should only generate quiet NaNs, but the gdtoa
- * author convincingly argues that if you ask for a NaN format
- * based on some implementation-defined string, you should get
- * what you asked for, even if it's a signaling NaN.
- */
+ /* POSIX says we should only generate quiet NaNs. */
assert(fetestexcept(FE_INVALID) == 0);
-#endif
printf("ok 2 - scanfloat\n");
@@ -282,6 +276,20 @@ main(int argc, char *argv[])
assert(strtod("0xy", &endp) == 0);
assert(strcmp("xy", endp) == 0);
+ /* This used to cause an infinite loop and round the wrong way. */
+ fesetround(FE_DOWNWARD);
+ assert(strtof("3.5e38", &endp) == FLT_MAX);
+ assert(strtod("2e308", &endp) == DBL_MAX);
+ fesetround(FE_UPWARD);
+ assert(strtof("3.5e38", &endp) == INFINITY);
+ assert(strtod("2e308", &endp) == INFINITY);
+ fesetround(FE_TOWARDZERO);
+ assert(strtof("3.5e38", &endp) == FLT_MAX);
+ assert(strtod("2e308", &endp) == DBL_MAX);
+ fesetround(FE_TONEAREST);
+ assert(strtof("3.5e38", &endp) == INFINITY);
+ assert(strtod("2e308", &endp) == INFINITY);
+
printf("ok 4 - scanfloat\n");
return (0);
@@ -292,8 +300,6 @@ _eq(long double epsilon, long double a, long double b)
{
long double delta;
- delta = a - b;
- if (delta < 0) /* XXX no fabsl() */
- delta = -delta;
+ delta = fabsl(a - b);
return (delta <= epsilon);
}
OpenPOWER on IntegriCloud