From owner-svn-src-all@FreeBSD.ORG Sun Dec 5 22:18:35 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F1E47106566B; Sun, 5 Dec 2010 22:18:35 +0000 (UTC) (envelope-from das@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id DFF188FC18; Sun, 5 Dec 2010 22:18:35 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id oB5MIZ29010246; Sun, 5 Dec 2010 22:18:35 GMT (envelope-from das@svn.freebsd.org) Received: (from das@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id oB5MIZlA010242; Sun, 5 Dec 2010 22:18:35 GMT (envelope-from das@svn.freebsd.org) Message-Id: <201012052218.oB5MIZlA010242@svn.freebsd.org> From: David Schultz Date: Sun, 5 Dec 2010 22:18:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r216214 - head/tools/regression/lib/msun X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Dec 2010 22:18:36 -0000 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 + * Copyright (c) 2008-2010 David Schultz * 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 @@ -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