cexp_test.c (271349) | cexp_test.c (287297) |
---|---|
1/*- 2 * Copyright (c) 2008-2011 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 cexp*(). 29 */ 30 31#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2008-2011 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 cexp*(). 29 */ 30 31#include <sys/cdefs.h> |
32__FBSDID("$FreeBSD: head/tools/regression/lib/msun/test-cexp.c 271349 2014-09-10 03:54:57Z ngie $"); | 32__FBSDID("$FreeBSD: head/tools/regression/lib/msun/test-cexp.c 287297 2015-08-29 19:47:20Z rodrigc $"); |
33 | 33 |
34#include <sys/param.h> 35 |
|
34#include <assert.h> 35#include <complex.h> 36#include <fenv.h> 37#include <float.h> 38#include <math.h> 39#include <stdio.h> 40 41#include "test-utils.h" 42 | 36#include <assert.h> 37#include <complex.h> 38#include <fenv.h> 39#include <float.h> 40#include <math.h> 41#include <stdio.h> 42 43#include "test-utils.h" 44 |
43#define N(i) (sizeof(i) / sizeof((i)[0])) 44 | |
45#pragma STDC FENV_ACCESS ON 46#pragma STDC CX_LIMITED_RANGE OFF 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 * reasons, but mainly because on some architectures it's impossible --- 58 unchanged lines hidden (view full) --- 111 */ 112void 113test_nan() 114{ 115 int i; 116 117 /* cexp(x + NaNi) = NaN + NaNi and optionally raises invalid */ 118 /* cexp(NaN + yi) = NaN + NaNi and optionally raises invalid (|y|>0) */ | 45#pragma STDC FENV_ACCESS ON 46#pragma STDC CX_LIMITED_RANGE OFF 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 * reasons, but mainly because on some architectures it's impossible --- 58 unchanged lines hidden (view full) --- 111 */ 112void 113test_nan() 114{ 115 int i; 116 117 /* cexp(x + NaNi) = NaN + NaNi and optionally raises invalid */ 118 /* cexp(NaN + yi) = NaN + NaNi and optionally raises invalid (|y|>0) */ |
119 for (i = 0; i < N(finites); i++) { | 119 for (i = 0; i < nitems(finites); i++) { |
120 printf("# Run %d..\n", i); 121 testall(CMPLXL(finites[i], NAN), CMPLXL(NAN, NAN), 122 ALL_STD_EXCEPT & ~FE_INVALID, 0, 0); 123 if (finites[i] == 0.0) 124 continue; 125 /* XXX FE_INEXACT shouldn't be raised here */ 126 testall(CMPLXL(NAN, finites[i]), CMPLXL(NAN, NAN), 127 ALL_STD_EXCEPT & ~(FE_INVALID | FE_INEXACT), 0, 0); --- 15 unchanged lines hidden (view full) --- 143} 144 145void 146test_inf(void) 147{ 148 int i; 149 150 /* cexp(x + inf i) = NaN + NaNi and raises invalid */ | 120 printf("# Run %d..\n", i); 121 testall(CMPLXL(finites[i], NAN), CMPLXL(NAN, NAN), 122 ALL_STD_EXCEPT & ~FE_INVALID, 0, 0); 123 if (finites[i] == 0.0) 124 continue; 125 /* XXX FE_INEXACT shouldn't be raised here */ 126 testall(CMPLXL(NAN, finites[i]), CMPLXL(NAN, NAN), 127 ALL_STD_EXCEPT & ~(FE_INVALID | FE_INEXACT), 0, 0); --- 15 unchanged lines hidden (view full) --- 143} 144 145void 146test_inf(void) 147{ 148 int i; 149 150 /* cexp(x + inf i) = NaN + NaNi and raises invalid */ |
151 for (i = 0; i < N(finites); i++) { | 151 for (i = 0; i < nitems(finites); i++) { |
152 printf("# Run %d..\n", i); 153 testall(CMPLXL(finites[i], INFINITY), CMPLXL(NAN, NAN), 154 ALL_STD_EXCEPT, FE_INVALID, 1); 155 } 156 /* cexp(-inf + yi) = 0 * (cos(y) + sin(y)i) */ 157 /* XXX shouldn't raise an inexact exception */ 158 testall(CMPLXL(-INFINITY, M_PI_4), CMPLXL(0.0, 0.0), 159 ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1); --- 24 unchanged lines hidden (view full) --- 184 ALL_STD_EXCEPT, 0, 1); 185} 186 187void 188test_reals(void) 189{ 190 int i; 191 | 152 printf("# Run %d..\n", i); 153 testall(CMPLXL(finites[i], INFINITY), CMPLXL(NAN, NAN), 154 ALL_STD_EXCEPT, FE_INVALID, 1); 155 } 156 /* cexp(-inf + yi) = 0 * (cos(y) + sin(y)i) */ 157 /* XXX shouldn't raise an inexact exception */ 158 testall(CMPLXL(-INFINITY, M_PI_4), CMPLXL(0.0, 0.0), 159 ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1); --- 24 unchanged lines hidden (view full) --- 184 ALL_STD_EXCEPT, 0, 1); 185} 186 187void 188test_reals(void) 189{ 190 int i; 191 |
192 for (i = 0; i < N(finites); i++) { | 192 for (i = 0; i < nitems(finites); i++) { |
193 /* XXX could check exceptions more meticulously */ 194 printf("# Run %d..\n", i); 195 test(cexp, CMPLXL(finites[i], 0.0), 196 CMPLXL(exp(finites[i]), 0.0), 197 FE_INVALID | FE_DIVBYZERO, 0, 1); 198 test(cexp, CMPLXL(finites[i], -0.0), 199 CMPLXL(exp(finites[i]), -0.0), 200 FE_INVALID | FE_DIVBYZERO, 0, 1); --- 6 unchanged lines hidden (view full) --- 207 } 208} 209 210void 211test_imaginaries(void) 212{ 213 int i; 214 | 193 /* XXX could check exceptions more meticulously */ 194 printf("# Run %d..\n", i); 195 test(cexp, CMPLXL(finites[i], 0.0), 196 CMPLXL(exp(finites[i]), 0.0), 197 FE_INVALID | FE_DIVBYZERO, 0, 1); 198 test(cexp, CMPLXL(finites[i], -0.0), 199 CMPLXL(exp(finites[i]), -0.0), 200 FE_INVALID | FE_DIVBYZERO, 0, 1); --- 6 unchanged lines hidden (view full) --- 207 } 208} 209 210void 211test_imaginaries(void) 212{ 213 int i; 214 |
215 for (i = 0; i < N(finites); i++) { | 215 for (i = 0; i < nitems(finites); i++) { |
216 printf("# Run %d..\n", i); 217 test(cexp, CMPLXL(0.0, finites[i]), 218 CMPLXL(cos(finites[i]), sin(finites[i])), 219 ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1); 220 test(cexp, CMPLXL(-0.0, finites[i]), 221 CMPLXL(cos(finites[i]), sin(finites[i])), 222 ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1); 223 test(cexpf, CMPLXL(0.0, finites[i]), --- 15 unchanged lines hidden (view full) --- 239 -1.0, M_PI_4, M_SQRT2 * 0.5 / M_E, M_SQRT2 * 0.5 / M_E, 240 2.0, M_PI_2, 0.0, M_E * M_E, 241 M_LN2, M_PI, -2.0, 0.0, 242 }; 243 double a, b; 244 double x, y; 245 int i; 246 | 216 printf("# Run %d..\n", i); 217 test(cexp, CMPLXL(0.0, finites[i]), 218 CMPLXL(cos(finites[i]), sin(finites[i])), 219 ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1); 220 test(cexp, CMPLXL(-0.0, finites[i]), 221 CMPLXL(cos(finites[i]), sin(finites[i])), 222 ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1); 223 test(cexpf, CMPLXL(0.0, finites[i]), --- 15 unchanged lines hidden (view full) --- 239 -1.0, M_PI_4, M_SQRT2 * 0.5 / M_E, M_SQRT2 * 0.5 / M_E, 240 2.0, M_PI_2, 0.0, M_E * M_E, 241 M_LN2, M_PI, -2.0, 0.0, 242 }; 243 double a, b; 244 double x, y; 245 int i; 246 |
247 for (i = 0; i < N(tests); i += 4) { | 247 for (i = 0; i < nitems(tests); i += 4) { |
248 printf("# Run %d..\n", i); 249 a = tests[i]; 250 b = tests[i + 1]; 251 x = tests[i + 2]; 252 y = tests[i + 3]; 253 test_tol(cexp, CMPLXL(a, b), CMPLXL(x, y), 3 * DBL_ULP()); 254 255 /* float doesn't have enough precision to pass these tests */ --- 67 unchanged lines hidden --- | 248 printf("# Run %d..\n", i); 249 a = tests[i]; 250 b = tests[i + 1]; 251 x = tests[i + 2]; 252 y = tests[i + 3]; 253 test_tol(cexp, CMPLXL(a, b), CMPLXL(x, y), 3 * DBL_ULP()); 254 255 /* float doesn't have enough precision to pass these tests */ --- 67 unchanged lines hidden --- |