Skip to content

Commit

Permalink
Use non-signaling floating-point comparisons in math functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurelien Jarno committed Feb 19, 2012
1 parent ebaf36e commit 9222155
Show file tree
Hide file tree
Showing 41 changed files with 161 additions and 92 deletions.
43 changes: 43 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
2012-02-19 Aurelien Jarno <aurelien@aurel32.net>

* math/w_acos.c: Use non-signaling floating-point comparisons.
* math/w_acosf.c: Likewise.
* math/w_acosh.c: Likewise.
* math/w_acoshf.c: Likewise.
* math/w_acoshl.c: Likewise.
* math/w_acosl.c: Likewise.
* math/w_asin.c: Likewise.
* math/w_asinf.c: Likewise.
* math/w_asinl.c: Likewise.
* math/w_atanh.c: Likewise.
* math/w_atanhf.c: Likewise.
* math/w_atanhl.c: Likewise.
* math/w_exp2.c: Likewise.
* math/w_exp2f.c: Likewise.
* math/w_exp2l.c: Likewise.
* math/w_j0.c: Likewise.
* math/w_j0f.c: Likewise.
* math/w_j0l.c: Likewise.
* math/w_j1.c: Likewise.
* math/w_j1f.c: Likewise.
* math/w_j1l.c: Likewise.
* math/w_jn.c: Likewise.
* math/w_jnf.c: Likewise.
* math/w_log.c: Likewise.
* math/w_log10.c: Likewise.
* math/w_log10f.c: Likewise.
* math/w_log10l.c: Likewise.
* math/w_log2.c: Likewise.
* math/w_log2f.c: Likewise.
* math/w_log2l.c: Likewise.
* math/w_logf.c: Likewise.
* math/w_logl.c: Likewise.
* math/w_sqrt.c: Likewise.
* math/w_sqrtf.c: Likewise.
* math/w_sqrtl.c: Likewise.
* sysdeps/ieee754/dbl-64/e_atanh.c: Likewise.
* sysdeps/ieee754/dbl-64/w_exp.c: Likewise.
* sysdeps/ieee754/flt-32/e_atanhf.c: Likewise.
* sysdeps/ieee754/flt-32/w_expf.c: Likewise.
* sysdeps/ieee754/ldbl-96/w_expl.c: Likewise.

2012-02-19 Joseph Myers <joseph@codesourcery.com>

