Changeset View
Changeset View
Standalone View
Standalone View
lib/msun/tests/next_test.c
Show First 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | #define testall(arg1, arg2, ans, ex) do { \ | ||||||||||
testboth((arg1), (arg2), (ans), (ex), f); \ | testboth((arg1), (arg2), (ans), (ex), f); \ | ||||||||||
testboth((arg1), (arg2), (ans), (ex), l); \ | testboth((arg1), (arg2), (ans), (ex), l); \ | ||||||||||
} while (0) | } while (0) | ||||||||||
static void _testl(const char *, int, long double, long double, int); | static void _testl(const char *, int, long double, long double, int); | ||||||||||
static double idd(double); | static double idd(double); | ||||||||||
static float idf(float); | static float idf(float); | ||||||||||
int | |||||||||||
main(void) | |||||||||||
{ | |||||||||||
static const int ex_under = FE_UNDERFLOW | FE_INEXACT; /* shorthand */ | static const int ex_under = FE_UNDERFLOW | FE_INEXACT; /* shorthand */ | ||||||||||
static const int ex_over = FE_OVERFLOW | FE_INEXACT; | static const int ex_over = FE_OVERFLOW | FE_INEXACT; | ||||||||||
long double ldbl_small, ldbl_eps, ldbl_max; | static const long double ldbl_eps = LDBL_EPSILON; | ||||||||||
printf("1..5\n"); | |||||||||||
ATF_TC_WITHOUT_HEAD(zeros); | |||||||||||
ATF_TC_BODY(zeros, tc) | |||||||||||
{ | |||||||||||
long double ldbl_small; | |||||||||||
#ifdef __i386__ | #ifdef __i386__ | ||||||||||
fpsetprec(FP_PE); | fpsetprec(FP_PE); | ||||||||||
#endif | #endif | ||||||||||
/* | /* | ||||||||||
* We can't use a compile-time constant here because gcc on | * We can't use a compile-time constant here because gcc on | ||||||||||
* FreeBSD/i386 assumes long doubles are truncated to the | * FreeBSD/i386 assumes long doubles are truncated to the | ||||||||||
* double format. | * double format. | ||||||||||
*/ | */ | ||||||||||
ldbl_small = ldexpl(1.0, LDBL_MIN_EXP - LDBL_MANT_DIG); | ldbl_small = ldexpl(1.0, LDBL_MIN_EXP - LDBL_MANT_DIG); | ||||||||||
ldbl_eps = LDBL_EPSILON; | |||||||||||
ldbl_max = ldexpl(1.0 - ldbl_eps / 2, LDBL_MAX_EXP); | |||||||||||
/* | /* | ||||||||||
* Special cases involving zeroes. | * Special cases involving zeroes. | ||||||||||
*/ | */ | ||||||||||
#define ztest(prec) \ | #define ztest(prec) \ | ||||||||||
test##prec(copysign##prec(1.0, nextafter##prec(0.0, -0.0)), -1.0, 0); \ | test##prec(copysign##prec(1.0, nextafter##prec(0.0, -0.0)), -1.0, 0); \ | ||||||||||
test##prec(copysign##prec(1.0, nextafter##prec(-0.0, 0.0)), 1.0, 0); \ | test##prec(copysign##prec(1.0, nextafter##prec(-0.0, 0.0)), 1.0, 0); \ | ||||||||||
test##prec(copysign##prec(1.0, nexttoward##prec(0.0, -0.0)), -1.0, 0);\ | test##prec(copysign##prec(1.0, nexttoward##prec(0.0, -0.0)), -1.0, 0);\ | ||||||||||
Show All 12 Lines | #define stest(next, eps, prec) \ | ||||||||||
stest(nextafter, 0x1p-1074, ); | stest(nextafter, 0x1p-1074, ); | ||||||||||
stest(nextafterf, 0x1p-149f, f); | stest(nextafterf, 0x1p-149f, f); | ||||||||||
stest(nextafterl, ldbl_small, l); | stest(nextafterl, ldbl_small, l); | ||||||||||
stest(nexttoward, 0x1p-1074, ); | stest(nexttoward, 0x1p-1074, ); | ||||||||||
stest(nexttowardf, 0x1p-149f, f); | stest(nexttowardf, 0x1p-149f, f); | ||||||||||
stest(nexttowardl, ldbl_small, l); | stest(nexttowardl, ldbl_small, l); | ||||||||||
#undef stest | #undef stest | ||||||||||
} | |||||||||||
printf("ok 1 - next\n"); | ATF_TC_WITHOUT_HEAD(eq_and_nan); | ||||||||||
ngie: TAP printf can be deleted. New test case after this. | |||||||||||
ATF_TC_BODY(eq_and_nan, tc) | |||||||||||
{ | |||||||||||
/* | /* | ||||||||||
* `x == y' and NaN tests | * `x == y' and NaN tests | ||||||||||
*/ | */ | ||||||||||
testall(42.0, 42.0, 42.0, 0); | testall(42.0, 42.0, 42.0, 0); | ||||||||||
testall(-42.0, -42.0, -42.0, 0); | testall(-42.0, -42.0, -42.0, 0); | ||||||||||
testall(INFINITY, INFINITY, INFINITY, 0); | testall(INFINITY, INFINITY, INFINITY, 0); | ||||||||||
testall(-INFINITY, -INFINITY, -INFINITY, 0); | testall(-INFINITY, -INFINITY, -INFINITY, 0); | ||||||||||
testall(NAN, 42.0, NAN, 0); | testall(NAN, 42.0, NAN, 0); | ||||||||||
testall(42.0, NAN, NAN, 0); | testall(42.0, NAN, NAN, 0); | ||||||||||
testall(NAN, NAN, NAN, 0); | testall(NAN, NAN, NAN, 0); | ||||||||||
} | |||||||||||
printf("ok 2 - next\n"); | ATF_TC_WITHOUT_HEAD(ordinary); | ||||||||||
Done Inline ActionsTAP printf can be deleted. New test case after this. ngie: TAP printf can be deleted. New test case after this. | |||||||||||
ATF_TC_BODY(ordinary, tc) | |||||||||||
{ | |||||||||||
/* | /* | ||||||||||
* Tests where x is an ordinary normalized number | * Tests where x is an ordinary normalized number | ||||||||||
*/ | */ | ||||||||||
testboth(1.0, 2.0, 1.0 + DBL_EPSILON, 0, ); | testboth(1.0, 2.0, 1.0 + DBL_EPSILON, 0, ); | ||||||||||
testboth(1.0, -INFINITY, 1.0 - DBL_EPSILON/2, 0, ); | testboth(1.0, -INFINITY, 1.0 - DBL_EPSILON / 2, 0, ); | ||||||||||
testboth(1.0, 2.0, 1.0 + FLT_EPSILON, 0, f); | testboth(1.0, 2.0, 1.0 + FLT_EPSILON, 0, f); | ||||||||||
testboth(1.0, -INFINITY, 1.0 - FLT_EPSILON/2, 0, f); | testboth(1.0, -INFINITY, 1.0 - FLT_EPSILON / 2, 0, f); | ||||||||||
testboth(1.0, 2.0, 1.0 + ldbl_eps, 0, l); | testboth(1.0, 2.0, 1.0 + ldbl_eps, 0, l); | ||||||||||
testboth(1.0, -INFINITY, 1.0 - ldbl_eps/2, 0, l); | testboth(1.0, -INFINITY, 1.0 - ldbl_eps / 2, 0, l); | ||||||||||
testboth(-1.0, 2.0, -1.0 + DBL_EPSILON/2, 0, ); | testboth(-1.0, 2.0, -1.0 + DBL_EPSILON / 2, 0, ); | ||||||||||
testboth(-1.0, -INFINITY, -1.0 - DBL_EPSILON, 0, ); | testboth(-1.0, -INFINITY, -1.0 - DBL_EPSILON, 0, ); | ||||||||||
testboth(-1.0, 2.0, -1.0 + FLT_EPSILON/2, 0, f); | testboth(-1.0, 2.0, -1.0 + FLT_EPSILON / 2, 0, f); | ||||||||||
testboth(-1.0, -INFINITY, -1.0 - FLT_EPSILON, 0, f); | testboth(-1.0, -INFINITY, -1.0 - FLT_EPSILON, 0, f); | ||||||||||
testboth(-1.0, 2.0, -1.0 + ldbl_eps/2, 0, l); | testboth(-1.0, 2.0, -1.0 + ldbl_eps / 2, 0, l); | ||||||||||
testboth(-1.0, -INFINITY, -1.0 - ldbl_eps, 0, l); | testboth(-1.0, -INFINITY, -1.0 - ldbl_eps, 0, l); | ||||||||||
/* Cases where nextafter(...) != nexttoward(...) */ | /* Cases where nextafter(...) != nexttoward(...) */ | ||||||||||
test(nexttoward(1.0, 1.0 + ldbl_eps), 1.0 + DBL_EPSILON, 0); | test(nexttoward(1.0, 1.0 + ldbl_eps), 1.0 + DBL_EPSILON, 0); | ||||||||||
testf(nexttowardf(1.0, 1.0 + ldbl_eps), 1.0 + FLT_EPSILON, 0); | testf(nexttowardf(1.0, 1.0 + ldbl_eps), 1.0 + FLT_EPSILON, 0); | ||||||||||
testl(nexttowardl(1.0, 1.0 + ldbl_eps), 1.0 + ldbl_eps, 0); | testl(nexttowardl(1.0, 1.0 + ldbl_eps), 1.0 + ldbl_eps, 0); | ||||||||||
} | |||||||||||
printf("ok 3 - next\n"); | ATF_TC_WITHOUT_HEAD(boundaries); | ||||||||||
Done Inline ActionsTAP printf can be deleted. New test case after this. ngie: TAP printf can be deleted. New test case after this. | |||||||||||
ATF_TC_BODY(boundaries, tc) | |||||||||||
{ | |||||||||||
/* | /* | ||||||||||
* Tests at word boundaries, normalization boundaries, etc. | * Tests at word boundaries, normalization boundaries, etc. | ||||||||||
*/ | */ | ||||||||||
testboth(0x1.87654ffffffffp+0, INFINITY, 0x1.87655p+0, 0, ); | testboth(0x1.87654ffffffffp+0, INFINITY, 0x1.87655p+0, 0, ); | ||||||||||
testboth(0x1.87655p+0, -INFINITY, 0x1.87654ffffffffp+0, 0, ); | testboth(0x1.87655p+0, -INFINITY, 0x1.87654ffffffffp+0, 0, ); | ||||||||||
testboth(0x1.fffffffffffffp+0, INFINITY, 0x1p1, 0, ); | testboth(0x1.fffffffffffffp+0, INFINITY, 0x1p1, 0, ); | ||||||||||
testboth(0x1p1, -INFINITY, 0x1.fffffffffffffp+0, 0, ); | testboth(0x1p1, -INFINITY, 0x1.fffffffffffffp+0, 0, ); | ||||||||||
testboth(0x0.fffffffffffffp-1022, INFINITY, 0x1p-1022, 0, ); | testboth(0x0.fffffffffffffp-1022, INFINITY, 0x1p-1022, 0, ); | ||||||||||
Show All 26 Lines | testboth(0x1.876543210988p+0L, -INFINITY, | ||||||||||
0x1.876543210987ffffffffffffffffp+0L, 0, l); | 0x1.876543210987ffffffffffffffffp+0L, 0, l); | ||||||||||
testboth(0x1.ffffffffffffffffffffffffffffp0L, INFINITY, 0x1p1L, 0, l); | testboth(0x1.ffffffffffffffffffffffffffffp0L, INFINITY, 0x1p1L, 0, l); | ||||||||||
testboth(0x1p1L, -INFINITY, 0x1.ffffffffffffffffffffffffffffp0L, 0, l); | testboth(0x1p1L, -INFINITY, 0x1.ffffffffffffffffffffffffffffp0L, 0, l); | ||||||||||
testboth(0x0.ffffffffffffffffffffffffffffp-16382L, INFINITY, | testboth(0x0.ffffffffffffffffffffffffffffp-16382L, INFINITY, | ||||||||||
0x1p-16382L, 0, l); | 0x1p-16382L, 0, l); | ||||||||||
testboth(0x1p-16382L, -INFINITY, | testboth(0x1p-16382L, -INFINITY, | ||||||||||
0x0.ffffffffffffffffffffffffffffp-16382L, ex_under, l); | 0x0.ffffffffffffffffffffffffffffp-16382L, ex_under, l); | ||||||||||
#endif | #endif | ||||||||||
} | |||||||||||
printf("ok 4 - next\n"); | ATF_TC_WITHOUT_HEAD(overflow); | ||||||||||
ATF_TC_BODY(overflow, tc) | |||||||||||
{ | |||||||||||
long double ldbl_max; | |||||||||||
/* | |||||||||||
* We can't use a compile-time constant here because gcc on | |||||||||||
* FreeBSD/i386 assumes long doubles are truncated to the | |||||||||||
* double format. | |||||||||||
*/ | |||||||||||
ldbl_max = ldexpl(1.0 - ldbl_eps / 2, LDBL_MAX_EXP); | |||||||||||
Done Inline ActionsTAP printf can be deleted. New test case after this. ngie: TAP printf can be deleted. New test case after this. | |||||||||||
/* | /* | ||||||||||
* Overflow tests | * Overflow tests | ||||||||||
*/ | */ | ||||||||||
test(idd(nextafter(DBL_MAX, INFINITY)), INFINITY, ex_over); | test(idd(nextafter(DBL_MAX, INFINITY)), INFINITY, ex_over); | ||||||||||
test(idd(nextafter(INFINITY, 0.0)), DBL_MAX, 0); | test(idd(nextafter(INFINITY, 0.0)), DBL_MAX, 0); | ||||||||||
test(idd(nexttoward(DBL_MAX, DBL_MAX * 2.0L)), INFINITY, ex_over); | test(idd(nexttoward(DBL_MAX, DBL_MAX * 2.0L)), INFINITY, ex_over); | ||||||||||
#if LDBL_MANT_DIG > 53 | #if LDBL_MANT_DIG > 53 | ||||||||||
test(idd(nexttoward(INFINITY, DBL_MAX * 2.0L)), DBL_MAX, 0); | test(idd(nexttoward(INFINITY, DBL_MAX * 2.0L)), DBL_MAX, 0); | ||||||||||
#endif | #endif | ||||||||||
testf(idf(nextafterf(FLT_MAX, INFINITY)), INFINITY, ex_over); | testf(idf(nextafterf(FLT_MAX, INFINITY)), INFINITY, ex_over); | ||||||||||
testf(idf(nextafterf(INFINITY, 0.0)), FLT_MAX, 0); | testf(idf(nextafterf(INFINITY, 0.0)), FLT_MAX, 0); | ||||||||||
testf(idf(nexttowardf(FLT_MAX, FLT_MAX * 2.0)), INFINITY, ex_over); | testf(idf(nexttowardf(FLT_MAX, FLT_MAX * 2.0)), INFINITY, ex_over); | ||||||||||
testf(idf(nexttowardf(INFINITY, FLT_MAX * 2.0)), FLT_MAX, 0); | testf(idf(nexttowardf(INFINITY, FLT_MAX * 2.0)), FLT_MAX, 0); | ||||||||||
testboth(ldbl_max, INFINITY, INFINITY, ex_over, l); | testboth(ldbl_max, INFINITY, INFINITY, ex_over, l); | ||||||||||
testboth(INFINITY, 0.0, ldbl_max, 0, l); | testboth(INFINITY, 0.0, ldbl_max, 0, l); | ||||||||||
printf("ok 5 - next\n"); | |||||||||||
return (0); | |||||||||||
} | } | ||||||||||
Done Inline Actions
Delete TAP printf ngie: Delete TAP printf | |||||||||||
static void | static void | ||||||||||
_testl(const char *exp, int line, long double actual, long double expected, | _testl(const char *exp, int line, long double actual, long double expected, | ||||||||||
int except) | int except) | ||||||||||
{ | { | ||||||||||
int actual_except; | int actual_except; | ||||||||||
actual_except = fetestexcept(ALL_STD_EXCEPT); | actual_except = fetestexcept(ALL_STD_EXCEPT); | ||||||||||
if (!fpequal(actual, expected)) { | if (!fpequal(actual, expected)) { | ||||||||||
fprintf(stderr, "%d: %s returned %La, expecting %La\n", | atf_tc_fail_check(__FILE__, line, | ||||||||||
line, exp, actual, expected); | "%s returned %La, expecting %La\n", exp, actual, expected); | ||||||||||
abort(); | |||||||||||
} | } | ||||||||||
if (actual_except != except) { | if (actual_except != except) { | ||||||||||
fprintf(stderr, "%d: %s raised 0x%x, expecting 0x%x\n", | atf_tc_fail_check(__FILE__, line, | ||||||||||
line, exp, actual_except, except); | "%s raised 0x%x, expecting 0x%x\n", exp, actual_except, | ||||||||||
abort(); | except); | ||||||||||
} | } | ||||||||||
} | } | ||||||||||
/* | /* | ||||||||||
* The idd() and idf() routines ensure that doubles and floats are | * The idd() and idf() routines ensure that doubles and floats are | ||||||||||
* converted to their respective types instead of stored in the FPU | * converted to their respective types instead of stored in the FPU | ||||||||||
* with extra precision. | * with extra precision. | ||||||||||
*/ | */ | ||||||||||
static double | static double | ||||||||||
idd(double x) | idd(double x) | ||||||||||
{ | { | ||||||||||
return (x); | return (x); | ||||||||||
} | } | ||||||||||
static float | static float | ||||||||||
idf(float x) | idf(float x) | ||||||||||
{ | { | ||||||||||
return (x); | return (x); | ||||||||||
} | |||||||||||
ATF_TP_ADD_TCS(tp) | |||||||||||
{ | |||||||||||
ATF_TP_ADD_TC(tp, zeros); | |||||||||||
ATF_TP_ADD_TC(tp, ordinary); | |||||||||||
ATF_TP_ADD_TC(tp, eq_and_nan); | |||||||||||
ATF_TP_ADD_TC(tp, boundaries); | |||||||||||
ATF_TP_ADD_TC(tp, overflow); | |||||||||||
return (atf_no_error()); | |||||||||||
} | } |
TAP printf can be deleted. New test case after this.