trig_test.c (251241) | trig_test.c (287297) |
---|---|
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 251241 2013-06-02 04:30:03Z das $"); | 37__FBSDID("$FreeBSD: head/tools/regression/lib/msun/test-trig.c 287297 2015-08-29 19:47:20Z rodrigc $"); |
38 | 38 |
39#include <sys/param.h> 40 |
|
39#include <assert.h> 40#include <fenv.h> 41#include <float.h> 42#include <math.h> 43#include <stdio.h> 44 45#include "test-utils.h" 46 | 41#include <assert.h> 42#include <fenv.h> 43#include <float.h> 44#include <math.h> 45#include <stdio.h> 46 47#include "test-utils.h" 48 |
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 54 * exceptions we should check. We need to be lenient for several 55 * reasons, but mainly because on some architectures it's impossible 56 * to raise FE_OVERFLOW without raising FE_INEXACT. --- 93 unchanged lines hidden (view full) --- 150#elif LDBL_MANT_DIG == 113 151 static const long double ld_pi_odd[] = { 152 /* XXX */ 153 }; 154#endif 155 156 int i; 157 | 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 54 * exceptions we should check. We need to be lenient for several 55 * reasons, but mainly because on some architectures it's impossible 56 * to raise FE_OVERFLOW without raising FE_INEXACT. --- 93 unchanged lines hidden (view full) --- 150#elif LDBL_MANT_DIG == 113 151 static const long double ld_pi_odd[] = { 152 /* XXX */ 153 }; 154#endif 155 156 int i; 157 |
158 for (i = 0; i < LEN(f_pi_odd); i++) { | 158 for (i = 0; i < nitems(f_pi_odd); i++) { |
159 assert(fabs(sinf(f_pi_odd[i])) < FLT_EPSILON); 160 assert(cosf(f_pi_odd[i]) == -1.0); 161 assert(fabs(tan(f_pi_odd[i])) < FLT_EPSILON); 162 163 assert(fabs(sinf(-f_pi_odd[i])) < FLT_EPSILON); 164 assert(cosf(-f_pi_odd[i]) == -1.0); 165 assert(fabs(tanf(-f_pi_odd[i])) < FLT_EPSILON); 166 167 assert(fabs(sinf(f_pi_odd[i] * 2)) < FLT_EPSILON); 168 assert(cosf(f_pi_odd[i] * 2) == 1.0); 169 assert(fabs(tanf(f_pi_odd[i] * 2)) < FLT_EPSILON); 170 171 assert(fabs(sinf(-f_pi_odd[i] * 2)) < FLT_EPSILON); 172 assert(cosf(-f_pi_odd[i] * 2) == 1.0); 173 assert(fabs(tanf(-f_pi_odd[i] * 2)) < FLT_EPSILON); 174 } 175 | 159 assert(fabs(sinf(f_pi_odd[i])) < FLT_EPSILON); 160 assert(cosf(f_pi_odd[i]) == -1.0); 161 assert(fabs(tan(f_pi_odd[i])) < FLT_EPSILON); 162 163 assert(fabs(sinf(-f_pi_odd[i])) < FLT_EPSILON); 164 assert(cosf(-f_pi_odd[i]) == -1.0); 165 assert(fabs(tanf(-f_pi_odd[i])) < FLT_EPSILON); 166 167 assert(fabs(sinf(f_pi_odd[i] * 2)) < FLT_EPSILON); 168 assert(cosf(f_pi_odd[i] * 2) == 1.0); 169 assert(fabs(tanf(f_pi_odd[i] * 2)) < FLT_EPSILON); 170 171 assert(fabs(sinf(-f_pi_odd[i] * 2)) < FLT_EPSILON); 172 assert(cosf(-f_pi_odd[i] * 2) == 1.0); 173 assert(fabs(tanf(-f_pi_odd[i] * 2)) < FLT_EPSILON); 174 } 175 |
176 for (i = 0; i < LEN(d_pi_odd); i++) { | 176 for (i = 0; i < nitems(d_pi_odd); i++) { |
177 assert(fabs(sin(d_pi_odd[i])) < 2 * DBL_EPSILON); 178 assert(cos(d_pi_odd[i]) == -1.0); 179 assert(fabs(tan(d_pi_odd[i])) < 2 * DBL_EPSILON); 180 181 assert(fabs(sin(-d_pi_odd[i])) < 2 * DBL_EPSILON); 182 assert(cos(-d_pi_odd[i]) == -1.0); 183 assert(fabs(tan(-d_pi_odd[i])) < 2 * DBL_EPSILON); 184 185 assert(fabs(sin(d_pi_odd[i] * 2)) < 2 * DBL_EPSILON); 186 assert(cos(d_pi_odd[i] * 2) == 1.0); 187 assert(fabs(tan(d_pi_odd[i] * 2)) < 2 * DBL_EPSILON); 188 189 assert(fabs(sin(-d_pi_odd[i] * 2)) < 2 * DBL_EPSILON); 190 assert(cos(-d_pi_odd[i] * 2) == 1.0); 191 assert(fabs(tan(-d_pi_odd[i] * 2)) < 2 * DBL_EPSILON); 192 } 193 194#if LDBL_MANT_DIG > 53 | 177 assert(fabs(sin(d_pi_odd[i])) < 2 * DBL_EPSILON); 178 assert(cos(d_pi_odd[i]) == -1.0); 179 assert(fabs(tan(d_pi_odd[i])) < 2 * DBL_EPSILON); 180 181 assert(fabs(sin(-d_pi_odd[i])) < 2 * DBL_EPSILON); 182 assert(cos(-d_pi_odd[i]) == -1.0); 183 assert(fabs(tan(-d_pi_odd[i])) < 2 * DBL_EPSILON); 184 185 assert(fabs(sin(d_pi_odd[i] * 2)) < 2 * DBL_EPSILON); 186 assert(cos(d_pi_odd[i] * 2) == 1.0); 187 assert(fabs(tan(d_pi_odd[i] * 2)) < 2 * DBL_EPSILON); 188 189 assert(fabs(sin(-d_pi_odd[i] * 2)) < 2 * DBL_EPSILON); 190 assert(cos(-d_pi_odd[i] * 2) == 1.0); 191 assert(fabs(tan(-d_pi_odd[i] * 2)) < 2 * DBL_EPSILON); 192 } 193 194#if LDBL_MANT_DIG > 53 |
195 for (i = 0; i < LEN(ld_pi_odd); i++) { | 195 for (i = 0; i < nitems(ld_pi_odd); i++) { |
196 assert(fabsl(sinl(ld_pi_odd[i])) < LDBL_EPSILON); 197 assert(cosl(ld_pi_odd[i]) == -1.0); 198 assert(fabsl(tanl(ld_pi_odd[i])) < LDBL_EPSILON); 199 200 assert(fabsl(sinl(-ld_pi_odd[i])) < LDBL_EPSILON); 201 assert(cosl(-ld_pi_odd[i]) == -1.0); 202 assert(fabsl(tanl(-ld_pi_odd[i])) < LDBL_EPSILON); 203 --- 77 unchanged lines hidden --- | 196 assert(fabsl(sinl(ld_pi_odd[i])) < LDBL_EPSILON); 197 assert(cosl(ld_pi_odd[i]) == -1.0); 198 assert(fabsl(tanl(ld_pi_odd[i])) < LDBL_EPSILON); 199 200 assert(fabsl(sinl(-ld_pi_odd[i])) < LDBL_EPSILON); 201 assert(cosl(-ld_pi_odd[i]) == -1.0); 202 assert(fabsl(tanl(-ld_pi_odd[i])) < LDBL_EPSILON); 203 --- 77 unchanged lines hidden --- |