fma_test.c (226602) | fma_test.c (251024) |
---|---|
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 --- 15 unchanged lines hidden (view full) --- 24 * SUCH DAMAGE. 25 */ 26 27/* 28 * Tests for fma{,f,l}(). 29 */ 30 31#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 --- 15 unchanged lines hidden (view full) --- 24 * SUCH DAMAGE. 25 */ 26 27/* 28 * Tests for fma{,f,l}(). 29 */ 30 31#include <sys/cdefs.h> |
32__FBSDID("$FreeBSD: head/tools/regression/lib/msun/test-fma.c 226602 2011-10-21 06:32:54Z das $"); | 32__FBSDID("$FreeBSD: head/tools/regression/lib/msun/test-fma.c 251024 2013-05-27 08:50:10Z das $"); |
33 34#include <assert.h> 35#include <fenv.h> 36#include <float.h> 37#include <math.h> 38#include <stdio.h> 39 40#define ALL_STD_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \ --- 31 unchanged lines hidden (view full) --- 72 test((func), (x), (y), (z), (ru), (exceptmask), (excepts)); \ 73 fesetround(FE_DOWNWARD); \ 74 test((func), (x), (y), (z), (rd), (exceptmask), (excepts)); \ 75 fesetround(FE_TOWARDZERO); \ 76 test((func), (x), (y), (z), (rz), (exceptmask), (excepts)); \ 77} while (0) 78 79/* | 33 34#include <assert.h> 35#include <fenv.h> 36#include <float.h> 37#include <math.h> 38#include <stdio.h> 39 40#define ALL_STD_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \ --- 31 unchanged lines hidden (view full) --- 72 test((func), (x), (y), (z), (ru), (exceptmask), (excepts)); \ 73 fesetround(FE_DOWNWARD); \ 74 test((func), (x), (y), (z), (rd), (exceptmask), (excepts)); \ 75 fesetround(FE_TOWARDZERO); \ 76 test((func), (x), (y), (z), (rz), (exceptmask), (excepts)); \ 77} while (0) 78 79/* |
80 * This is needed because clang constant-folds fma in ways that are incorrect 81 * in rounding modes other than FE_TONEAREST. 82 */ 83volatile double one = 1.0; 84 85/* |
|
80 * Determine whether x and y are equal, with two special rules: 81 * +0.0 != -0.0 82 * NaN == NaN 83 */ 84int 85fpequal(long double x, long double y) 86{ 87 --- 15 unchanged lines hidden (view full) --- 103 testall(0.0, -0.0, 0.0, rd ? -0.0 : 0.0, ALL_STD_EXCEPT, 0); 104 testall(-0.0, -0.0, 0.0, 0.0, ALL_STD_EXCEPT, 0); 105 testall(0.0, 0.0, -0.0, rd ? -0.0 : 0.0, ALL_STD_EXCEPT, 0); 106 testall(-0.0, -0.0, -0.0, rd ? -0.0 : 0.0, ALL_STD_EXCEPT, 0); 107 108 testall(-0.0, 0.0, -0.0, -0.0, ALL_STD_EXCEPT, 0); 109 testall(0.0, -0.0, -0.0, -0.0, ALL_STD_EXCEPT, 0); 110 | 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 --- 15 unchanged lines hidden (view full) --- 109 testall(0.0, -0.0, 0.0, rd ? -0.0 : 0.0, ALL_STD_EXCEPT, 0); 110 testall(-0.0, -0.0, 0.0, 0.0, ALL_STD_EXCEPT, 0); 111 testall(0.0, 0.0, -0.0, rd ? -0.0 : 0.0, ALL_STD_EXCEPT, 0); 112 testall(-0.0, -0.0, -0.0, rd ? -0.0 : 0.0, ALL_STD_EXCEPT, 0); 113 114 testall(-0.0, 0.0, -0.0, -0.0, ALL_STD_EXCEPT, 0); 115 testall(0.0, -0.0, -0.0, -0.0, ALL_STD_EXCEPT, 0); 116 |
111 testall(-1.0, 1.0, 1.0, rd ? -0.0 : 0.0, ALL_STD_EXCEPT, 0); 112 testall(1.0, -1.0, 1.0, rd ? -0.0 : 0.0, ALL_STD_EXCEPT, 0); 113 testall(-1.0, -1.0, -1.0, rd ? -0.0 : 0.0, ALL_STD_EXCEPT, 0); | 117 testall(-one, one, one, rd ? -0.0 : 0.0, ALL_STD_EXCEPT, 0); 118 testall(one, -one, one, rd ? -0.0 : 0.0, ALL_STD_EXCEPT, 0); 119 testall(-one, -one, -one, rd ? -0.0 : 0.0, ALL_STD_EXCEPT, 0); |
114 115 switch (fegetround()) { 116 case FE_TONEAREST: 117 case FE_TOWARDZERO: 118 test(fmaf, -FLT_MIN, FLT_MIN, 0.0, -0.0, 119 ALL_STD_EXCEPT, FE_INEXACT | FE_UNDERFLOW); 120 test(fma, -DBL_MIN, DBL_MIN, 0.0, -0.0, 121 ALL_STD_EXCEPT, FE_INEXACT | FE_UNDERFLOW); --- 63 unchanged lines hidden (view full) --- 185 * Tests for cases where z is very small compared to x*y. 186 */ 187static void 188test_small_z(void) 189{ 190 191 /* x*y positive, z positive */ 192 if (fegetround() == FE_UPWARD) { | 120 121 switch (fegetround()) { 122 case FE_TONEAREST: 123 case FE_TOWARDZERO: 124 test(fmaf, -FLT_MIN, FLT_MIN, 0.0, -0.0, 125 ALL_STD_EXCEPT, FE_INEXACT | FE_UNDERFLOW); 126 test(fma, -DBL_MIN, DBL_MIN, 0.0, -0.0, 127 ALL_STD_EXCEPT, FE_INEXACT | FE_UNDERFLOW); --- 63 unchanged lines hidden (view full) --- 191 * Tests for cases where z is very small compared to x*y. 192 */ 193static void 194test_small_z(void) 195{ 196 197 /* x*y positive, z positive */ 198 if (fegetround() == FE_UPWARD) { |
193 test(fmaf, 1.0, 1.0, 0x1.0p-100, 1.0 + FLT_EPSILON, | 199 test(fmaf, one, one, 0x1.0p-100, 1.0 + FLT_EPSILON, |
194 ALL_STD_EXCEPT, FE_INEXACT); | 200 ALL_STD_EXCEPT, FE_INEXACT); |
195 test(fma, 1.0, 1.0, 0x1.0p-200, 1.0 + DBL_EPSILON, | 201 test(fma, one, one, 0x1.0p-200, 1.0 + DBL_EPSILON, |
196 ALL_STD_EXCEPT, FE_INEXACT); | 202 ALL_STD_EXCEPT, FE_INEXACT); |
197 test(fmal, 1.0, 1.0, 0x1.0p-200, 1.0 + LDBL_EPSILON, | 203 test(fmal, one, one, 0x1.0p-200, 1.0 + LDBL_EPSILON, |
198 ALL_STD_EXCEPT, FE_INEXACT); 199 } else { | 204 ALL_STD_EXCEPT, FE_INEXACT); 205 } else { |
200 testall(0x1.0p100, 1.0, 0x1.0p-100, 0x1.0p100, | 206 testall(0x1.0p100, one, 0x1.0p-100, 0x1.0p100, |
201 ALL_STD_EXCEPT, FE_INEXACT); 202 } 203 204 /* x*y negative, z negative */ 205 if (fegetround() == FE_DOWNWARD) { | 207 ALL_STD_EXCEPT, FE_INEXACT); 208 } 209 210 /* x*y negative, z negative */ 211 if (fegetround() == FE_DOWNWARD) { |
206 test(fmaf, -1.0, 1.0, -0x1.0p-100, -(1.0 + FLT_EPSILON), | 212 test(fmaf, -one, one, -0x1.0p-100, -(1.0 + FLT_EPSILON), |
207 ALL_STD_EXCEPT, FE_INEXACT); | 213 ALL_STD_EXCEPT, FE_INEXACT); |
208 test(fma, -1.0, 1.0, -0x1.0p-200, -(1.0 + DBL_EPSILON), | 214 test(fma, -one, one, -0x1.0p-200, -(1.0 + DBL_EPSILON), |
209 ALL_STD_EXCEPT, FE_INEXACT); | 215 ALL_STD_EXCEPT, FE_INEXACT); |
210 test(fmal, -1.0, 1.0, -0x1.0p-200, -(1.0 + LDBL_EPSILON), | 216 test(fmal, -one, one, -0x1.0p-200, -(1.0 + LDBL_EPSILON), |
211 ALL_STD_EXCEPT, FE_INEXACT); 212 } else { | 217 ALL_STD_EXCEPT, FE_INEXACT); 218 } else { |
213 testall(0x1.0p100, -1.0, -0x1.0p-100, -0x1.0p100, | 219 testall(0x1.0p100, -one, -0x1.0p-100, -0x1.0p100, |
214 ALL_STD_EXCEPT, FE_INEXACT); 215 } 216 217 /* x*y positive, z negative */ 218 if (fegetround() == FE_DOWNWARD || fegetround() == FE_TOWARDZERO) { | 220 ALL_STD_EXCEPT, FE_INEXACT); 221 } 222 223 /* x*y positive, z negative */ 224 if (fegetround() == FE_DOWNWARD || fegetround() == FE_TOWARDZERO) { |
219 test(fmaf, 1.0, 1.0, -0x1.0p-100, 1.0 - FLT_EPSILON / 2, | 225 test(fmaf, one, one, -0x1.0p-100, 1.0 - FLT_EPSILON / 2, |
220 ALL_STD_EXCEPT, FE_INEXACT); | 226 ALL_STD_EXCEPT, FE_INEXACT); |
221 test(fma, 1.0, 1.0, -0x1.0p-200, 1.0 - DBL_EPSILON / 2, | 227 test(fma, one, one, -0x1.0p-200, 1.0 - DBL_EPSILON / 2, |
222 ALL_STD_EXCEPT, FE_INEXACT); | 228 ALL_STD_EXCEPT, FE_INEXACT); |
223 test(fmal, 1.0, 1.0, -0x1.0p-200, 1.0 - LDBL_EPSILON / 2, | 229 test(fmal, one, one, -0x1.0p-200, 1.0 - LDBL_EPSILON / 2, |
224 ALL_STD_EXCEPT, FE_INEXACT); 225 } else { | 230 ALL_STD_EXCEPT, FE_INEXACT); 231 } else { |
226 testall(0x1.0p100, 1.0, -0x1.0p-100, 0x1.0p100, | 232 testall(0x1.0p100, one, -0x1.0p-100, 0x1.0p100, |
227 ALL_STD_EXCEPT, FE_INEXACT); 228 } 229 230 /* x*y negative, z positive */ 231 if (fegetround() == FE_UPWARD || fegetround() == FE_TOWARDZERO) { | 233 ALL_STD_EXCEPT, FE_INEXACT); 234 } 235 236 /* x*y negative, z positive */ 237 if (fegetround() == FE_UPWARD || fegetround() == FE_TOWARDZERO) { |
232 test(fmaf, -1.0, 1.0, 0x1.0p-100, -1.0 + FLT_EPSILON / 2, | 238 test(fmaf, -one, one, 0x1.0p-100, -1.0 + FLT_EPSILON / 2, |
233 ALL_STD_EXCEPT, FE_INEXACT); | 239 ALL_STD_EXCEPT, FE_INEXACT); |
234 test(fma, -1.0, 1.0, 0x1.0p-200, -1.0 + DBL_EPSILON / 2, | 240 test(fma, -one, one, 0x1.0p-200, -1.0 + DBL_EPSILON / 2, |
235 ALL_STD_EXCEPT, FE_INEXACT); | 241 ALL_STD_EXCEPT, FE_INEXACT); |
236 test(fmal, -1.0, 1.0, 0x1.0p-200, -1.0 + LDBL_EPSILON / 2, | 242 test(fmal, -one, one, 0x1.0p-200, -1.0 + LDBL_EPSILON / 2, |
237 ALL_STD_EXCEPT, FE_INEXACT); 238 } else { | 243 ALL_STD_EXCEPT, FE_INEXACT); 244 } else { |
239 testall(-0x1.0p100, 1.0, 0x1.0p-100, -0x1.0p100, | 245 testall(-0x1.0p100, one, 0x1.0p-100, -0x1.0p100, |
240 ALL_STD_EXCEPT, FE_INEXACT); 241 } 242} 243 244/* 245 * Tests for cases where z is very large compared to x*y. 246 */ 247static void --- 280 unchanged lines hidden --- | 246 ALL_STD_EXCEPT, FE_INEXACT); 247 } 248} 249 250/* 251 * Tests for cases where z is very large compared to x*y. 252 */ 253static void --- 280 unchanged lines hidden --- |