glibc/sysdeps/ieee754
Vincent Lefevre 68d7128942 math: Fix non-portability in the computation of signgam in lgammaf
The k>>31 in signgam = 1 - (((k&(k>>31))&1)<<1); is not portable:

* The ISO C standard says "If E1 has a signed type and a negative
  value, the resulting value is implementation-defined." (this is
  still in C23).
* If the int type is larger than 32 bits (e.g. a 64-bit type),
  then k = INT_MAX; line 144 will make k>>31 put 1 in bit 0
  (thus signgam will be -1) while 0 is expected.

Moreover, instead of the fx >= 0x1p31f condition, testing fx >= 0
is probably better for 2 reasons:

The signgam expression has more or less a condition on the sign
of fx (the goal of k>>31, which can be dropped with this new
condition). Since fx ≥ 0 should be the most common case, one can
get signgam directly in this case (value 1). And this simplifies
the expression for the other case (fx < 0).

This new condition may be easier/faster to test on the processor
(e.g. by avoiding a load of a constant from the memory).

This is commit d41459c731865516318f813cf4c966dafa0eecbf from CORE-MATH.

Checked on x86_64-linux-gnu.
2024-11-25 09:20:47 -03:00
..
dbl-64 math: Split s_erfF in erff and erfc 2024-11-22 10:52:26 -03:00
float128 math: Split s_erfF in erff and erfc 2024-11-22 10:52:26 -03:00
flt-32 math: Fix non-portability in the computation of signgam in lgammaf 2024-11-25 09:20:47 -03:00
ldbl-64-128 math: Provide missing math symbols on libc.a (BZ 31781) 2024-05-23 09:36:08 -03:00
ldbl-96 math: Split s_erfF in erff and erfc 2024-11-22 10:52:26 -03:00
ldbl-128 math: Split s_erfF in erff and erfc 2024-11-22 10:52:26 -03:00
ldbl-128ibm math: Split s_erfF in erff and erfc 2024-11-22 10:52:26 -03:00
ldbl-128ibm-compat Implement C23 exp2m1, exp10m1 2024-06-17 16:31:49 +00:00
ldbl-opt Convert to autoconf 2.72 (vanilla release, no distribution patches) 2024-06-17 21:15:28 +02:00
soft-fp Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
ieee754.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
k_standard.c Use copysign functions not __copysign functions in glibc libm. 2018-09-27 20:04:48 +00:00
k_standardf.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
k_standardl.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
libm-alias-finite.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
Makefile Avoid -Wno-write-strings for k_standard.c. 2015-02-26 22:50:54 +00:00
s_lib_version.c Simplify math-svid-compat code. 2017-08-28 15:19:52 +00:00
s_matherr.c Obsolete matherr, _LIB_VERSION, libieee.a. 2017-08-21 17:45:10 +00:00
s_signgam.c Remove unnecessary math_private.h includes. 2018-09-28 21:53:33 +00:00