Skip to content

Commit

Permalink
Implement C23 exp2m1, exp10m1
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jsm28 committed Jun 17, 2024
1 parent 55eb99e commit 7ec903e
Show file tree
Hide file tree
Showing 58 changed files with 9,923 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions manual/math.texi
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
14 changes: 13 additions & 1 deletion math/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ gen-libm-calls = \
s_csqrtF \
s_ctanF \
s_ctanhF \
s_exp10m1F \
s_exp2m1F \
s_fdimF \
s_fmaxF \
s_fmaximumF \
Expand Down Expand Up @@ -643,6 +645,8 @@ libm-test-funcs-auto = \
exp \
exp2 \
exp10 \
exp10m1 \
exp2m1 \
expm1 \
fma \
hypot \
Expand All @@ -651,10 +655,10 @@ libm-test-funcs-auto = \
jn \
lgamma \
log \
log2 \
log10 \
log10p1 \
log1p \
log2 \
log2p1 \
pow \
sin \
Expand Down Expand Up @@ -932,8 +936,10 @@ tgmath3-macros = \
erf \
erfc \
exp \
exp10m1 \
exp2 \
exp10 \
exp2m1 \
expm1 \
fabs \
fdim \
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions math/Versions
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
201 changes: 201 additions & 0 deletions math/auto-libm-test-in
Original file line number Diff line number Diff line change
Expand Up @@ -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
exp10m1 0x3.735f497c4e67535cp-4
exp10m1 -0x7.d6c50b469d404p+0
exp10m1 0x4.857de8p+4
exp10m1 0x5.dfeb68p-4
exp10m1 0x4.0000000000000028p-16384
exp10m1 0x5.8b911eb6733469c8p-4
exp10m1 0x5.a343df0d680099a7a1a873a751a8p-4
exp10m1 min
exp10m1 -min
exp10m1 min_subnorm
exp10m1 -min_subnorm
exp10m1 0x2.688268p+4
exp10m1 0x2.68826cp+4
exp10m1 0x1.34413509f79fep+8
exp10m1 0x1.34413509f79ffp+8
exp10m1 0x1.34413509f79fef2f625b0205a88p+8 xfail:ibm128-libgcc
exp10m1 0x1.34413509f79fef2f625b0205a9p+8 xfail:ibm128-libgcc
exp10m1 0x1.34413509f79fef3p+12
exp10m1 0x1.34413509f79fef32p+12
exp10m1 0x1.34413509f79fef311f12b35816f9p+12
exp10m1 0x1.34413509f79fef311f12b35816fap+12
exp10m1 0x1p-128
exp10m1 0x1p-1024
exp10m1 0x1p-16384
exp10m1 -0x1p-128
exp10m1 -0x1p-1024
exp10m1 -0x1p-16384

exp2 0
exp2 -0
exp2 10
Expand Down Expand Up @@ -5353,6 +5453,107 @@ exp2 -0xc.1bf12p-16
exp2 -0x4.8ce878p-4
exp2 0xf.93d18bf7be8d272p-4

exp2m1 0
exp2m1 -0
exp2m1 1
exp2m1 0.75
exp2m1 2
exp2m1 3
exp2m1 4
exp2m1 5
exp2m1 10
exp2m1 15
exp2m1 20
exp2m1 25
exp2m1 30
exp2m1 35
exp2m1 40
exp2m1 50.0
exp2m1 60
exp2m1 70
exp2m1 80
exp2m1 90
exp2m1 100
exp2m1 127.0
exp2m1 500.0
exp2m1 11356.25
exp2m1 -10.0
exp2m1 -16.0
exp2m1 -17.0
exp2m1 -18.0
exp2m1 -36.0
exp2m1 -37.0
exp2m1 -38.0
exp2m1 -44.0
exp2m1 -45.0
exp2m1 -46.0
exp2m1 -73.0
exp2m1 -74.0
exp2m1 -75.0
exp2m1 -78.0
exp2m1 -79.0
exp2m1 -80.0
exp2m1 -100.0
exp2m1 -1000.0
exp2m1 -10000.0
exp2m1 -100000.0
exp2m1 100000.0
exp2m1 max
exp2m1 -max
exp2m1 0x1p-2
exp2m1 -0x1p-2
exp2m1 0x1p-10
exp2m1 -0x1p-10
exp2m1 0x1p-20
exp2m1 -0x1p-20
exp2m1 0x1p-29
exp2m1 -0x1p-29
exp2m1 0x1p-32
exp2m1 -0x1p-32
exp2m1 0x1p-50
exp2m1 -0x1p-50
exp2m1 0x1p-64
exp2m1 -0x1p-64
exp2m1 0x1p-100
exp2m1 -0x1p-100
exp2m1 0x1p-600
exp2m1 -0x1p-600
exp2m1 0x1p-10000
exp2m1 -0x1p-10000
exp2m1 0xe.4152ac57cd1ea7ap-60
exp2m1 0x6.660247486aed8p-4
exp2m1 0x6.289a78p-4
exp2m1 0x6.1b4d318238d4a2a8p-4
exp2m1 0x5.fb8dc64e91a74p-4
exp2m1 0x3.735f497c4e67535cp-4
exp2m1 -0x7.d6c50b469d404p+0
exp2m1 0x4.857de8p+4
exp2m1 0x5.dfeb68p-4
exp2m1 0x4.0000000000000028p-16384
exp2m1 0x5.8b911eb6733469c8p-4
exp2m1 0x5.a343df0d680099a7a1a873a751a8p-4
exp2m1 min
exp2m1 -min
exp2m1 min_subnorm
exp2m1 -min_subnorm
exp2m1 128
exp2m1 0x7.fffff8p+4
exp2m1 0x8.00001p+4
exp2m1 0x3.ffffffffffffep+8
exp2m1 0x4.0000000000004p+8
exp2m1 0x3.fffffffffffffffa3aae26b51fp+8 xfail-rounding:ibm128-libgcc
exp2m1 0x3.fffffffffffffffa3aae26b52p+8 xfail-rounding:ibm128-libgcc
exp2m1 0x3.fffffffffffffffcp+12
exp2m1 0x4.0000000000000008p+12
exp2m1 0x3.fffffffffffffffffffffffffffep+12
exp2m1 0x4.0000000000000000000000000004p+12
exp2m1 0x1p-125
exp2m1 0x1p-1021
exp2m1 0x1p-16381
exp2m1 -0x1p-125
exp2m1 -0x1p-1021
exp2m1 -0x1p-16381

expm1 0
expm1 -0 no-mathvec
expm1 1
Expand Down
Loading

0 comments on commit 7ec903e

Please sign in to comment.