[BZ #9739]
Expand Down
5 changes: 3 additions & 2 deletions math/w_acos.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2011 Free Software Foundation, Inc.
/* Copyright (C) 2011, 2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gmail.com>, 2011.
Expand All @@ -25,7 +25,8 @@
double
__acos (double x)
{
if (__builtin_expect (fabs (x) > 1.0, 0) && _LIB_VERSION != _IEEE_)
if (__builtin_expect (isgreater (fabs (x), 1.0), 0)
&& _LIB_VERSION != _IEEE_)
{
/* acos(|x|>1) */
feraiseexcept (FE_INVALID);
Expand Down
5 changes: 3 additions & 2 deletions math/w_acosf.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2011 Free Software Foundation, Inc.
/* Copyright (C) 2011, 2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gmail.com>, 2011.
Expand All @@ -25,7 +25,8 @@
float
__acosf (float x)
{
if (__builtin_expect (fabsf (x) > 1.0f, 0) && _LIB_VERSION != _IEEE_)
if (__builtin_expect (isgreater (fabsf (x), 1.0f), 0)
&& _LIB_VERSION != _IEEE_)
{
/* acos(|x|>1) */
feraiseexcept (FE_INVALID);
Expand Down
4 changes: 2 additions & 2 deletions math/w_acosh.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2011 Free Software Foundation, Inc.
/* Copyright (C) 2011, 2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gmail.com>, 2011.
Expand All @@ -24,7 +24,7 @@
double
__acosh (double x)
{
if (__builtin_expect (x < 1.0, 0) && _LIB_VERSION != _IEEE_)
if (__builtin_expect (isless (x, 1.0), 0) && _LIB_VERSION != _IEEE_)
/* acosh(x<1) */
return __kernel_standard (x, x, 29);

Expand Down
4 changes: 2 additions & 2 deletions math/w_acoshf.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2011 Free Software Foundation, Inc.
/* Copyright (C) 2011, 2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gmail.com>, 2011.
Expand All @@ -24,7 +24,7 @@
float
__acoshf (float x)
{
if (__builtin_expect (x < 1.0f, 0) && _LIB_VERSION != _IEEE_)
if (__builtin_expect (isless (x, 1.0f), 0) && _LIB_VERSION != _IEEE_)
/* acosh(x<1) */
return __kernel_standard_f (x, x, 129);

Expand Down
4 changes: 2 additions & 2 deletions math/w_acoshl.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2011 Free Software Foundation, Inc.
/* Copyright (C) 2011, 2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gmail.com>, 2011.
Expand All @@ -24,7 +24,7 @@
long double
__acoshl (long double x)
{
if (__builtin_expect (x < 1.0L, 0) && _LIB_VERSION != _IEEE_)
if (__builtin_expect (isless (x, 1.0L), 0) && _LIB_VERSION != _IEEE_)
/* acosh(x<1) */
return __kernel_standard (x, x, 229);

Expand Down
5 changes: 3 additions & 2 deletions math/w_acosl.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2011 Free Software Foundation, Inc.
/* Copyright (C) 2011, 2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gmail.com>, 2011.
Expand All @@ -25,7 +25,8 @@
long double
__acosl (long double x)
{
if (__builtin_expect (fabsl (x) > 1.0L, 0) && _LIB_VERSION != _IEEE_)
if (__builtin_expect (isgreater (fabsl (x), 1.0L), 0)
&& _LIB_VERSION != _IEEE_)
{
/* acos(|x|>1) */
feraiseexcept (FE_INVALID);
Expand Down
5 changes: 3 additions & 2 deletions math/w_asin.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2011 Free Software Foundation, Inc.
/* Copyright (C) 2011, 2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gmail.com>, 2011.
Expand All @@ -25,7 +25,8 @@
double
__asin (double x)
{
if (__builtin_expect (fabs (x) > 1.0, 0) && _LIB_VERSION != _IEEE_)
if (__builtin_expect (isgreater (fabs (x), 1.0), 0)
&& _LIB_VERSION != _IEEE_)
{
/* asin(|x|>1) */
feraiseexcept (FE_INVALID);
Expand Down
5 changes: 3 additions & 2 deletions math/w_asinf.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2011 Free Software Foundation, Inc.
/* Copyright (C) 2011, 2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gmail.com>, 2011.
Expand All @@ -25,7 +25,8 @@
float
__asinf (float x)
{
if (__builtin_expect (fabsf (x) > 1.0f, 0) && _LIB_VERSION != _IEEE_)
if (__builtin_expect (isgreater (fabsf (x), 1.0f), 0)
&& _LIB_VERSION != _IEEE_)
{
/* asin(|x|>1) */
feraiseexcept (FE_INVALID);
Expand Down
5 changes: 3 additions & 2 deletions math/w_asinl.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2011 Free Software Foundation, Inc.
/* Copyright (C) 2011, 2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gmail.com>, 2011.
Expand All @@ -25,7 +25,8 @@
long double
__asinl (long double x)
{
if (__builtin_expect (fabsl (x) > 1.0L, 0) && _LIB_VERSION != _IEEE_)
if (__builtin_expect (isgreater (fabsl (x), 1.0L), 0)
&& _LIB_VERSION != _IEEE_)
{
/* asin(|x|>1) */
feraiseexcept (FE_INVALID);
Expand Down
5 changes: 3 additions & 2 deletions math/w_atanh.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2011 Free Software Foundation, Inc.
/* Copyright (C) 2011, 2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gmail.com>, 2011.
Expand All @@ -24,7 +24,8 @@
double
__atanh (double x)
{
if (__builtin_expect (fabs (x) >= 1.0, 0) && _LIB_VERSION != _IEEE_)
if (__builtin_expect (isgreaterequal (fabs (x), 1.0), 0)
&& _LIB_VERSION != _IEEE_)
return __kernel_standard (x, x,
fabs (x) > 1.0
? 30 /* atanh(|x|>1) */
Expand Down
5 changes: 3 additions & 2 deletions math/w_atanhf.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2011 Free Software Foundation, Inc.
/* Copyright (C) 2011, 2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gmail.com>, 2011.
Expand All @@ -24,7 +24,8 @@
float
__atanhf (float x)
{
if (__builtin_expect (fabsf (x) >= 1.0f, 0) && _LIB_VERSION != _IEEE_)
if (__builtin_expect (isgreaterequal (fabsf (x), 1.0f), 0)
&& _LIB_VERSION != _IEEE_)
return __kernel_standard_f (x, x,
fabsf (x) > 1.0f
? 130 /* atanh(|x|>1) */
Expand Down
5 changes: 3 additions & 2 deletions math/w_atanhl.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2011 Free Software Foundation, Inc.
/* Copyright (C) 2011, 2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gmail.com>, 2011.
Expand All @@ -24,7 +24,8 @@
long double
__atanhl (long double x)
{
if (__builtin_expect (fabsl (x) >= 1.0L, 0) && _LIB_VERSION != _IEEE_)
if (__builtin_expect (isgreaterequal (fabsl (x), 1.0L), 0)
&& _LIB_VERSION != _IEEE_)
return __kernel_standard (x, x,
fabsl (x) > 1.0L
? 230 /* atanh(|x|>1) */
Expand Down
3 changes: 2 additions & 1 deletion math/w_exp2.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ static const double u_threshold = (double) (DBL_MIN_EXP - DBL_MANT_DIG - 1);
double
__exp2 (double x)
{
if (__builtin_expect (x <= u_threshold || x > o_threshold, 0)
if (__builtin_expect (islessequal (x, u_threshold)
|| isgreater (x, o_threshold), 0)
&& _LIB_VERSION != _IEEE_ && __finite (x))
/* exp2 overflow: 44, exp2 underflow: 45 */
return __kernel_standard (x, x, 44 + (x <= o_threshold));
Expand Down
3 changes: 2 additions & 1 deletion math/w_exp2f.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ static const float u_threshold = (float) (FLT_MIN_EXP - FLT_MANT_DIG - 1);
float
__exp2f (float x)
{
if (__builtin_expect (x <= u_threshold || x > o_threshold, 0)
if (__builtin_expect (islessequal (x, u_threshold)
|| isgreater (x, o_threshold), 0)
&& _LIB_VERSION != _IEEE_ && __finitef (x))
/* exp2 overflow: 144, exp2 underflow: 145 */
return __kernel_standard_f (x, x, 144 + (x <= o_threshold));
Expand Down
3 changes: 2 additions & 1 deletion math/w_exp2l.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ static const long double u_threshold
long double
__exp2l (long double x)
{
if (__builtin_expect (x <= u_threshold || x > o_threshold, 0)
if (__builtin_expect (islessequal (x, u_threshold)
|| isgreater (x, o_threshold), 0)
&& _LIB_VERSION != _IEEE_ && __finitel (x))
/* exp2 overflow: 244, exp2 underflow: 245 */
return __kernel_standard (x, x, 244 + (x <= o_threshold));
Expand Down
8 changes: 5 additions & 3 deletions math/w_j0.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2011 Free Software Foundation, Inc.
/* Copyright (C) 2011, 2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gmail.com>, 2011.
Expand All @@ -25,7 +25,8 @@
double
j0 (double x)
{
if (__builtin_expect (fabs (x) > X_TLOSS, 0) && _LIB_VERSION != _IEEE_)
if (__builtin_expect (isgreater (fabs (x), X_TLOSS), 0)
&& _LIB_VERSION != _IEEE_)
/* j0(|x|>X_TLOSS) */
return __kernel_standard (x, x, 34);

Expand All @@ -40,7 +41,8 @@ strong_alias (j0, j0l)
double
y0 (double x)
{
if (__builtin_expect (x <= 0.0 || x > X_TLOSS, 0) && _LIB_VERSION != _IEEE_)
if (__builtin_expect (islessequal (x, 0.0) || isgreater (x, X_TLOSS), 0)
&& _LIB_VERSION != _IEEE_)
{
if (x < 0.0)
{
Expand Down
7 changes: 4 additions & 3 deletions math/w_j0f.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2011 Free Software Foundation, Inc.
/* Copyright (C) 2011, 2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gmail.com>, 2011.
Expand All @@ -25,7 +25,7 @@
float
j0f (float x)
{
if (__builtin_expect (fabsf (x) > (float) X_TLOSS, 0)
if (__builtin_expect (isgreater (fabsf (x), (float) X_TLOSS), 0)
&& _LIB_VERSION != _IEEE_)
/* j0(|x|>X_TLOSS) */
return __kernel_standard_f (x, x, 134);
Expand All @@ -38,7 +38,8 @@ j0f (float x)
float
y0f (float x)
{
if (__builtin_expect (x <= 0.0f || x > (float) X_TLOSS, 0)
if (__builtin_expect (islessequal (x, 0.0f)
|| isgreater (x, (float) X_TLOSS), 0)
&& _LIB_VERSION != _IEEE_)
{
if (x < 0.0f)
Expand Down
8 changes: 5 additions & 3 deletions math/w_j0l.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2011 Free Software Foundation, Inc.
/* Copyright (C) 2011, 2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gmail.com>, 2011.
Expand All @@ -25,7 +25,8 @@
long double
__j0l (long double x)
{
if (__builtin_expect (fabsl (x) > X_TLOSS, 0) && _LIB_VERSION != _IEEE_)
if (__builtin_expect (isgreater (fabsl (x), X_TLOSS), 0)
&& _LIB_VERSION != _IEEE_)
/* j0(|x|>X_TLOSS) */
return __kernel_standard (x, x, 234);

Expand All @@ -38,7 +39,8 @@ weak_alias (__j0l, j0l)
long double
__y0l (long double x)
{
if (__builtin_expect (x <= 0.0L || x > X_TLOSS, 0) && _LIB_VERSION != _IEEE_)
if (__builtin_expect (islessequal (x, 0.0L) || isgreater (x, X_TLOSS), 0)
&& _LIB_VERSION != _IEEE_)
{
if (x < 0.0L)
{
Expand Down
8 changes: 5 additions & 3 deletions math/w_j1.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2011 Free Software Foundation, Inc.
/* Copyright (C) 2011, 2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gmail.com>, 2011.
Expand All @@ -25,7 +25,8 @@
double
j1 (double x)
{
if (__builtin_expect (fabs (x) > X_TLOSS, 0) && _LIB_VERSION != _IEEE_)
if (__builtin_expect (isgreater (fabs (x), X_TLOSS), 0)
&& _LIB_VERSION != _IEEE_)
/* j1(|x|>X_TLOSS) */
return __kernel_standard (x, x, 36);

Expand All @@ -40,7 +41,8 @@ strong_alias (j1, j1l)
double
y1 (double x)
{
if (__builtin_expect (x <= 0.0 || x > X_TLOSS, 0) && _LIB_VERSION != _IEEE_)
if (__builtin_expect (islessequal (x, 0.0) || isgreater (x, X_TLOSS), 0)
&& _LIB_VERSION != _IEEE_)
{
if (x < 0.0)
{
Expand Down
8 changes: 5 additions & 3 deletions math/w_j1f.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2011 Free Software Foundation, Inc.
/* Copyright (C) 2011, 2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gmail.com>, 2011.
Expand All @@ -25,7 +25,8 @@
float
j1f (float x)
{
if (__builtin_expect (fabsf (x) > X_TLOSS, 0) && _LIB_VERSION != _IEEE_)
if (__builtin_expect (isgreater (fabsf (x), X_TLOSS), 0)
&& _LIB_VERSION != _IEEE_)
/* j1(|x|>X_TLOSS) */
return __kernel_standard_f (x, x, 136);

Expand All @@ -37,7 +38,8 @@ j1f (float x)
float
y1f (float x)
{
if (__builtin_expect (x <= 0.0f || x > (float) X_TLOSS, 0)
if (__builtin_expect (islessequal (x, 0.0f)
|| isgreater (x, (float) X_TLOSS), 0)
&& _LIB_VERSION != _IEEE_)
{
if (x < 0.0f)
Expand Down
Loading

0 comments on commit 9222155

Please sign in to comment.