Deleted Added
full compact
test-trig.c (216222) test-trig.c (251241)
1/*-
2 * Copyright (c) 2008 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

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

29 * are included as well, but these are very basic sanity checks, not
30 * intended to be comprehensive.
31 *
32 * The program for generating representable numbers near multiples of pi is
33 * available at http://www.cs.berkeley.edu/~wkahan/testpi/ .
34 */
35
36#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2008 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

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

29 * are included as well, but these are very basic sanity checks, not
30 * intended to be comprehensive.
31 *
32 * The program for generating representable numbers near multiples of pi is
33 * available at http://www.cs.berkeley.edu/~wkahan/testpi/ .
34 */
35
36#include <sys/cdefs.h>
37__FBSDID("$FreeBSD: head/tools/regression/lib/msun/test-trig.c 216222 2010-12-06 00:02:49Z das $");
37__FBSDID("$FreeBSD: head/tools/regression/lib/msun/test-trig.c 251241 2013-06-02 04:30:03Z das $");
38
39#include <assert.h>
40#include <fenv.h>
41#include <float.h>
42#include <math.h>
43#include <stdio.h>
44
38
39#include <assert.h>
40#include <fenv.h>
41#include <float.h>
42#include <math.h>
43#include <stdio.h>
44
45#define ALL_STD_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \
46 FE_OVERFLOW | FE_UNDERFLOW)
45#include "test-utils.h"
47
48#define LEN(a) (sizeof(a) / sizeof((a)[0]))
49
50#pragma STDC FENV_ACCESS ON
51
52/*
53 * Test that a function returns the correct value and sets the
54 * exception flags correctly. The exceptmask specifies which

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

61 *
62 * XXX The volatile here is to avoid gcc's bogus constant folding and work
63 * around the lack of support for the FENV_ACCESS pragma.
64 */
65#define test(func, x, result, exceptmask, excepts) do { \
66 volatile long double _d = x; \
67 assert(feclearexcept(FE_ALL_EXCEPT) == 0); \
68 assert(fpequal((func)(_d), (result))); \
46
47#define LEN(a) (sizeof(a) / sizeof((a)[0]))
48
49#pragma STDC FENV_ACCESS ON
50
51/*
52 * Test that a function returns the correct value and sets the
53 * exception flags correctly. The exceptmask specifies which

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

60 *
61 * XXX The volatile here is to avoid gcc's bogus constant folding and work
62 * around the lack of support for the FENV_ACCESS pragma.
63 */
64#define test(func, x, result, exceptmask, excepts) do { \
65 volatile long double _d = x; \
66 assert(feclearexcept(FE_ALL_EXCEPT) == 0); \
67 assert(fpequal((func)(_d), (result))); \
69 assert(((func), fetestexcept(exceptmask) == (excepts))); \
68 assert(((void)(func), fetestexcept(exceptmask) == (excepts))); \
70} while (0)
71
72#define testall(prefix, x, result, exceptmask, excepts) do { \
73 test(prefix, x, (double)result, exceptmask, excepts); \
74 test(prefix##f, x, (float)result, exceptmask, excepts); \
75 test(prefix##l, x, result, exceptmask, excepts); \
76} while (0)
77
78#define testdf(prefix, x, result, exceptmask, excepts) do { \
79 test(prefix, x, (double)result, exceptmask, excepts); \
80 test(prefix##f, x, (float)result, exceptmask, excepts); \
81} while (0)
82
69} while (0)
70
71#define testall(prefix, x, result, exceptmask, excepts) do { \
72 test(prefix, x, (double)result, exceptmask, excepts); \
73 test(prefix##f, x, (float)result, exceptmask, excepts); \
74 test(prefix##l, x, result, exceptmask, excepts); \
75} while (0)
76
77#define testdf(prefix, x, result, exceptmask, excepts) do { \
78 test(prefix, x, (double)result, exceptmask, excepts); \
79 test(prefix##f, x, (float)result, exceptmask, excepts); \
80} while (0)
81
83
84
85/*
82/*
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
96/*
97 * Test special cases in sin(), cos(), and tan().
98 */
99static void
100run_special_tests(void)
101{
102
103 /* Values at 0 should be exact. */
104 testall(tan, 0.0, 0.0, ALL_STD_EXCEPT, 0);

--- 190 unchanged lines hidden ---
83 * Test special cases in sin(), cos(), and tan().
84 */
85static void
86run_special_tests(void)
87{
88
89 /* Values at 0 should be exact. */
90 testall(tan, 0.0, 0.0, ALL_STD_EXCEPT, 0);

--- 190 unchanged lines hidden ---