Deleted Added
full compact
test-logarithm.c (226378) test-logarithm.c (251241)
1/*-
2 * Copyright (c) 2008-2010 David Schultz <das@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * SUCH DAMAGE.
25 */
26
27/*
28 * Tests for corner cases in log*().
29 */
30
31#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2008-2010 David Schultz <das@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * SUCH DAMAGE.
25 */
26
27/*
28 * Tests for corner cases in log*().
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/tools/regression/lib/msun/test-logarithm.c 226378 2011-10-15 05:28:13Z das $");
32__FBSDID("$FreeBSD: head/tools/regression/lib/msun/test-logarithm.c 251241 2013-06-02 04:30:03Z das $");
33
34#include <assert.h>
35#include <fenv.h>
36#include <float.h>
37#include <math.h>
38#include <stdio.h>
39
40#ifdef __i386__
41#include <ieeefp.h>
42#endif
43
33
34#include <assert.h>
35#include <fenv.h>
36#include <float.h>
37#include <math.h>
38#include <stdio.h>
39
40#ifdef __i386__
41#include <ieeefp.h>
42#endif
43
44#define ALL_STD_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \
45 FE_OVERFLOW | FE_UNDERFLOW)
44#include "test-utils.h"
46
47#pragma STDC FENV_ACCESS ON
48
49/*
50 * Test that a function returns the correct value and sets the
51 * exception flags correctly. The exceptmask specifies which
52 * exceptions we should check. We need to be lenient for several
53 * reasoons, but mainly because on some architectures it's impossible

--- 4 unchanged lines hidden (view full) ---

58 *
59 * XXX The volatile here is to avoid gcc's bogus constant folding and work
60 * around the lack of support for the FENV_ACCESS pragma.
61 */
62#define test(func, x, result, exceptmask, excepts) do { \
63 volatile long double _d = x; \
64 assert(feclearexcept(FE_ALL_EXCEPT) == 0); \
65 assert(fpequal((func)(_d), (result))); \
45
46#pragma STDC FENV_ACCESS ON
47
48/*
49 * Test that a function returns the correct value and sets the
50 * exception flags correctly. The exceptmask specifies which
51 * exceptions we should check. We need to be lenient for several
52 * reasoons, but mainly because on some architectures it's impossible

--- 4 unchanged lines hidden (view full) ---

57 *
58 * XXX The volatile here is to avoid gcc's bogus constant folding and work
59 * around the lack of support for the FENV_ACCESS pragma.
60 */
61#define test(func, x, result, exceptmask, excepts) do { \
62 volatile long double _d = x; \
63 assert(feclearexcept(FE_ALL_EXCEPT) == 0); \
64 assert(fpequal((func)(_d), (result))); \
66 assert(((func), fetestexcept(exceptmask) == (excepts))); \
65 assert(((void)(func), fetestexcept(exceptmask) == (excepts))); \
67} while (0)
68
69/* Test all the functions that compute log(x). */
70#define testall0(x, result, exceptmask, excepts) do { \
71 test(log, x, result, exceptmask, excepts); \
72 test(logf, x, result, exceptmask, excepts); \
73 test(log2, x, result, exceptmask, excepts); \
74 test(log2f, x, result, exceptmask, excepts); \
75 test(log10, x, result, exceptmask, excepts); \
76 test(log10f, x, result, exceptmask, excepts); \
77} while (0)
78
79/* Test all the functions that compute log(1+x). */
80#define testall1(x, result, exceptmask, excepts) do { \
81 test(log1p, x, result, exceptmask, excepts); \
82 test(log1pf, x, result, exceptmask, excepts); \
83} while (0)
84
66} while (0)
67
68/* Test all the functions that compute log(x). */
69#define testall0(x, result, exceptmask, excepts) do { \
70 test(log, x, result, exceptmask, excepts); \
71 test(logf, x, result, exceptmask, excepts); \
72 test(log2, x, result, exceptmask, excepts); \
73 test(log2f, x, result, exceptmask, excepts); \
74 test(log10, x, result, exceptmask, excepts); \
75 test(log10f, x, result, exceptmask, excepts); \
76} while (0)
77
78/* Test all the functions that compute log(1+x). */
79#define testall1(x, result, exceptmask, excepts) do { \
80 test(log1p, x, result, exceptmask, excepts); \
81 test(log1pf, x, result, exceptmask, excepts); \
82} while (0)
83
85/*
86 * Determine whether x and y are equal, with two special rules:
87 * +0.0 != -0.0
88 * NaN == NaN
89 */
90int
91fpequal(long double x, long double y)
92{
93 return ((x == y && !signbit(x) == !signbit(y)) || isnan(x) && isnan(y));
94}
95
96void
97run_generic_tests(void)
98{
99
100 /* log(1) == 0, no exceptions raised */
101 testall0(1.0, 0.0, ALL_STD_EXCEPT, 0);
102 testall1(0.0, 0.0, ALL_STD_EXCEPT, 0);
103 testall1(-0.0, -0.0, ALL_STD_EXCEPT, 0);

--- 82 unchanged lines hidden ---
84void
85run_generic_tests(void)
86{
87
88 /* log(1) == 0, no exceptions raised */
89 testall0(1.0, 0.0, ALL_STD_EXCEPT, 0);
90 testall1(0.0, 0.0, ALL_STD_EXCEPT, 0);
91 testall1(-0.0, -0.0, ALL_STD_EXCEPT, 0);

--- 82 unchanged lines hidden ---