Skip to content

Commit 4dafd99

Browse files
futogkeith-packard
authored andcommitted
libm: use the WANT_ROUNDING macro in #if directives
Use preprocessor directives instead of using the macro in if statements.
1 parent a723a70 commit 4dafd99

File tree

6 files changed

+33
-11
lines changed

6 files changed

+33
-11
lines changed

newlib/libm/common/exp.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ specialcase (double_t tmp, uint64_t sbits, uint64_t ki)
8181
lo = 1.0 - hi + y + lo;
8282
y = eval_as_double (hi + lo) - 1.0;
8383
/* Avoid -0.0 with downward rounding. */
84-
if (WANT_ROUNDING && y == 0.0)
84+
#if WANT_ROUNDING
85+
if (y == 0.0)
8586
y = 0.0;
87+
#endif
8688
/* The underflow exception needs to be signaled explicitly. */
8789
force_eval_double (opt_barrier_double (0x1p-1022) * 0x1p-1022);
8890
}
@@ -111,7 +113,11 @@ exp (double x)
111113
if (abstop - top12 (0x1p-54) >= 0x80000000)
112114
/* Avoid spurious underflow for tiny x. */
113115
/* Note: 0 is common input. */
114-
return WANT_ROUNDING ? 1.0 + x : 1.0;
116+
#if WANT_ROUNDING
117+
return 1.0 + x;
118+
#else
119+
return 1.0;
120+
#endif
115121
if (abstop >= top12 (1024.0))
116122
{
117123
if (asuint64 (x) == asuint64 ((double) -INFINITY))

newlib/libm/common/exp2.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ specialcase (double_t tmp, uint64_t sbits, uint64_t ki)
7979
lo = 1.0 - hi + y + lo;
8080
y = eval_as_double (hi + lo) - 1.0;
8181
/* Avoid -0.0 with downward rounding. */
82-
if (WANT_ROUNDING && y == 0.0)
82+
#if WANT_ROUNDING
83+
if (y == 0.0)
8384
y = 0.0;
85+
#endif
8486
/* The underflow exception needs to be signaled explicitly. */
8587
force_eval_double (opt_barrier_double (0x1p-1022) * 0x1p-1022);
8688
}
@@ -109,7 +111,11 @@ exp2 (double x)
109111
if (abstop - top12 (0x1p-54) >= 0x80000000)
110112
/* Avoid spurious underflow for tiny x. */
111113
/* Note: 0 is common input. */
112-
return WANT_ROUNDING ? 1.0 + x : 1.0;
114+
#if WANT_ROUNDING
115+
return 1.0 + x;
116+
#else
117+
return 1.0;
118+
#endif
113119
if (abstop >= top12 (1024.0))
114120
{
115121
if (asuint64 (x) == asuint64 ((double) -INFINITY))

newlib/libm/common/log.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ log (double x)
7272
{
7373
/* Handle close to 1.0 inputs separately. */
7474
/* Fix sign of zero with downward rounding when x==1. */
75-
if (WANT_ROUNDING && unlikely (ix == asuint64 (1.0)))
75+
#if WANT_ROUNDING
76+
if (unlikely (ix == asuint64 (1.0)))
7677
return 0;
78+
#endif
7779
r = x - 1.0;
7880
r2 = r * r;
7981
r3 = r * r2;

newlib/libm/common/log2.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ double
6969
{
7070
/* Handle close to 1.0 inputs separately. */
7171
/* Fix sign of zero with downward rounding when x==1. */
72-
if (WANT_ROUNDING && unlikely (ix == asuint64 (1.0)))
72+
#if WANT_ROUNDING
73+
if (unlikely (ix == asuint64 (1.0)))
7374
return 0;
75+
#endif
7476
r = x - 1.0;
7577
#if __HAVE_FAST_FMA
7678
hi = r * InvLn2hi;

newlib/libm/common/pow.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,11 @@ exp_inline (double x, double xtail, uint32_t sign_bias)
211211
{
212212
/* Avoid spurious underflow for tiny x. */
213213
/* Note: 0 is common input. */
214-
double_t one = WANT_ROUNDING ? 1.0 + x : 1.0;
214+
#if WANT_ROUNDING
215+
double_t one = 1.0 + x;
216+
#else
217+
double_t one = 1.0;
218+
#endif
215219
return sign_bias ? -one : one;
216220
}
217221
if (abstop >= top12 (1024.0))
@@ -363,10 +367,11 @@ pow (double x, double y)
363367
if ((topy & 0x7ff) < 0x3be)
364368
{
365369
/* |y| < 2^-65, x^y ~= 1 + y*log(x). */
366-
if (WANT_ROUNDING)
370+
#if WANT_ROUNDING
367371
return ix > asuint64 (1.0) ? 1.0 + y : 1.0 - y;
368-
else
372+
#else
369373
return 1.0;
374+
#endif
370375
}
371376
return (ix > asuint64 (1.0)) == (topy < 0x800) ? __math_oflow (0)
372377
: __math_uflow (0);

newlib/libm/common/sf_pow.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,16 @@ powf (float x, float y)
224224
if (ylogx > 0x1.fffffffd1d571p+6 * POWF_SCALE)
225225
/* |x^y| > 0x1.ffffffp127. */
226226
return __math_oflowf (sign_bias);
227-
if (WANT_ROUNDING && WANT_ERRNO
228-
&& ylogx > 0x1.fffffffa3aae2p+6 * POWF_SCALE)
227+
#if WANT_ROUNDING && WANT_ERRNO
228+
if (ylogx > 0x1.fffffffa3aae2p+6 * POWF_SCALE)
229229
/* |x^y| > 0x1.fffffep127, check if we round away from 0. */
230230
if ((!sign_bias
231231
&& eval_as_float (1.0f + opt_barrier_float (0x1p-25f)) != 1.0f)
232232
|| (sign_bias
233233
&& eval_as_float (-1.0f - opt_barrier_float (0x1p-25f))
234234
!= -1.0f))
235235
return __math_oflowf (sign_bias);
236+
#endif
236237
if (ylogx <= -150.0 * POWF_SCALE)
237238
return __math_uflowf (sign_bias);
238239
#if WANT_ERRNO_UFLOW

0 commit comments

Comments
 (0)