svn commit: r216214 - head/tools/regression/lib/msun
David Schultz
das at FreeBSD.org
Sun Dec 5 22:18:36 UTC 2010
Author: das
Date: Sun Dec 5 22:18:35 2010
New Revision: 216214
URL: http://svn.freebsd.org/changeset/base/216214
Log:
Add regression tests for logarithmic functions in the math library.
Added:
head/tools/regression/lib/msun/test-logarithm.c
- copied, changed from r215587, head/tools/regression/lib/msun/test-exponential.c
head/tools/regression/lib/msun/test-logarithm.t
- copied unchanged from r215587, head/tools/regression/lib/msun/test-exponential.t
Modified:
head/tools/regression/lib/msun/Makefile
Modified: head/tools/regression/lib/msun/Makefile
==============================================================================
--- head/tools/regression/lib/msun/Makefile Sun Dec 5 22:16:51 2010 (r216213)
+++ head/tools/regression/lib/msun/Makefile Sun Dec 5 22:18:35 2010 (r216214)
@@ -1,7 +1,7 @@
# $FreeBSD$
TESTS= test-conj test-csqrt test-exponential test-fenv test-fma \
- test-fmaxmin test-ilogb test-invtrig test-lrint \
+ test-fmaxmin test-ilogb test-invtrig test-logarithm test-lrint \
test-lround test-nan test-nearbyint test-next test-rem test-trig
CFLAGS+= -O0 -lm
Copied and modified: head/tools/regression/lib/msun/test-logarithm.c (from r215587, head/tools/regression/lib/msun/test-exponential.c)
==============================================================================
--- head/tools/regression/lib/msun/test-exponential.c Sat Nov 20 20:04:29 2010 (r215587, copy source)
+++ head/tools/regression/lib/msun/test-logarithm.c Sun Dec 5 22:18:35 2010 (r216214)
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2008 David Schultz <das at FreeBSD.org>
+ * Copyright (c) 2008-2010 David Schultz <das at FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -25,7 +25,7 @@
*/
/*
- * Tests for corner cases in exp*().
+ * Tests for corner cases in log*().
*/
#include <sys/cdefs.h>
@@ -66,19 +66,20 @@ __FBSDID("$FreeBSD$");
assert(((func), fetestexcept(exceptmask) == (excepts))); \
} while (0)
-/* Test all the functions that compute b^x. */
+/* Test all the functions that compute log(x). */
#define testall0(x, result, exceptmask, excepts) do { \
- test(exp, x, result, exceptmask, excepts); \
- test(expf, x, result, exceptmask, excepts); \
- test(exp2, x, result, exceptmask, excepts); \
- test(exp2f, x, result, exceptmask, excepts); \
- test(exp2l, x, result, exceptmask, excepts); \
+ test(log, x, result, exceptmask, excepts); \
+ test(logf, x, result, exceptmask, excepts); \
+ test(log2, x, result, exceptmask, excepts); \
+ test(log2f, x, result, exceptmask, excepts); \
+ test(log10, x, result, exceptmask, excepts); \
+ test(log10f, x, result, exceptmask, excepts); \
} while (0)
-/* Test all the functions that compute b^x - 1. */
+/* Test all the functions that compute log(1+x). */
#define testall1(x, result, exceptmask, excepts) do { \
- test(expm1, x, result, exceptmask, excepts); \
- test(expm1f, x, result, exceptmask, excepts); \
+ test(log1p, x, result, exceptmask, excepts); \
+ test(log1pf, x, result, exceptmask, excepts); \
} while (0)
/*
@@ -96,54 +97,47 @@ void
run_generic_tests(void)
{
- /* exp(0) == 1, no exceptions raised */
- testall0(0.0, 1.0, ALL_STD_EXCEPT, 0);
+ /* exp(1) == 0, no exceptions raised */
+ testall0(1.0, 0.0, ALL_STD_EXCEPT, 0);
testall1(0.0, 0.0, ALL_STD_EXCEPT, 0);
- testall0(-0.0, 1.0, ALL_STD_EXCEPT, 0);
testall1(-0.0, -0.0, ALL_STD_EXCEPT, 0);
- /* exp(NaN) == NaN, no exceptions raised */
+ /* log(NaN) == NaN, no exceptions raised */
testall0(NAN, NAN, ALL_STD_EXCEPT, 0);
testall1(NAN, NAN, ALL_STD_EXCEPT, 0);
- /* exp(Inf) == Inf, no exceptions raised */
+ /* log(Inf) == Inf, no exceptions raised */
testall0(INFINITY, INFINITY, ALL_STD_EXCEPT, 0);
testall1(INFINITY, INFINITY, ALL_STD_EXCEPT, 0);
- /* exp(-Inf) == 0, no exceptions raised */
- testall0(-INFINITY, 0.0, ALL_STD_EXCEPT, 0);
- testall1(-INFINITY, -1.0, ALL_STD_EXCEPT, 0);
-
- /* exp(big) == Inf, overflow exception */
- testall0(50000.0, INFINITY, ALL_STD_EXCEPT & ~FE_INEXACT, FE_OVERFLOW);
- testall1(50000.0, INFINITY, ALL_STD_EXCEPT & ~FE_INEXACT, FE_OVERFLOW);
-
- /* exp(small) == 0, underflow and inexact exceptions */
- testall0(-50000.0, 0.0, ALL_STD_EXCEPT, FE_UNDERFLOW | FE_INEXACT);
- testall1(-50000.0, -1.0, ALL_STD_EXCEPT, FE_INEXACT);
+ /* log(x) == NaN for x < 0, invalid exception raised */
+ testall0(-INFINITY, NAN, ALL_STD_EXCEPT, FE_INVALID);
+ testall1(-INFINITY, NAN, ALL_STD_EXCEPT, FE_INVALID);
+ testall0(-1.0, NAN, ALL_STD_EXCEPT, FE_INVALID);
+ testall1(-1.5, NAN, ALL_STD_EXCEPT, FE_INVALID);
+
+ /* log(0) == -Inf, divide-by-zero exception */
+ testall0(0.0, -INFINITY, ALL_STD_EXCEPT & ~FE_INEXACT, FE_DIVBYZERO);
+ testall0(-0.0, -INFINITY, ALL_STD_EXCEPT & ~FE_INEXACT, FE_DIVBYZERO);
+ testall1(-1.0, -INFINITY, ALL_STD_EXCEPT & ~FE_INEXACT, FE_DIVBYZERO);
}
void
-run_exp2_tests(void)
+run_log2_tests(void)
{
int i;
/*
- * We should insist that exp2() return exactly the correct
- * result and not raise an inexact exception for integer
- * arguments.
+ * We should insist that log2() return exactly the correct
+ * result and not raise an inexact exception for powers of 2.
*/
feclearexcept(FE_ALL_EXCEPT);
for (i = FLT_MIN_EXP - FLT_MANT_DIG; i < FLT_MAX_EXP; i++) {
- assert(exp2f(i) == ldexpf(1.0, i));
+ assert(log2f(ldexpf(1.0, i)) == i);
assert(fetestexcept(ALL_STD_EXCEPT) == 0);
}
for (i = DBL_MIN_EXP - DBL_MANT_DIG; i < DBL_MAX_EXP; i++) {
- assert(exp2(i) == ldexp(1.0, i));
- assert(fetestexcept(ALL_STD_EXCEPT) == 0);
- }
- for (i = LDBL_MIN_EXP - LDBL_MANT_DIG; i < LDBL_MAX_EXP; i++) {
- assert(exp2l(i) == ldexpl(1.0, i));
+ assert(log2(ldexp(1.0, i)) == i);
assert(fetestexcept(ALL_STD_EXCEPT) == 0);
}
}
@@ -152,19 +146,13 @@ int
main(int argc, char *argv[])
{
- printf("1..3\n");
-
- run_generic_tests();
- printf("ok 1 - exponential\n");
+ printf("1..2\n");
-#ifdef __i386__
- fpsetprec(FP_PE);
run_generic_tests();
-#endif
- printf("ok 2 - exponential\n");
+ printf("ok 1 - logarithm\n");
- run_exp2_tests();
- printf("ok 3 - exponential\n");
+ run_log2_tests();
+ printf("ok 2 - logarithm\n");
return (0);
}
Copied: head/tools/regression/lib/msun/test-logarithm.t (from r215587, head/tools/regression/lib/msun/test-exponential.t)
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/tools/regression/lib/msun/test-logarithm.t Sun Dec 5 22:18:35 2010 (r216214, copy of r215587, head/tools/regression/lib/msun/test-exponential.t)
@@ -0,0 +1,10 @@
+#!/bin/sh
+# $FreeBSD$
+
+cd `dirname $0`
+
+executable=`basename $0 .t`
+
+make $executable 2>&1 > /dev/null
+
+exec ./$executable
More information about the svn-src-all
mailing list