Deleted Added
sdiff udiff text old ( 226602 ) new ( 251024 )
full compact
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 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/*
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/*
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
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);
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) {
199 test(fmaf, one, one, 0x1.0p-100, 1.0 + FLT_EPSILON,
200 ALL_STD_EXCEPT, FE_INEXACT);
201 test(fma, one, one, 0x1.0p-200, 1.0 + DBL_EPSILON,
202 ALL_STD_EXCEPT, FE_INEXACT);
203 test(fmal, one, one, 0x1.0p-200, 1.0 + LDBL_EPSILON,
204 ALL_STD_EXCEPT, FE_INEXACT);
205 } else {
206 testall(0x1.0p100, one, 0x1.0p-100, 0x1.0p100,
207 ALL_STD_EXCEPT, FE_INEXACT);
208 }
209
210 /* x*y negative, z negative */
211 if (fegetround() == FE_DOWNWARD) {
212 test(fmaf, -one, one, -0x1.0p-100, -(1.0 + FLT_EPSILON),
213 ALL_STD_EXCEPT, FE_INEXACT);
214 test(fma, -one, one, -0x1.0p-200, -(1.0 + DBL_EPSILON),
215 ALL_STD_EXCEPT, FE_INEXACT);
216 test(fmal, -one, one, -0x1.0p-200, -(1.0 + LDBL_EPSILON),
217 ALL_STD_EXCEPT, FE_INEXACT);
218 } else {
219 testall(0x1.0p100, -one, -0x1.0p-100, -0x1.0p100,
220 ALL_STD_EXCEPT, FE_INEXACT);
221 }
222
223 /* x*y positive, z negative */
224 if (fegetround() == FE_DOWNWARD || fegetround() == FE_TOWARDZERO) {
225 test(fmaf, one, one, -0x1.0p-100, 1.0 - FLT_EPSILON / 2,
226 ALL_STD_EXCEPT, FE_INEXACT);
227 test(fma, one, one, -0x1.0p-200, 1.0 - DBL_EPSILON / 2,
228 ALL_STD_EXCEPT, FE_INEXACT);
229 test(fmal, one, one, -0x1.0p-200, 1.0 - LDBL_EPSILON / 2,
230 ALL_STD_EXCEPT, FE_INEXACT);
231 } else {
232 testall(0x1.0p100, one, -0x1.0p-100, 0x1.0p100,
233 ALL_STD_EXCEPT, FE_INEXACT);
234 }
235
236 /* x*y negative, z positive */
237 if (fegetround() == FE_UPWARD || fegetround() == FE_TOWARDZERO) {
238 test(fmaf, -one, one, 0x1.0p-100, -1.0 + FLT_EPSILON / 2,
239 ALL_STD_EXCEPT, FE_INEXACT);
240 test(fma, -one, one, 0x1.0p-200, -1.0 + DBL_EPSILON / 2,
241 ALL_STD_EXCEPT, FE_INEXACT);
242 test(fmal, -one, one, 0x1.0p-200, -1.0 + LDBL_EPSILON / 2,
243 ALL_STD_EXCEPT, FE_INEXACT);
244 } else {
245 testall(-0x1.0p100, one, 0x1.0p-100, -0x1.0p100,
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 ---