diff options
| author | David Schultz <das@FreeBSD.org> | 2008-09-03 07:35:14 +0000 |
|---|---|---|
| committer | David Schultz <das@FreeBSD.org> | 2008-09-03 07:35:14 +0000 |
| commit | 73a3a6581e9b19de0d1dc075164ca0690e01691e (patch) | |
| tree | 81833acb01487c24aa210a166742d4283d4006ce /tools/regression/lib/libc/stdio/test-scanfloat.c | |
| parent | 9fb02073a39fddbc615147ff1ced2873cb9f110f (diff) | |
Notes
Diffstat (limited to 'tools/regression/lib/libc/stdio/test-scanfloat.c')
| -rw-r--r-- | tools/regression/lib/libc/stdio/test-scanfloat.c | 28 |
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 6ab63c842c22..7e1a55043909 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); } |
