/* This program isn't finished yet.
It has tests for:
acos, acosh, asin, asinh, atan, atan2, atanh,
- cbrt, ceil, copysign, cos, cosh, exp, exp2, expm1,
- fabs, fdim, floor, fmin, fmax, fpclassify,
- frexp, hypot, ilogb, ldexp,
- log, log10, log1p, log2, logb, modf, nextafter,
- pow, rint, rinttol, rinttoll, round, roundtol, roundtoll,
- scalb, scalbn, sin, sinh, sqrt, tan, tanh, trunc
+ cbrt, ceil, copysign, cos, cosh, erf, erfc, exp, exp2, expm1,
+ fabs, fdim, floor, fmin, fmax, fmod, fpclassify,
+ frexp, gamma, hypot,
+ ilogb, isfinite, isinf, isnan, isnormal,
+ ldexp, lgamma, log, log10, log1p, log2, logb,
+ modf, nearbyint, nextafter,
+ pow, remainder, remquo, rint, rinttol, rinttoll,
+ round, roundtol, roundtoll,
+ scalb, scalbn, signbit, sin, sincos, sinh, sqrt, tan, tanh, trunc
and for the following complex math functions:
cacos, cacosh, casin, casinh, catan, catanh,
At the moment the following functions aren't tested:
cabs, carg, conj, cproj, cimag, creal, drem,
- erf, erfc, gamma, lgamma,
j0, j1, jn, y0, y1, yn,
- nearbyint, remainder, remquo, signbit, significant, sincos.
+ significand,
+ nan, comparison macros (isless,isgreater,...).
The routines using random variables are still under construction. I don't
like it the way it's working now and will change it.
checked against. These implemented tests should check all cases
that are specified in ISO C 9X.
+ Exception testing: At the moment only divide-by-zero and invalid
+ exceptions are tested. Overflow/underflow and inexact exceptions
+ aren't checked at the moment.
+
+ NaN values: There exist signalling and quiet NaNs. This implementation
+ only uses signalling NaN as parameter but does not differenciate
+ between the two kinds of NaNs as result.
+
Inline functions: Inlining functions should give an improvement in
speed - but not in precission. The inlined functions return
reasonable values for a reasonable range of input values. The
- Compiler has errors
With e.g. gcc 2.7.2.2 the test for cexp fails because of a compiler error.
+
*/
#ifndef _GNU_SOURCE
}
/* Get a random value x with x < max_value. */
-#ifndef TEST_INLINE
static MATHTYPE
random_less (MATHTYPE max_value)
{
return random_value (-1e6, max_value);
}
-#endif
static void
else
{
output_fail_value (test_name);
+ if (verbose > 1)
+ printf (" Value: %d\n", result);
++noErrors;
}
output_result_bool (test_name, computed);
}
+
+
+/*
+ check that computed and expected values are equal (int values)
+ */
+static void
+check_int (const char *test_name, int computed, int expected)
+{
+ int diff = computed - expected;
+ int result = diff == 0;
+
+ output_new_test (test_name);
+ test_exceptions (test_name, NO_EXCEPTION);
+
+ if (result)
+ {
+ output_pass_value ();
+ }
+ else
+ {
+ output_fail_value (test_name);
+ if (verbose > 1)
+ {
+ printf ("Result:\n");
+ printf (" is: %d\n", computed);
+ printf (" should be: %d\n", expected);
+ }
+ noErrors++;
+ }
+
+ fpstack_test (test_name);
+}
+
+
/*
check that computed and expected values are equal (long int values)
*/
output_isvalue (test_name, isnan (computed), computed);
}
-
/*
check that computed value is not-a-number and supply parameter
*/
}
#endif
+/*
+ check that computed value is not-a-number, test for exceptions
+ and supply parameter
+ */
+static void
+check_isnan_exc_ext (const char *test_name, MATHTYPE computed,
+ short exception, MATHTYPE parameter)
+{
+ output_new_test (test_name);
+ test_exceptions (test_name,exception);
+ output_isvalue_ext (test_name, isnan (computed), computed, parameter);
+}
+
/* Tests if computed is +Inf */
static void
check_isnan_exc ("acos (x) == NaN plus invalid exception for |x| > 1",
FUNC(acos) (x),
INVALID_EXCEPTION);
+
+ x = random_less (1);
+ check_isnan_exc ("acos (x) == NaN plus invalid exception for |x| > 1",
+ FUNC(acos) (x),
+ INVALID_EXCEPTION);
#endif
check ("acos (1) == 0", FUNC(acos) (1), 0);
+ check ("acos (-1) == pi", FUNC(acos) (-1), M_PI);
}
+
static void
acosh_test (void)
{
check_isnan_exc ("asin x == NaN plus invalid exception for |x| > 1",
FUNC(asin) (x),
INVALID_EXCEPTION);
+
+ x = random_less (1);
+ check_isnan_exc ("asin x == NaN plus invalid exception for |x| > 1",
+ FUNC(asin) (x),
+ INVALID_EXCEPTION);
#endif
check ("asin (0) == 0", FUNC(asin) (0), 0);
check ("asinh(+0) == +0", FUNC(asinh) (0), 0);
#ifndef TEST_INLINE
check ("asinh(-0) == -0", FUNC(asinh) (minus_zero), minus_zero);
+ check_isinfp ("asinh(+inf) == +inf", FUNC(asinh) (plus_infty));
+ check_isinfn ("asinh(-inf) == -inf", FUNC(asinh) (minus_infty));
#endif
+
}
check ("atan (-inf) == -pi/2", FUNC(atan) (minus_infty), -M_PI_2);
}
+
static void
atan2_test (void)
{
x = random_greater (0);
check ("atan2 (y,-0) == pi/2 for y > 0", FUNC(atan2) (x, minus_zero), M_PI_2);
+ x = random_less (0);
+ check ("atan2 (y,+0) == -pi/2 for y < 0", FUNC(atan2) (x, 0), -M_PI_2);
+
+ x = random_less (0);
+ check ("atan2 (y,-0) == -pi/2 for y < 0", FUNC(atan2) (x, minus_zero), -M_PI_2);
+
+ x = random_greater (0);
+ check ("atan2 (y,inf) == +0 for finite y > 0",
+ FUNC(atan2) (x, plus_infty), 0);
+
+ x = -random_greater (0);
+ check ("atan2 (y,inf) == -0 for finite y < 0",
+ FUNC(atan2) (x, plus_infty), minus_zero);
+
+ x = random_value (-1e4, 1e4);
+ check ("atan2(+inf, x) == pi/2 for finite x",
+ FUNC(atan2) (plus_infty, x), M_PI_2);
+
+ x = random_value (-1e4, 1e4);
+ check ("atan2(-inf, x) == -pi/2 for finite x",
+ FUNC(atan2) (minus_infty, x), -M_PI_2);
+
x = random_greater (0);
check ("atan2 (y,-inf) == +pi for finite y > 0",
FUNC(atan2) (x, minus_infty), M_PI);
check ("atan2 (-inf,-inf) == -3*pi/4",
FUNC(atan2) (minus_infty, minus_infty), -3 * M_PI_4);
+
+ /* FIXME: Add some specific tests */
}
static void
atanh_test (void)
{
+ MATHTYPE x;
check ("atanh(+0) == +0", FUNC(atanh) (0), 0);
#ifndef TEST_INLINE
FUNC(atanh) (1), DIVIDE_BY_ZERO_EXCEPTION);
check_isinfn_exc ("atanh(-1) == -inf plus divide-by-zero exception",
FUNC(atanh) (-1), DIVIDE_BY_ZERO_EXCEPTION);
+
+ x = random_greater (1.0);
+ check_isnan_exc_ext ("atanh (x) == NaN plus invalid exception if |x| > 1",
+ FUNC(atanh) (x), INVALID_EXCEPTION, x);
+
+ x = random_less (1.0);
+ check_isnan_exc_ext ("atanh (x) == NaN plus invalid exception if |x| > 1",
+ FUNC(atanh) (x), INVALID_EXCEPTION, x);
+
#endif
}
}
+static void
+erf_test (void)
+{
+ errno = 0;
+ FUNC(erf) (0);
+ if (errno == ENOSYS)
+ /* Function not implemented. */
+ return;
+
+ check ("erf (+0) == +0", FUNC(erf) (0), 0);
+ check ("erf (-0) == -0", FUNC(erf) (minus_zero), minus_zero);
+ check ("erf (+inf) == +1", FUNC(erf) (plus_infty), 1);
+ check ("erf (-inf) == -1", FUNC(erf) (minus_infty), -1);
+}
+
+
+static void
+erfc_test (void)
+{
+ errno = 0;
+ FUNC(erfc) (0);
+ if (errno == ENOSYS)
+ /* Function not implemented. */
+ return;
+
+ check ("erfc (+inf) == 0", FUNC(erfc) (plus_infty), 0.0);
+ check ("erfc (-inf) == 2", FUNC(erfc) (minus_infty), 2.0);
+ check ("erfc (+0) == 1", FUNC(erfc) (0.0), 1.0);
+ check ("erfc (-0) == 1", FUNC(erfc) (minus_zero), 1.0);
+}
+
+
static void
exp_test (void)
{
}
+static void
+isfinite_test (void)
+{
+ check_bool ("isfinite (0) != 0", isfinite (0));
+ check_bool ("isfinite (-0) != 0", isfinite (minus_zero));
+ check_bool ("isfinite (10) != 0", isfinite (10));
+ check_bool ("isfinite (+inf) == 0", isfinite (plus_infty) == 0);
+ check_bool ("isfinite (-inf) == 0", isfinite (minus_infty) == 0);
+ check_bool ("isfinite (NaN) == 0", isfinite (nan_value) == 0);
+}
+
+
+static void
+isnormal_test (void)
+{
+ check_bool ("isnormal (0) == 0", isnormal (0) == 0);
+ check_bool ("isnormal (-0) == 0", isnormal (minus_zero) == 0);
+ check_bool ("isnormal (10) != 0", isnormal (10));
+ check_bool ("isnormal (+inf) == 0", isnormal (plus_infty) == 0);
+ check_bool ("isnormal (-inf) == 0", isnormal (minus_infty) == 0);
+ check_bool ("isnormal (NaN) == 0", isnormal (nan_value) == 0);
+
+}
+
+
+static void
+signbit_test (void)
+{
+ MATHTYPE x;
+
+ check_bool ("signbit (+0) == 0", signbit (0) == 0);
+ check_bool ("signbit (-0) != 0", signbit (minus_zero));
+ check_bool ("signbit (+inf) == 0", signbit (plus_infty) == 0);
+ check_bool ("signbit (-inf) != 0", signbit (minus_infty));
+ check_bool ("signbit (NaN) == 0", signbit (nan_value));
+
+ x = random_less (0);
+ check_bool ("signbit (x) != 0 for x < 0", signbit (x));
+
+ x = random_greater (0);
+ check_bool ("signbit (x) == 0 for x > 0", signbit (x) == 0);
+
+}
+
+
+
+static void
+gamma_test (void)
+{
+ MATHTYPE x;
+
+ check_isinfp ("gamma (+inf) == +inf", FUNC(gamma) (plus_infty));
+ check_isnan_exc ("gamma (0) == NaN plus invalid exception",
+ FUNC(gamma) (0), INVALID_EXCEPTION);
+
+ x = random_less (0.0);
+ check_isnan_exc_ext ("gamma (x) == NaN plus invalid exception for x <= 0",
+ FUNC(gamma) (x), INVALID_EXCEPTION, x);
+ check_isnan_exc ("gamma (-inf) == NaN plus invalid exception",
+ FUNC(gamma) (minus_infty), INVALID_EXCEPTION);
+
+ check ("gamma (0.5) == sqrt(pi)", FUNC(gamma) (0.5), FUNC(sqrt) (M_PI));
+ check ("gamma (-0.5) == -2*sqrt(pi)", FUNC(gamma) (-0.5),
+ -2*FUNC(sqrt) (M_PI));
+
+ check ("gamma (1) == 1", FUNC(gamma) (1), 1);
+ check ("gamma (4) == 6", FUNC(gamma) (4), 6);
+
+}
+
+
+static void
+lgamma_test (void)
+{
+ MATHTYPE x;
+
+ check_isinfp ("lgamma (+inf) == +inf", FUNC(lgamma) (plus_infty));
+ check_isnan_exc ("lgamma (0) == +inf plus divide by zero exception",
+ FUNC(lgamma) (0), DIVIDE_BY_ZERO_EXCEPTION);
+
+ x = random_less (0.0);
+ check_isnan_exc_ext ("lgamma (x) == +inf plus divide by zero exception for x <= 0",
+ FUNC(lgamma) (x), DIVIDE_BY_ZERO_EXCEPTION, x);
+ check_isnan_exc ("lgamma (-inf) == NaN plus invalid exception",
+ FUNC(lgamma) (minus_infty), INVALID_EXCEPTION);
+
+ check ("lgamma (1) == 0", FUNC(lgamma) (1), 0);
+ check_int ("lgamma (0) sets signgam to 1", signgam, 1);
+
+ check ("lgamma (3) == M_LN2", FUNC(lgamma) (3), M_LN2);
+ check_int ("lgamma (3) sets signgam to 1", signgam, 1);
+
+ check_eps ("lgamma (0.5) == log(sqrt(pi))", FUNC(lgamma) (0.5),
+ FUNC(log) (FUNC(sqrt) (M_PI)), CHOOSE (0, 1e-15, 1e-7));
+ check_int ("lgamma (0.5) sets signgam to 1", signgam, 1);
+
+ check_eps ("lgamma (-0.5) == log(2*sqrt(pi))", FUNC(lgamma) (-0.5),
+ FUNC(log) (2*FUNC(sqrt) (M_PI)), CHOOSE (0, 1e-15, 0));
+
+ check_int ("lgamma (-0.5) sets signgam to -1", signgam, -1);
+
+}
+
+
static void
ilogb_test (void)
{
}
+static void
+sincos_test (void)
+{
+ MATHTYPE sin_res, cos_res;
+ fenv_t fenv;
+
+ FUNC(sincos) (0, &sin_res, &cos_res);
+ fegetenv (&fenv);
+ check ("sincos (+0, &sin, &cos) puts +0 in sin", sin_res, 0);
+ fesetenv (&fenv);
+ check ("sincos (+0, &sin, &cos) puts 1 in cos", cos_res, 1);
+
+ FUNC(sincos) (minus_zero, &sin_res, &cos_res);
+ fegetenv (&fenv);
+ check ("sincos (-0, &sin, &cos) puts -0 in sin", sin_res, minus_zero);
+ fesetenv (&fenv);
+ check ("sincos (-0, &sin, &cos) puts 1 in cos", cos_res, 1);
+
+ FUNC(sincos) (plus_infty, &sin_res, &cos_res);
+ fegetenv (&fenv);
+ check_isnan_exc ("sincos (+inf, &sin, &cos) puts NaN in sin plus invalid exception",
+ sin_res, INVALID_EXCEPTION);
+ fesetenv (&fenv);
+ check_isnan_exc ("sincos (+inf, &sin, &cos) puts NaN in cos plus invalid exception",
+ cos_res, INVALID_EXCEPTION);
+
+ FUNC(sincos) (minus_infty, &sin_res, &cos_res);
+ fegetenv (&fenv);
+ check_isnan_exc ("sincos (-inf,&sin, &cos) puts NaN in sin plus invalid exception",
+ sin_res, INVALID_EXCEPTION);
+ fesetenv (&fenv);
+ check_isnan_exc ("sincos (-inf,&sin, &cos) puts NaN in cos plus invalid exception",
+ cos_res, INVALID_EXCEPTION);
+
+ FUNC(sincos) (M_PI_2, &sin_res, &cos_res);
+ fegetenv (&fenv);
+ check ("sincos (pi/2, &sin, &cos) puts 1 in sin", sin_res, 1);
+ fesetenv (&fenv);
+ check_eps ("sincos (pi/2, &sin, &cos) puts 0 in cos", cos_res, 0,
+ CHOOSE(0, 1e-16, 1e-7));
+
+ FUNC(sincos) (M_PI / 6.0, &sin_res, &cos_res);
+ check ("sincos (pi/6, &sin, &cos) puts 0.5 in sin", sin_res, 0.5);
+
+ FUNC(sincos) (M_PI / 3.0, &sin_res, &cos_res);
+ check_eps ("sincos (pi/3, &sin, &cos) puts 0.5 in cos", cos_res, 0.5,
+ CHOOSE(0, 1e-15, 1e-7));
+
+
+}
+
+
static void
tan_test (void)
{
check_isinfp_ext ("hypot (+inf, x) == +inf", FUNC(hypot) (plus_infty, a), a);
check_isinfp_ext ("hypot (-inf, x) == +inf", FUNC(hypot) (minus_infty, a), a);
+#ifndef TEST_INLINE
+ check_isinfp ("hypot (+inf, NaN) == +inf", FUNC(hypot) (minus_infty, nan_value));
+ check_isinfp ("hypot (-inf, NaN) == +inf", FUNC(hypot) (minus_infty, nan_value));
+#endif
+
check_isnan ("hypot (NaN, NaN) == NaN", FUNC(hypot) (nan_value, nan_value));
a = FUNC(hypot) (12.4L, 0.7L);
}
+static void
+fmod_test (void)
+{
+ MATHTYPE x;
+
+ x = random_greater (0);
+ check_ext ("fmod (+0, y) == +0 for y != 0", FUNC(fmod) (0, x), 0, x);
+
+ x = random_greater (0);
+ check_ext ("fmod (-0, y) == -0 for y != 0", FUNC(fmod) (minus_zero, x),
+ minus_zero, x);
+
+ check_isnan_exc_ext ("fmod (+inf, y) == NaN plus invalid exception",
+ FUNC(fmod) (plus_infty, x), INVALID_EXCEPTION, x);
+ check_isnan_exc_ext ("fmod (-inf, y) == NaN plus invalid exception",
+ FUNC(fmod) (minus_infty, x), INVALID_EXCEPTION, x);
+ check_isnan_exc_ext ("fmod (x, +0) == NaN plus invalid exception",
+ FUNC(fmod) (x, 0), INVALID_EXCEPTION, x);
+ check_isnan_exc_ext ("fmod (x, -0) == NaN plus invalid exception",
+ FUNC(fmod) (x, minus_zero), INVALID_EXCEPTION, x);
+
+ x = random_greater (0);
+ check_ext ("fmod (x, +inf) == x for x not infinite",
+ FUNC(fmod) (x, plus_infty), x, x);
+ x = random_greater (0);
+ check_ext ("fmod (x, -inf) == x for x not infinite",
+ FUNC(fmod) (x, minus_infty), x, x);
+
+ check_eps ("fmod (6.5, 2.3) == 1.9", FUNC(fmod) (6.5, 2.3), 1.9,
+ CHOOSE(0, 1e-15, 0));
+ check_eps ("fmod (-6.5, 2.3) == 1.9", FUNC(fmod) (-6.5, 2.3), -1.9,
+ CHOOSE(0, 1e-15, 0));
+ check_eps ("fmod (6.5, -2.3) == 1.9", FUNC(fmod) (6.5, -2.3), 1.9,
+ CHOOSE(0, 1e-15, 0));
+ check_eps ("fmod (-6.5, -2.3) == 1.9", FUNC(fmod) (-6.5, -2.3), -1.9,
+ CHOOSE(0, 1e-15, 0));
+
+
+}
+
+
static void
nextafter_test (void)
{
check_isnan ("sqrt (NaN) == NaN", FUNC(sqrt) (nan_value));
check_isinfp ("sqrt (+inf) == +inf", FUNC(sqrt) (plus_infty));
+ check ("sqrt (-0) == -0", FUNC(sqrt) (0), 0);
+
+ x = random_less (0.0);
+ check_isnan_exc_ext ("sqrt (x) == NaN plus invalid exception for x < 0",
+ FUNC(sqrt) (x), INVALID_EXCEPTION, x);
+
x = random_value (0, 10000);
check_ext ("sqrt (x*x) == x", FUNC(sqrt) (x*x), x, x);
check ("sqrt (4) == 2", FUNC(sqrt) (4), 2);
}
+static void
+remainder_test (void)
+{
+ MATHTYPE result;
+
+ result = FUNC(remainder) (1, 0);
+ check_isnan_exc ("remainder(1, +0) == NaN plus invalid exception",
+ result, INVALID_EXCEPTION);
+
+ result = FUNC(remainder) (1, minus_zero);
+ check_isnan_exc ("remainder(1, -0) == NaN plus invalid exception",
+ result, INVALID_EXCEPTION);
+
+ result = FUNC(remainder) (plus_infty, 1);
+ check_isnan_exc ("remainder(+inf, 1) == NaN plus invalid exception",
+ result, INVALID_EXCEPTION);
+
+ result = FUNC(remainder) (minus_infty, 1);
+ check_isnan_exc ("remainder(-inf, 1) == NaN plus invalid exception",
+ result, INVALID_EXCEPTION);
+
+ result = FUNC(remainder) (1.625, 1.0);
+ check ("remainder(1.625, 1.0) == -0.375", result, -0.375);
+
+ result = FUNC(remainder) (-1.625, 1.0);
+ check ("remainder(-1.625, 1.0) == 0.375", result, 0.375);
+
+ result = FUNC(remainder) (1.625, -1.0);
+ check ("remainder(1.625, -1.0) == -0.375", result, -0.375);
+
+ result = FUNC(remainder) (-1.625, -1.0);
+ check ("remainder(-1.625, -1.0) == 0.375", result, 0.375);
+
+ result = FUNC(remainder) (5.0, 2.0);
+ check ("remainder(5.0, 2.0) == 1.0", result, 1.0);
+
+ result = FUNC(remainder) (3.0, 2.0);
+ check ("remainder(3.0, 2.0) == -1.0", result, -1.0);
+}
+
static void
remquo_test (void)
int quo;
MATHTYPE result;
+ result = FUNC(remquo) (1, 0, &quo);
+ check_isnan_exc ("remquo(1, +0, &x) == NaN plus invalid exception",
+ result, INVALID_EXCEPTION);
+
+ result = FUNC(remquo) (1, minus_zero, &quo);
+ check_isnan_exc ("remquo(1, -0, &x) == NaN plus invalid exception",
+ result, INVALID_EXCEPTION);
+
+ result = FUNC(remquo) (plus_infty, 1, &quo);
+ check_isnan_exc ("remquo(+inf, 1, &x) == NaN plus invalid exception",
+ result, INVALID_EXCEPTION);
+
+ result = FUNC(remquo) (minus_infty, 1, &quo);
+ check_isnan_exc ("remquo(-inf, 1, &x) == NaN plus invalid exception",
+ result, INVALID_EXCEPTION);
+
result = FUNC(remquo) (1.625, 1.0, &quo);
check ("remquo(1.625, 1.0, &x) == -0.375", result, -0.375);
- check_long ("remquo(1.625, 1.0, &x) puts 1 in x", quo, 1);
-
+ check_long ("remquo(1.625, 1.0, &x) puts 2 in x", quo, 2);
+
result = FUNC(remquo) (-1.625, 1.0, &quo);
check ("remquo(-1.625, 1.0, &x) == 0.375", result, 0.375);
- check_long ("remquo(-1.625, 1.0, &x) puts -1 in x", quo, -1);
-
+ check_long ("remquo(-1.625, 1.0, &x) puts -2 in x", quo, -2);
+
result = FUNC(remquo) (1.625, -1.0, &quo);
check ("remquo(1.625, -1.0, &x) == -0.375", result, -0.375);
- check_long ("remquo(1.625, -1.0, &x) puts -1 in x", quo, -1);
-
+ check_long ("remquo(1.625, -1.0, &x) puts -2 in x", quo, -2);
+
result = FUNC(remquo) (-1.625, -1.0, &quo);
check ("remquo(-1.625, -1.0, &x) == 0.375", result, 0.375);
- check_long ("remquo(-1.625, -1.0, &x) puts 1 in x", quo, 1);
+ check_long ("remquo(-1.625, -1.0, &x) puts 2 in x", quo, 2);
+
+ result = FUNC(remquo) (5.0, 2.0, &quo);
+ check ("remquo(5.0, 2.0, &x) == 1.0", result, 1.0);
+ check_long ("remquo (5.0, 2.0, &x) puts 2 in x", quo, 2);
+
+ result = FUNC(remquo) (3.0, 2.0, &quo);
+ check ("remquo(3.0, 2.0, &x) == -1.0", result, -1.0);
+ check_long ("remquo (3.0, 2.0, &x) puts 2 in x", quo, 2);
}
}
+static void
+nearbyint_test (void)
+{
+ check ("nearbyint(+0) = 0", FUNC(nearbyint) (0.0), 0.0);
+ check ("nearbyint(-0) = -0", FUNC(nearbyint) (minus_zero), minus_zero);
+ check_isinfp ("nearbyint(+Inf) = +Inf", FUNC(nearbyint) (plus_infty));
+ check_isinfn ("nearbyint(-Inf) = -Inf", FUNC(nearbyint) (minus_infty));
+}
+
+
static void
rint_test (void)
{
basic_tests ();
+ /* keep the tests a wee bit ordered (according to ISO 9X) */
+ /* classification functions */
+ fpclassify_test ();
+ isfinite_test ();
+ isnormal_test ();
+ signbit_test ();
+
+ /* trigonometric functions */
acos_test ();
- acosh_test ();
asin_test ();
- asinh_test ();
atan_test ();
- atanh_test ();
atan2_test ();
- cbrt_test ();
- ceil_test ();
cos_test ();
+ sin_test ();
+ sincos_test ();
+ tan_test ();
+
+ /* hyperbolic functions */
+ acosh_test ();
+ asinh_test ();
+ atanh_test ();
cosh_test ();
+ sinh_test ();
+ tanh_test ();
+
+ /* exponential and logarithmic functions */
exp_test ();
exp2_test ();
expm1_test ();
frexp_test ();
- ilogb_test ();
ldexp_test ();
log_test ();
log10_test ();
log2_test ();
logb_test ();
modf_test ();
+ ilogb_test ();
scalb_test ();
scalbn_test ();
- sin_test ();
- sinh_test ();
- tan_test ();
- tanh_test ();
+
+ /* power and absolute value functions */
+ cbrt_test ();
fabs_test ();
- floor_test ();
- fpclassify_test ();
hypot_test ();
pow_test ();
- fdim_test ();
- fmin_test ();
- fmax_test ();
- nextafter_test ();
- copysign_test ();
sqrt_test ();
+
+ /* error and gamma functions */
+ erf_test ();
+ erfc_test ();
+ gamma_test ();
+ lgamma_test ();
+
+ /* nearest integer functions */
+ ceil_test ();
+ floor_test ();
+ nearbyint_test ();
+ rint_test ();
+ rinttol_test ();
+ rinttoll_test ();
+ round_test ();
+ roundtol_test ();
+ roundtoll_test ();
trunc_test ();
-#if 0
- /* XXX I'm not sure what is the correct result. */
+
+ /* remainder functions */
+ fmod_test ();
+ remainder_test ();
remquo_test ();
-#endif
+
+ /* manipulation functions */
+ copysign_test ();
+ nextafter_test ();
+
+ /* maximum, minimum and positive difference functions */
+ fdim_test ();
+ fmin_test ();
+ fmax_test ();
+
+ /* complex functions */
cexp_test ();
csin_test ();
csinh_test ();
csqrt_test ();
cpow_test ();
- rint_test ();
- rinttol_test ();
- rinttoll_test ();
- round_test ();
- roundtol_test ();
- roundtoll_test ();
-
+ /* special tests */
identities ();
inverse_functions ();
/* Get implementation for some internal functions. */
#include "../../resolv/mapv4v6addr.h"
-#define ENTNAME hostent
-#define DATABASE "hosts"
-#define NEED_H_ERRNO
-
-#define ENTDATA hostent_data
-struct hostent_data
- {
- unsigned char host_addr[16]; /* IPv4 or IPv6 address. */
- char *h_addr_ptrs[2]; /* Points to that and null terminator. */
- };
-
-#define TRAILING_LIST_MEMBER h_aliases
-#define TRAILING_LIST_SEPARATOR_P isspace
-#include "../../nss/nss_files/files-parse.c"
-LINE_PARSER
-("#",
- {
- char *addr;
-
- STRING_FIELD (addr, isspace, 1);
-
- /* Parse address. */
- if (inet_pton (AF_INET6, addr, entdata->host_addr) > 0)
- {
- result->h_addrtype = AF_INET6;
- result->h_length = IN6ADDRSZ;
- }
- else
- if (inet_pton (AF_INET, addr, entdata->host_addr) > 0)
- {
- if (_res.options & RES_USE_INET6)
- {
- map_v4v6_address ((char *) entdata->host_addr,
- (char *) entdata->host_addr);
- result->h_addrtype = AF_INET6;
- result->h_length = IN6ADDRSZ;
- }
- else
- {
- result->h_addrtype = AF_INET;
- result->h_length = INADDRSZ;
- }
- }
- else
- /* Illegal address: ignore line. */
- return 0;
-
- /* Store a pointer to the address in the expected form. */
- entdata->h_addr_ptrs[0] = entdata->host_addr;
- entdata->h_addr_ptrs[1] = NULL;
- result->h_addr_list = entdata->h_addr_ptrs;
-
- STRING_FIELD (result->h_name, isspace, 1);
- }
-)
-
-
static int
-_nss_nisplus_parse_hostent (nis_result *result, struct hostent *host,
+_nss_nisplus_parse_hostent (nis_result *result, int af, struct hostent *host,
char *buffer, size_t buflen)
{
- char *p = buffer;
- size_t room_left = buflen;
- int parse_res;
unsigned int i;
- struct parser_data *data = (void *) buffer;
+ char *first_unused = buffer;
+ size_t room_left = buflen;
+ char *data, *p, *line;
if (result == NULL)
return 0;
result->objects.objects_val[0].zo_data.objdata_u.en_data.en_cols.en_cols_len < 4)
return 0;
- memset (p, '\0', room_left);
-
- /* Generate the hosts entry format and use the normal parser */
- if (NISENTRYLEN (0, 2, result) + 1 > room_left)
+ if (room_left < NISENTRYLEN (0, 2, result) + 1)
{
__set_errno (ERANGE);
return 0;
}
- strncpy (p, NISENTRYVAL (0, 2, result),
- NISENTRYLEN (0, 2, result));
- room_left -= (NISENTRYLEN (0, 2, result) + 1);
+
+ data = first_unused;
+ if (inet_pton (af, NISENTRYVAL (0, 2, result), data) < 1)
+ /* Illegal address: ignore line. */
+ return 0;
+
+ host->h_addrtype = af;
+ if (af == AF_INET6)
+ host->h_length = IN6ADDRSZ;
+ else
+ {
+ if (_res.options & RES_USE_INET6)
+ {
+ map_v4v6_address (data, data);
+ host->h_addrtype = AF_INET6;
+ host->h_length = IN6ADDRSZ;
+ }
+ else
+ {
+ host->h_addrtype = AF_INET;
+ host->h_length = INADDRSZ;
+ }
+ }
+ first_unused+=host->h_length;
+ room_left-=host->h_length;
if (NISENTRYLEN (0, 0, result) + 1 > room_left)
{
__set_errno (ERANGE);
return 0;
}
- strcat (p, "\t");
- strncat (p, NISENTRYVAL (0, 0, result), NISENTRYLEN (0, 0, result));
+ p = stpncpy (first_unused, NISENTRYVAL (0, 0, result),
+ NISENTRYLEN (0, 0, result));
+ *p = '\0';
room_left -= (NISENTRYLEN (0, 0, result) + 1);
- /* + 1: We overwrite the last \0 */
+ host->h_name = first_unused;
+ first_unused += NISENTRYLEN (0, 0, result) +1;
+ p = first_unused;
- for (i = 1; i < result->objects.objects_len; i++)
+ line = p;
+ for (i = 0; i < result->objects.objects_len; i++)
{
- if (NISENTRYLEN (i, 1, result) + 1 > room_left)
+ if (strcmp (NISENTRYVAL (i, 1, result), host->h_name) != 0)
+ {
+ if (NISENTRYLEN (i, 1, result) + 2 > room_left)
+ {
+ __set_errno (ERANGE);
+ return 0;
+ }
+ p = stpcpy(p, " ");
+ p = stpncpy (p, NISENTRYVAL (i, 1, result),
+ NISENTRYLEN (i, 1, result));
+ *p = '\0';
+ room_left -= (NISENTRYLEN (i, 1, result) + 1);
+ }
+ }
+ ++p;
+ first_unused = p;
+ /* Adjust the pointer so it is aligned for
+ storing pointers. */
+ first_unused += __alignof__ (char *) - 1;
+ first_unused -= ((first_unused - (char *) 0) % __alignof__ (char *));
+ host->h_addr_list = (char **) first_unused;
+ if (room_left < 2 * sizeof (char *))
+ {
+ __set_errno (ERANGE);
+ return 0;
+ }
+ room_left -= (2 * sizeof (char *));
+ host->h_addr_list[0] = data;
+ host->h_addr_list[1] = NULL;
+ host->h_aliases = &host->h_addr_list[2];
+ host->h_aliases[0] = NULL;
+
+ i = 0;
+ while (*line != '\0')
+ {
+ /* Skip leading blanks. */
+ while (isspace (*line))
+ line++;
+
+ if (*line == '\0')
+ break;
+
+ if (room_left < sizeof (char *))
{
__set_errno (ERANGE);
return 0;
}
- strcat (p, " ");
- strcat (p, NISENTRYVAL (i, 1, result));
- room_left -= (NISENTRYLEN (i, 1, result) + 1);
+
+ room_left -= sizeof (char *);
+ host->h_aliases[i] = line;
+
+ while (*line != '\0' && *line != ' ')
+ line++;
+
+ if (line != host->h_aliases[i])
+ {
+ *line = '\0';
+ line++;
+ i++;
+ }
}
- parse_res = parse_line (p, host, data, buflen);
+ return 1;
- return parse_res;
}
enum nss_status
}
}
- parse_res = _nss_nisplus_parse_hostent (result, host, buffer, buflen);
+ parse_res = _nss_nisplus_parse_hostent (result, AF_INET6,
+ host, buffer, buflen);
+ if (!parse_res && errno != ERANGE)
+ parse_res = _nss_nisplus_parse_hostent (result, AF_INET, host,
+ buffer, buflen);
if (!parse_res && errno == ERANGE)
{
*herrnop = NETDB_INTERNAL;
return retval;
}
- parse_res = _nss_nisplus_parse_hostent (result, host, buffer, buflen);
+ parse_res =
+ _nss_nisplus_parse_hostent (result, af, host, buffer, buflen);
nis_freeresult (result);
}
enum nss_status
-_nss_nisplus_gethostbyaddr_r (const char *addr, struct hostent *host,
- char *buffer, size_t buflen, int *herrnop)
+_nss_nisplus_gethostbyaddr_r (const char *addr, int addrlen, int type,
+ struct hostent *host, char *buffer,
+ size_t buflen, int *herrnop)
{
if (addr == NULL)
return NSS_STATUS_NOTFOUND;
else
{
nis_result *result;
- char buf[24 + strlen (addr)];
+ char buf[1025];
int retval, parse_res;
- sprintf(buf, "[addr=%s],hosts.org_dir", addr);
-
+ snprintf(buf, sizeof (buf) -1, "[addr=%s],hosts.org_dir",
+ inet_ntoa (*(struct in_addr *)addr));
result = nis_list(buf, EXPAND_NAME, NULL, NULL);
retval = niserr2nss (result->status);
return retval;
}
- parse_res = _nss_nisplus_parse_hostent (result, host, buffer, buflen);
+ parse_res = _nss_nisplus_parse_hostent (result, type, host,
+ buffer, buflen);
nis_freeresult (result);