diff options
| author | Joseph Myers <josmyers@redhat.com> | 2024-06-17 16:31:49 +0000 |
|---|---|---|
| committer | Joseph Myers <josmyers@redhat.com> | 2024-06-17 16:31:49 +0000 |
| commit | 7ec903e028271d029818378fd60ddaf6b76b89ac (patch) | |
| tree | 29840403dc63c9c633e18e1d6607280ae59ce601 | |
| parent | 55eb99e9a9d840ba452b128be14d6529c2dde039 (diff) | |
| download | glibc-7ec903e028271d029818378fd60ddaf6b76b89ac.tar.xz glibc-7ec903e028271d029818378fd60ddaf6b76b89ac.zip | |
Implement C23 exp2m1, exp10m1
C23 adds various <math.h> function families originally defined in TS
18661-4. Add the exp2m1 and exp10m1 functions (exp2(x)-1 and
exp10(x)-1, like expm1).
As with other such functions, these use type-generic templates that
could be replaced with faster and more accurate type-specific
implementations in future. Test inputs are copied from those for
expm1, plus some additions close to the overflow threshold (copied
from exp2 and exp10) and also some near the underflow threshold.
exp2m1 has the unusual property of having an input (M_MAX_EXP) where
whether the function overflows (under IEEE semantics) depends on the
rounding mode. Although these could reasonably be XFAILed in the
testsuite (as we do in some cases for arguments very close to a
function's overflow threshold when an error of a few ulps in the
implementation can result in the implementation not agreeing with an
ideal one on whether overflow takes place - the testsuite isn't smart
enough to handle this automatically), since these functions aren't
required to be correctly rounding, I made the implementation check for
and handle this case specially.
The Makefile ordering expected by lint-makefiles for the new functions
is a bit peculiar, but I implemented it in this patch so that the test
passes; I don't know why log2 also needed moving in one Makefile
variable setting when it didn't in my previous patches, but the
failure showed a different place was expected for that function as
well.
The powerpc64le IFUNC setup seems not to be as self-contained as one
might hope; it shouldn't be necessary to add IFUNCs for new functions
such as these simply to get them building, but without setting up
IFUNCs for the new functions, there were undefined references to
__GI___expm1f128 (that IFUNC machinery results in no such function
being defined, but doesn't stop include/math.h from doing the
redirection resulting in the exp2m1f128 and exp10m1f128
implementations expecting to call it).
Tested for x86_64 and x86, and with build-many-glibcs.py.
58 files changed, 9923 insertions, 3 deletions
@@ -26,6 +26,8 @@ Major new features: functions for float, double, long double, _FloatN and _FloatNx, and a type-generic macro in <tgmath.h>. + - Exponential functions: exp2m1, exp10m1. + - Logarithmic functions: log2p1, log10p1, logp1. * A new tunable, glibc.rtld.enable_secure, used to run a program diff --git a/manual/math.texi b/manual/math.texi index 18b7173bf0..e4f9122609 100644 --- a/manual/math.texi +++ b/manual/math.texi @@ -740,6 +740,36 @@ near zero---a case where @code{exp (@var{x}) - 1} would be inaccurate owing to subtraction of two numbers that are nearly equal. @end deftypefun +@deftypefun double exp2m1 (double @var{x}) +@deftypefunx float exp2m1f (float @var{x}) +@deftypefunx {long double} exp2m1l (long double @var{x}) +@deftypefunx _FloatN exp2m1fN (_Float@var{N} @var{x}) +@deftypefunx _FloatNx exp2m1fNx (_Float@var{N}x @var{x}) +@standards{TS 18661-4:2015, math.h} +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} +These functions return a value equivalent to @code{exp2 (@var{x}) - 1}. +They are computed in a way that is accurate even if @var{x} is +near zero---a case where @code{exp2 (@var{x}) - 1} would be inaccurate owing +to subtraction of two numbers that are nearly equal. + +The @code{exp2m1} functions are from TS 18661-4:2015. +@end deftypefun + +@deftypefun double exp10m1 (double @var{x}) +@deftypefunx float exp10m1f (float @var{x}) +@deftypefunx {long double} exp10m1l (long double @var{x}) +@deftypefunx _FloatN exp10m1fN (_Float@var{N} @var{x}) +@deftypefunx _FloatNx exp10m1fNx (_Float@var{N}x @var{x}) +@standards{TS 18661-4:2015, math.h} +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} +These functions return a value equivalent to @code{exp10 (@var{x}) - 1}. +They are computed in a way that is accurate even if @var{x} is +near zero---a case where @code{exp10 (@var{x}) - 1} would be inaccurate owing +to subtraction of two numbers that are nearly equal. + +The @code{exp10m1} functions are from TS 18661-4:2015. +@end deftypefun + @deftypefun double log1p (double @var{x}) @deftypefunx float log1pf (float @var{x}) @deftypefunx {long double} log1pl (long double @var{x}) diff --git a/math/Makefile b/math/Makefile index 95085d9601..f06d370383 100644 --- a/math/Makefile +++ b/math/Makefile @@ -113,6 +113,8 @@ gen-libm-calls = \ s_csqrtF \ s_ctanF \ s_ctanhF \ + s_exp10m1F \ + s_exp2m1F \ s_fdimF \ s_fmaxF \ s_fmaximumF \ @@ -643,6 +645,8 @@ libm-test-funcs-auto = \ exp \ exp2 \ exp10 \ + exp10m1 \ + exp2m1 \ expm1 \ fma \ hypot \ @@ -651,10 +655,10 @@ libm-test-funcs-auto = \ jn \ lgamma \ log \ + log2 \ log10 \ log10p1 \ log1p \ - log2 \ log2p1 \ pow \ sin \ @@ -932,8 +936,10 @@ tgmath3-macros = \ erf \ erfc \ exp \ + exp10m1 \ exp2 \ exp10 \ + exp2m1 \ expm1 \ fabs \ fdim \ @@ -1328,7 +1334,9 @@ CFLAGS-s_erf.c += -fno-builtin-erfl CFLAGS-s_erfc.c += -fno-builtin-erfcl CFLAGS-e_exp.c += -fno-builtin-expl CFLAGS-w_exp10.c += -fno-builtin-exp10l +CFLAGS-s_exp10m1.c += -fno-builtin-exp10m1l CFLAGS-e_exp2.c += -fno-builtin-exp2l +CFLAGS-s_exp2m1.c += -fno-builtin-exp2m1l CFLAGS-s_expm1.c += -fno-builtin-expm1l CFLAGS-s_f32xaddf64.c += -fno-builtin-daddl CFLAGS-s_f32xdivf64.c += -fno-builtin-ddivl @@ -1464,7 +1472,9 @@ CFLAGS-s_erf.c += -fno-builtin-erff32x -fno-builtin-erff64 CFLAGS-s_erfc.c += -fno-builtin-erfcf32x -fno-builtin-erfcf64 CFLAGS-e_exp.c += -fno-builtin-expf32x -fno-builtin-expf64 CFLAGS-w_exp10.c += -fno-builtin-exp10f32x -fno-builtin-exp10f64 +CFLAGS-s_exp10m1.c += -fno-builtin-exp10m1f32x -fno-builtin-exp10m1f64 CFLAGS-e_exp2.c += -fno-builtin-exp2f32x -fno-builtin-exp2f64 +CFLAGS-s_exp2m1.c += -fno-builtin-exp2m1f32x -fno-builtin-exp2m1f64 CFLAGS-s_expm1.c += -fno-builtin-expm1f32x -fno-builtin-expm1f64 CFLAGS-s_fabs.c += -fno-builtin-fabsf32x -fno-builtin-fabsf64 CFLAGS-s_fadd.c += -fno-builtin-f32addf32x -fno-builtin-f32addf64 @@ -1586,7 +1596,9 @@ CFLAGS-s_erff.c += -fno-builtin-erff32 CFLAGS-s_erfcf.c += -fno-builtin-erfcf32 CFLAGS-e_expf.c += -fno-builtin-expf32 CFLAGS-w_exp10f.c += -fno-builtin-exp10f32 +CFLAGS-s_exp10m1f.c += -fno-builtin-exp10m1f32 CFLAGS-e_exp2f.c += -fno-builtin-exp2f32 +CFLAGS-s_exp2m1f.c += -fno-builtin-exp2m1f32 CFLAGS-s_expm1f.c += -fno-builtin-expm1f32 CFLAGS-s_fabsf.c += -fno-builtin-fabsf32 CFLAGS-s_fdimf.c += -fno-builtin-fdimf32 diff --git a/math/Versions b/math/Versions index 633722f8c6..49d61f212f 100644 --- a/math/Versions +++ b/math/Versions @@ -641,10 +641,14 @@ libm { } GLIBC_2.40 { # Functions not involving _Float64x or _Float128, for all configurations. + exp2m1; exp2m1f; exp2m1l; exp2m1f32; exp2m1f64; exp2m1f32x; + exp10m1; exp10m1f; exp10m1l; exp10m1f32; exp10m1f64; exp10m1f32x; log2p1; log2p1f; log2p1l; log2p1f32; log2p1f64; log2p1f32x; log10p1; log10p1f; log10p1l; log10p1f32; log10p1f64; log10p1f32x; logp1; logp1f; logp1l; logp1f32; logp1f64; logp1f32x; # Functions involving _Float64x or _Float128, for some configurations. + exp2m1f64x; exp2m1f128; + exp10m1f64x; exp10m1f128; log2p1f64x; log2p1f128; log10p1f64x; log10p1f128; logp1f64x; logp1f128; diff --git a/math/auto-libm-test-in b/math/auto-libm-test-in index 16b1d3e0c6..8f0c3d87bb 100644 --- a/math/auto-libm-test-in +++ b/math/auto-libm-test-in @@ -5249,6 +5249,106 @@ exp10 0xe.8b349p+4 exp10 0x3.495c78p+0 exp10 0xf.f33f6p+0 +exp10m1 0 +exp10m1 -0 +exp10m1 1 +exp10m1 0.75 +exp10m1 2 +exp10m1 3 +exp10m1 4 +exp10m1 5 +exp10m1 10 +exp10m1 15 +exp10m1 20 +exp10m1 25 +exp10m1 30 +exp10m1 35 +exp10m1 40 +exp10m1 50.0 +exp10m1 60 +exp10m1 70 +exp10m1 80 +exp10m1 90 +exp10m1 100 +exp10m1 127.0 +exp10m1 500.0 +exp10m1 11356.25 +exp10m1 -10.0 +exp10m1 -16.0 +exp10m1 -17.0 +exp10m1 -18.0 +exp10m1 -36.0 +exp10m1 -37.0 +exp10m1 -38.0 +exp10m1 -44.0 +exp10m1 -45.0 +exp10m1 -46.0 +exp10m1 -73.0 +exp10m1 -74.0 +exp10m1 -75.0 +exp10m1 -78.0 +exp10m1 -79.0 +exp10m1 -80.0 +exp10m1 -100.0 +exp10m1 -1000.0 +exp10m1 -10000.0 +exp10m1 -100000.0 +exp10m1 100000.0 +exp10m1 max +exp10m1 -max +exp10m1 0x1p-2 +exp10m1 -0x1p-2 +exp10m1 0x1p-10 +exp10m1 -0x1p-10 +exp10m1 0x1p-20 +exp10m1 -0x1p-20 +exp10m1 0x1p-29 +exp10m1 -0x1p-29 +exp10m1 0x1p-32 +exp10m1 -0x1p-32 +exp10m1 0x1p-50 +exp10m1 -0x1p-50 +exp10m1 0x1p-64 +exp10m1 -0x1p-64 +exp10m1 0x1p-100 +exp10m1 -0x1p-100 +exp10m1 0x1p-600 +exp10m1 -0x1p-600 +exp10m1 0x1p-10000 +exp10m1 -0x1p-10000 +exp10m1 0xe.4152ac57cd1ea7ap-60 +exp10m1 0x6.660247486aed8p-4 +exp10m1 0x6.289a78p-4 +exp10m1 0x6.1b4d318238d4a2a8p-4 +exp10m1 0x5.fb8dc64e91a74p-4 |
