diff --git a/SHARED-FILES b/SHARED-FILES index d84e8e9697..2aefac8a95 100644 --- a/SHARED-FILES +++ b/SHARED-FILES @@ -219,3 +219,15 @@ tzdata: timezone/leapseconds # This is yearistype.sh in the parent project timezone/yearistype + +# The following files are shared with the CORE-MATH project +sysdeps/ieee754/flt-32/e_gammaf_r.c + (file src/binary32/tgamma/tgammaf.c in CORE-MATH) + Instructions to merge new versions: + - change the function name from cr_tgammaf to __ieee754_gammaf_r + - add "int *signgamp" as 2nd argument and add at the beginning: + if (signgamp != NULL) *signgamp = 1; + - remove the errno stuff (this is done by the wrapper) + - replace 0x1p127f * 0x1p127f by math_narrow_eval (x * 0x1p127f) + - replace 0x1p-127f * sgn[k&1] by math_narrow_eval (0x1p-127f * sgn[k&1]) + - add libm_alias_finite (__ieee754_gammaf_r, __gammaf_r) at the end diff --git a/benchtests/Makefile b/benchtests/Makefile index d228e9e68a..79d802aaf0 100644 --- a/benchtests/Makefile +++ b/benchtests/Makefile @@ -94,6 +94,7 @@ bench-math := \ tan \ tanh \ tgamma \ + tgammaf \ trunc \ truncf \ y0 \ diff --git a/benchtests/tgammaf-inputs b/benchtests/tgammaf-inputs new file mode 100644 index 0000000000..b2baf5c020 --- /dev/null +++ b/benchtests/tgammaf-inputs @@ -0,0 +1,1006 @@ +## includes: math.h +## args: float +## ret: float + +# Random inputs in [-a,a=0x1.18522ep+5) +# where a is the smallest number such that tgammaf rounds to +Inf (to nearest) +0x1.714acp+2 +0x1.0f4884p+4 +-0x1.16b54p+1 +0x1.238ef4p+4 +0x1.4896ap+4 +-0x1.714e7p+2 +0x1.c254cp+4 +0x1.c76928p+3 +0x1.0b82acp+5 +-0x1.a4d6dp+2 +0x1.16f3ap+2 +0x1.43a5bp+2 +-0x1.da2ef8p+4 +0x1.f7c01p+2 +0x1.f5b698p+4 +-0x1.3dcbccp+3 +0x1.34238p+3 +-0x1.0b6364p+5 +-0x1.1c820cp+4 +-0x1.bcdeccp+4 +0x1.481cdp+3 +0x1.83fbf8p+4 +0x1.18504cp+5 +-0x1.b65098p+4 +0x1.5aa868p+4 +-0x1.8f06ap+3 +-0x1.a8d468p+2 +0x1.11a554p+5 +0x1.b47368p+4 +0x1.df0d08p+4 +-0x1.f80fcap+4 +0x1.c9cda4p+4 +0x1.785454p+4 +-0x1.af1b08p+2 +-0x1.0f6e86p+5 +0x1.869148p+3 +0x1.054cp+1 +0x1.f545dp+4 +-0x1.20e18p+1 +0x1.ec8cd8p+4 +-0x1.047434p+5 +-0x1.059518p+5 +0x1.6c32bp+2 +0x1.e72af8p+4 +-0x1.8e6d38p+4 +-0x1.5173ep+2 +0x1.0df39p+5 +-0x1.98be5p+4 +0x1.d16e8p-1 +-0x1.8d11ap+2 +-0x1.10bc48p+5 +0x1.99a9bp+3 +0x1.ea951p+2 +-0x1.38a44p+3 +-0x1.e303f2p+4 +0x1.3efc18p+3 +-0x1.d4510cp+3 +0x1.10a078p+3 +0x1.75f644p+4 +-0x1.b0b2c2p+4 +-0x1.dc58ep+1 +0x1.be8c2p+2 +-0x1.ad4244p+4 +0x1.4bdd88p+3 +0x1.7e3b98p+3 +-0x1.47af9p+2 +-0x1.26b82p+2 +-0x1.d8bd38p+4 +0x1.348244p+4 +0x1.5b6f4p+0 +-0x1.0f1764p+5 +-0x1.eea53p+2 +0x1.17cdbp+4 +-0x1.c0d6fp+1 +0x1.5d8fbcp+4 +-0x1.46e70cp+4 +0x1.a7379p+2 +-0x1.c537b8p+2 +0x1.65fdfp+2 +-0x1.573a14p+4 +-0x1.f6d328p+2 +0x1.3fa52p+3 +-0x1.9e64d4p+3 +-0x1.d1f208p+4 +0x1.daff8p+1 +-0x1.f85f48p+3 +-0x1.aa2b78p+4 +-0x1.1d6d14p+3 +0x1.06be64p+5 +-0x1.00671cp+4 +0x1.eeb7p-2 +0x1.10efdp+2 +0x1.de3fc8p+4 +-0x1.1da752p+4 +0x1.76392p+4 +-0x1.acd59p+4 +0x1.3db448p+3 +-0x1.2ef648p+4 +-0x1.30f1e8p+4 +-0x1.d3de8ep+4 +-0x1.e9566p+3 +-0x1.9ea03cp+3 +-0x1.f0158p-1 +-0x1.ff9bbp+1 +-0x1.3a3454p+3 +-0x1.87b4e4p+3 +0x1.3ea26p+1 +0x1.638248p+4 +-0x1.125e42p+4 +0x1.cc892cp+4 +0x1.b01cap+4 +0x1.d24a08p+3 +0x1.a2a1e8p+4 +0x1.15e17p+5 +0x1.10825p+5 +0x1.daad88p+4 +-0x1.21f976p+4 +-0x1.031fbcp+4 +-0x1.17fd7ep+5 +0x1.126018p+4 +-0x1.e621bp+4 +0x1.c4cf78p+3 +0x1.53dcd4p+4 +-0x1.8b519cp+4 +-0x1.69dacp+0 +0x1.4172ep+2 +0x1.160e68p+4 +0x1.a7da7p+4 +-0x1.decd6cp+4 +0x1.4b2bap+3 +0x1.806868p+3 +0x1.427174p+4 +-0x1.f04p-2 +0x1.0c93d8p+4 +0x1.093c6p+2 +-0x1.082e6ep+5 +-0x1.181a92p+5 +-0x1.19dfbp+2 +-0x1.98fef8p+2 +0x1.a77e94p+4 +0x1.1ad3cp+0 +-0x1.39c9bcp+3 +-0x1.ea251cp+4 +0x1.dec54p+2 +0x1.cc7e1cp+4 +0x1.6d9f1p+2 +-0x1.fe9198p+2 +-0x1.026232p+4 +0x1.08ad5p+5 +-0x1.43db28p+4 +-0x1.c4139ap+4 +0x1.bd6538p+4 +-0x1.a1ca9p+3 +-0x1.100adap+4 +0x1.1642p+5 +0x1.5a583p+3 +-0x1.902c5ap+4 +0x1.12f3ap+3 +0x1.0762a4p+5 +0x1.dea9e8p+4 +0x1.73af2p+4 +-0x1.51b6p+2 +0x1.e5fdf8p+3 +-0x1.2cdf44p+3 +-0x1.15518ep+5 +0x1.8481cp+1 +0x1.14c8ap+5 +-0x1.e34466p+4 +-0x1.2e8a6ep+4 +-0x1.edbcap+2 +-0x1.a34a2p+3 +0x1.62ba48p+4 +-0x1.48a09cp+3 +0x1.365f9p+2 +-0x1.e31778p+3 +0x1.373324p+4 +0x1.2a03p+2 +-0x1.4304dcp+4 +0x1.abb9dcp+4 +0x1.0dc9ap+5 +-0x1.b292f4p+4 +0x1.c72028p+3 +-0x1.78e0a4p+4 +-0x1.25c21cp+4 +0x1.155e5p+2 +-0x1.edba2p+3 +-0x1.dc87a6p+4 +0x1.44f16p+3 +-0x1.35781p+3 +0x1.b1acfp+4 +-0x1.c4c57p+3 +-0x1.c6ca42p+4 +-0x1.619604p+3 +-0x1.1f1f2p+2 +0x1.1ed8p+0 +0x1.76619cp+4 +-0x1.382454p+3 +-0x1.5270ep+1 +-0x1.16be2p+1 +0x1.4062fp+2 +-0x1.9fd7a8p+2 +-0x1.e1d9d8p+4 +0x1.ad37d8p+3 +-0x1.c78fecp+4 +-0x1.fbc6bp+2 +-0x1.e4c7dcp+3 +0x1.e5efp+2 +-0x1.28d7c8p+4 +0x1.72d978p+3 +0x1.37137cp+4 +-0x1.53ec9cp+3 +0x1.66a2bp+3 +0x1.9a4ep-3 +0x1.1140e4p+4 +0x1.16ed74p+5 +0x1.a82d78p+3 +0x1.975b0cp+4 +0x1.ca4ebp+3 +-0x1.589c6ap+4 +0x1.8ef3cp+2 +0x1.e2b6p+2 +-0x1.6b87f8p+2 +0x1.24f1e8p+4 +0x1.3a7a8p+4 +-0x1.f984f2p+4 +-0x1.a401p-1 +0x1.956ec8p+4 +-0x1.db5688p+4 +0x1.36f2ap+3 +-0x1.d1107p+3 +-0x1.b25828p+2 +-0x1.ffd308p+4 +0x1.3ec6c4p+4 +-0x1.721c04p+4 +0x1.d9e568p+4 +0x1.a293a8p+3 +0x1.10c4d8p+5 +0x1.cbe78p+0 +0x1.1052c8p+3 +0x1.32e02p+1 +0x1.be4b2p+4 +0x1.b1e164p+4 +-0x1.4dedb8p+4 +-0x1.52518cp+3 +-0x1.ddb38p-1 +-0x1.42cd08p+4 +0x1.2154d4p+4 +-0x1.067cc8p+4 +-0x1.767908p+4 +-0x1.3a2d44p+4 +-0x1.705b12p+4 +-0x1.de6e8p+0 +0x1.626488p+4 +-0x1.69fe64p+4 +-0x1.9f53eep+4 +-0x1.d6668p+0 +0x1.40e7c8p+4 +0x1.0f18bp+2 +0x1.7d9204p+4 +-0x1.40e0c2p+4 +0x1.3ca2p-1 +0x1.d0cf4p+4 +-0x1.9af13p+1 +0x1.49159p+3 +0x1.0e886cp+4 +-0x1.387932p+4 +-0x1.76d0b2p+4 +0x1.e3a888p+4 +0x1.95945p+3 +-0x1.f11fccp+3 +-0x1.f94b88p+3 +-0x1.5c3164p+4 +0x1.7042fp+4 +0x1.7b4304p+4 +0x1.193fcp+0 +-0x1.a69a94p+3 +0x1.fca03p+2 +0x1.a8b48p+1 +-0x1.4b058cp+3 +0x1.f889cp+4 +0x1.216c5cp+4 +0x1.4abf8p+3 +-0x1.903e98p+3 +0x1.002418p+5 +-0x1.81bd24p+4 +0x1.bcd70cp+4 +-0x1.27c00ap+4 +0x1.82ff1p+2 +0x1.a61df8p+3 +0x1.cc60d8p+3 +-0x1.36d58p+4 +0x1.35c0e4p+4 +-0x1.0cca7ap+5 +-0x1.f7191p+1 +0x1.064398p+5 +0x1.326608p+3 +0x1.6e83ep+3 +0x1.f9d508p+4 +0x1.aef608p+4 +-0x1.78885cp+4 +0x1.2a9f6p+4 +-0x1.3852c4p+4 +0x1.f53fe8p+4 +0x1.54b6cp+0 +-0x1.07f15cp+5 +-0x1.6d6c6cp+4 +0x1.836434p+4 +-0x1.f2d5b8p+2 +0x1.28f9c8p+3 +0x1.7e7d6cp+4 +-0x1.dcc444p+4 +0x1.aba548p+4 +0x1.c8b9f4p+4 +0x1.3b2d8p+3 +0x1.f0f87p+4 +0x1.526da8p+4 +-0x1.387fb8p+4 +-0x1.4167fp+4 +-0x1.570d18p+3 +0x1.aaedb8p+3 +-0x1.b53824p+3 +0x1.4a0e1cp+4 +0x1.021604p+4 +-0x1.21900cp+4 +-0x1.84c488p+3 +-0x1.03b874p+3 +0x1.5bcc5cp+4 +-0x1.9fb5c8p+3 +-0x1.842c52p+4 +-0x1.3deae4p+3 +-0x1.9ae034p+4 +-0x1.10fa9cp+5 +-0x1.b95bdcp+4 +-0x1.62e5bap+4 +0x1.e0e8fp+4 +-0x1.96a54cp+4 +0x1.c61774p+4 +-0x1.90c15p+4 +-0x1.5de06ap+4 +-0x1.08898ep+5 +0x1.644f1p+4 +0x1.caf23p+2 +0x1.3b8f6p+3 +-0x1.c806aap+4 +0x1.c6ebe4p+4 +-0x1.49fcd4p+3 +-0x1.787318p+4 +0x1.164038p+3 +-0x1.05b048p+2 +-0x1.dbe2f8p+2 +-0x1.7f48bp+2 +0x1.70e1ecp+4 +0x1.330974p+4 +-0x1.dd4fdp+3 +0x1.460e1p+3 +-0x1.2d880cp+3 +-0x1.9575f2p+4 +-0x1.0acce4p+5 +0x1.048768p+4 +-0x1.03fd18p+3 +0x1.05b15p+5 +0x1.54f76p+1 +0x1.f6f6e8p+4 +0x1.b3677p+4 +0x1.c01f3p+2 +-0x1.e32a14p+4 +-0x1.c72a8p+0 +-0x1.ebac5ap+4 +0x1.d83bp-1 +-0x1.4926e8p+4 +-0x1.797964p+4 +-0x1.49e964p+3 +-0x1.841d6cp+4 +-0x1.25273cp+3 +-0x1.07b102p+4 +-0x1.14b7acp+5 +-0x1.b5e63ap+4 +0x1.b52cacp+4 +0x1.f47f3p+2 +-0x1.6f3afcp+4 +-0x1.13717cp+3 +-0x1.1b037cp+4 +0x1.5da03p+4 +0x1.ec788p+4 +0x1.139c4cp+4 +-0x1.7418a6p+4 +0x1.03917cp+5 +-0x1.95383p+4 +0x1.03f114p+5 +-0x1.57e28ep+4 +0x1.caf3a4p+4 +-0x1.2cbb8p-1 +0x1.245f6p+3 +-0x1.2f17dp+3 +-0x1.86afacp+4 +0x1.2aaac8p+4 +-0x1.0a568p+0 +0x1.a7e7b4p+4 +0x1.c330b8p+3 +0x1.0faeap+1 +-0x1.2d39p+2 +-0x1.4ddb52p+4 +-0x1.f0c194p+4 +-0x1.3381cp+2 +0x1.12218p+5 +0x1.4804bp+2 +-0x1.df3382p+4 +-0x1.163aap+1 +0x1.8d269cp+4 +0x1.b46b3p+4 +-0x1.476e0cp+3 +-0x1.449c18p+3 +0x1.1a06p-1 +-0x1.2dba34p+4 +-0x1.2bc334p+4 +0x1.bba7b4p+4 +-0x1.c0eb2ep+4 +0x1.c2fa38p+4 +0x1.0f8538p+5 +0x1.fc3df8p+4 +0x1.537f8cp+4 +-0x1.a8d7ccp+4 +0x1.96023p+2 +0x1.3b2d2p+1 +-0x1.7b62c6p+4 +-0x1.5185ap+1 +-0x1.f7a8p-1 +-0x1.0c922p+3 +-0x1.df916p+4 +0x1.f3911p+3 +-0x1.5d9218p+3 +0x1.e0c878p+4 +-0x1.bd25bp+1 +0x1.66c448p+3 +-0x1.811accp+3 +-0x1.010c9cp+4 +0x1.f2a9f8p+4 +-0x1.1002dcp+4 +-0x1.274c8ep+4 +-0x1.2a902p+4 +0x1.74b20cp+4 +0x1.ff9988p+4 +-0x1.08647p+4 +-0x1.6557ecp+3 +0x1.cc62p+0 +-0x1.01b0c6p+5 +-0x1.75cep+4 +0x1.56d63cp+4 +-0x1.f86a7p+2 +0x1.4c874p+4 +0x1.37df0cp+4 +-0x1.265c3cp+3 +-0x1.0c48cp+5 +-0x1.e459d8p+3 +-0x1.8bca4p+3 +0x1.14706p+3 +-0x1.c99d3p+2 +-0x1.0fb52ap+4 +-0x1.071aecp+5 +-0x1.8975d8p+2 +-0x1.128304p+3 +-0x1.e3ff3p+1 +-0x1.152db8p+2 +-0x1.16b954p+5 +-0x1.15e6cep+5 +0x1.21b8d8p+4 +-0x1.1a98a8p+2 +0x1.059a88p+5 +0x1.2e2f4cp+4 +0x1.9f7c4p+3 +0x1.67382p+1 +0x1.2551dp+4 +0x1.b0fd4p+2 +0x1.583a68p+3 +0x1.30a698p+3 +-0x1.f8fe88p+2 +0x1.96d6f4p+4 +-0x1.0d8a96p+5 +-0x1.74878p-1 +0x1.10f1ep+1 +0x1.300af8p+4 +0x1.26de1cp+4 +0x1.ac842p+2 +0x1.74276p+4 +-0x1.d4723ep+4 +0x1.7222f8p+4 +-0x1.12400cp+5 +-0x1.6626e8p+3 +-0x1.a6c344p+3 +-0x1.3f75ep+2 +0x1.968ac4p+4 +-0x1.e132ecp+3 +0x1.308c5cp+4 +0x1.32232p+1 +-0x1.101cap+5 +-0x1.0adf06p+5 +-0x1.9d61p+3 +0x1.0937dp+5 +0x1.b44f3cp+4 +-0x1.c78ap+0 +-0x1.829a6p+4 +0x1.7ecb88p+3 +0x1.44aa6p+4 +-0x1.f017dap+4 +-0x1.a4603p+3 +-0x1.6fc0c8p+3 +0x1.ec29cp+4 +-0x1.ff5bdcp+4 +0x1.d5782p+4 +-0x1.2f712ap+4 +-0x1.552f48p+2 +0x1.a127bp+4 +-0x1.3a8cdcp+3 +-0x1.7a1228p+3 +0x1.8b913p+2 +0x1.db95fp+3 +0x1.7a43p+3 +-0x1.539778p+4 +-0x1.a4d114p+4 +-0x1.c4127p+4 +0x1.75c1p+4 +-0x1.f3b83p+2 +-0x1.2d3ffep+4 +0x1.73c72p+2 +0x1.b9044p+0 +0x1.e7383p+4 +-0x1.f12826p+4 +-0x1.ace2ap+1 +0x1.fb643p+4 +-0x1.d6d9a8p+2 +0x1.5da19p+4 +-0x1.1f967p+3 +-0x1.9ac65ep+4 +-0x1.03408cp+3 +-0x1.014488p+5 +-0x1.3ce4d8p+4 +-0x1.99e4a8p+4 +0x1.e51898p+4 +0x1.8df99p+2 +0x1.9240dp+4 +0x1.94107p+3 +-0x1.e7551p+3 +0x1.f8568p+4 +-0x1.57339cp+4 +0x1.d9ef98p+4 +0x1.ea652p+4 +-0x1.185138p+4 +-0x1.37b20cp+3 +0x1.6e3ea8p+4 +-0x1.08b312p+4 +-0x1.f85fep+4 +-0x1.50c0dcp+4 +-0x1.daf28p+0 +0x1.1dd7b8p+4 +0x1.7179e8p+4 +-0x1.489db4p+4 +-0x1.5b705cp+3 +0x1.c989d4p+4 +-0x1.d0da4p+0 +0x1.67d708p+3 +-0x1.a4d0f8p+3 +-0x1.22519cp+4 +0x1.0e6b54p+4 +0x1.17e9bp+5 +0x1.68d95cp+4 +-0x1.ec6d2cp+4 +-0x1.38ffccp+4 +-0x1.23bf1ep+4 +0x1.a0e2p+2 +0x1.24094p+3 +-0x1.90f946p+4 +-0x1.4f2b2p+4 +0x1.93398p+0 +0x1.3d7fdp+4 +0x1.3741fp+4 +-0x1.a88074p+3 +-0x1.103f16p+5 +0x1.53c554p+4 +0x1.e8e9p+1 +-0x1.0e4e4cp+4 +-0x1.e2389ep+4 +-0x1.ad61p+3 +-0x1.c30eecp+3 +-0x1.67abb8p+2 +-0x1.c4fffcp+3 +-0x1.5dd3ap+1 +-0x1.6eb4a8p+2 +0x1.63f0bp+3 +-0x1.073cd8p+5 +0x1.bb22e8p+4 +-0x1.a8ce5p+2 +-0x1.51153cp+3 +-0x1.56371p+3 +0x1.f1fb4p+0 +0x1.498f8p+3 +0x1.332da8p+3 +0x1.080834p+5 +-0x1.32da04p+3 +0x1.650174p+4 +-0x1.59f60cp+4 +-0x1.4e8858p+2 +0x1.84688p+0 +0x1.3629fp+2 +0x1.0ba29p+5 +-0x1.0ae52p+2 +-0x1.4f44ap+1 +0x1.9ae28p+0 +0x1.2baf1p+2 +0x1.0c802p+2 +-0x1.c67dd8p+2 +-0x1.de957p+1 +0x1.48b72p+1 +-0x1.4c0c68p+4 +0x1.46a744p+4 +-0x1.39d01cp+3 +0x1.53d76p+3 +0x1.1668a4p+5 +0x1.f4433p+4 +0x1.e4b0fp+2 +-0x1.7c4cf8p+4 +0x1.0d5e8p+4 +-0x1.880078p+4 +0x1.53c5ep+4 +0x1.904728p+3 +0x1.0d36f8p+5 +0x1.f6183p+4 +0x1.08f43cp+4 +0x1.77e2c8p+4 +-0x1.cb5924p+4 +0x1.486de8p+4 +0x1.060a78p+3 +0x1.0c8e4cp+5 +0x1.fb2dcp+3 +0x1.39f22p+4 +-0x1.0111a6p+5 +0x1.8b0198p+3 +-0x1.c08372p+4 +-0x1.e9686p+4 +-0x1.2f4aa4p+3 +0x1.ad5be4p+4 +-0x1.518fccp+3 +-0x1.c858d4p+3 +-0x1.5f7f7cp+3 +-0x1.556ffep+4 +-0x1.2215a4p+3 +-0x1.50b018p+4 +0x1.f249ap+2 +0x1.12e38p+5 +-0x1.b1dc0cp+4 +-0x1.a102dcp+3 +0x1.80dbc4p+4 +-0x1.684cbcp+3 +0x1.ed581p+2 +-0x1.dca674p+3 +0x1.973504p+4 +-0x1.f820f8p+4 +-0x1.81a7p+1 +-0x1.0c8b6p+5 +0x1.d1e7b8p+4 +0x1.3709dcp+4 +-0x1.48f4ap+3 +-0x1.07881p+5 +0x1.45905p+2 +-0x1.0c0d02p+5 +-0x1.067a0cp+3 +0x1.9dd588p+4 +0x1.ba0ed8p+4 +0x1.f44628p+4 +0x1.cabed4p+4 +-0x1.e23812p+4 +-0x1.0a744ep+5 +0x1.db644p+0 +0x1.51211p+4 +0x1.a63694p+4 +0x1.246b2cp+4 +-0x1.756b7p+4 +-0x1.ff7878p+4 +-0x1.f10044p+4 +-0x1.cda77p+1 +-0x1.1961a2p+4 +0x1.d4abbp+2 +-0x1.03ed76p+4 +0x1.079cfcp+4 +-0x1.7365f4p+3 +-0x1.2dd44p+0 +-0x1.b47a6p+1 +0x1.9784d4p+4 +-0x1.f35baep+4 +-0x1.bb35acp+4 +0x1.b9d88p+1 +0x1.14f6a4p+5 +-0x1.7c5ecp+0 +0x1.05bd1cp+5 +-0x1.a19a52p+4 +-0x1.148c8p+3 +-0x1.771ce2p+4 +-0x1.072ffap+5 +0x1.c4178cp+4 +0x1.8bad68p+4 +0x1.b47704p+4 +0x1.0e2438p+4 +-0x1.fc9778p+4 +0x1.5ec7ap+2 +0x1.43912p+2 +0x1.46345p+3 +0x1.6cd29p+4 +0x1.0144cp+2 +-0x1.1e9854p+3 +-0x1.3756bap+4 +-0x1.0b664ap+4 +-0x1.9aep-3 +0x1.68f64p+3 +0x1.3aa67p+3 +-0x1.07615ap+5 +-0x1.f0c314p+4 +0x1.b0bdf4p+4 +-0x1.54f9aep+4 +0x1.9c367p+4 +-0x1.14b3ecp+4 +0x1.791af8p+4 +0x1.a81588p+3 +0x1.3b838p+4 +0x1.e13758p+4 +0x1.56c47p+2 +0x1.8f7e7cp+4 +0x1.5262e8p+4 +-0x1.896a58p+2 +0x1.f37f48p+4 +0x1.fbaadp+4 +0x1.4d2cfp+2 +0x1.6c67ap+2 +0x1.9b882p+3 +0x1.5b66fp+2 +-0x1.9d42dp+1 +-0x1.05346cp+4 +0x1.0ab82p+1 +0x1.9e15b8p+3 +-0x1.d98274p+3 +0x1.0a78b8p+3 +-0x1.2f3774p+4 +0x1.a9b88p+0 +-0x1.f47fecp+4 +-0x1.558a24p+4 +0x1.46c308p+3 +-0x1.bf564cp+4 +0x1.b638c8p+4 +0x1.42b98p+0 +-0x1.97a6a4p+4 +-0x1.4220ecp+4 +0x1.6845ap+3 +-0x1.fb5ddp+4 +0x1.eb47fp+2 +-0x1.067b58p+3 +0x1.167014p+5 +0x1.e7924p+4 +-0x1.5f6cp-3 +0x1.30a098p+3 +0x1.05834cp+5 +-0x1.da437cp+3 +0x1.3e04b8p+4 +-0x1.9ef4ecp+3 +0x1.51ce1p+3 +-0x1.112634p+5 +0x1.77c6ep+4 +-0x1.d37be8p+3 +-0x1.7e568p+0 +-0x1.c5a644p+4 +-0x1.6e036p+1 +-0x1.1786d4p+3 +-0x1.8580e8p+2 +0x1.c466cp+0 +0x1.0ba94p+3 +0x1.86773p+2 +0x1.803bep+4 +-0x1.ae82f8p+2 +-0x1.862498p+2 +0x1.3da6p+0 +0x1.a865d8p+3 +-0x1.ce0fb8p+2 +-0x1.846eep+4 +-0x1.d932p+3 +-0x1.547b34p+4 +0x1.7a1cbp+3 +0x1.248f58p+3 +-0x1.352bcp+4 +-0x1.8b421cp+4 +0x1.fd815p+2 +0x1.22a41p+3 +-0x1.0ac0eap+4 +-0x1.45f61p+4 +0x1.36d9bp+4 +-0x1.9cd784p+3 +-0x1.5fb918p+2 +-0x1.810298p+3 +0x1.e7b198p+3 +-0x1.ff5fc4p+4 +0x1.92637p+3 +0x1.82252p+2 +-0x1.aa8ebap+4 +-0x1.dc9b4ep+4 +0x1.ae464p+4 +0x1.d58b9p+3 +0x1.879fep+4 +0x1.afb52cp+4 +-0x1.9eda98p+4 +0x1.f3939p+4 +-0x1.e927e8p+3 +-0x1.582306p+4 +0x1.10753cp+5 +-0x1.80fd7cp+4 +0x1.9b3cbp+2 +0x1.67267p+4 +-0x1.51e6e8p+4 +-0x1.6250c8p+2 +-0x1.1550c4p+4 +0x1.2d6838p+3 +0x1.099948p+4 +-0x1.2eaf5p+4 +0x1.dca0cp+0 +-0x1.7374p-4 +-0x1.c2053ep+4 +0x1.9e5f04p+4 +-0x1.07dbf6p+5 +-0x1.23ba88p+4 +0x1.0956a4p+4 +-0x1.b798ap+1 +0x1.f7143p+2 +0x1.b56028p+3 +-0x1.151df6p+5 +-0x1.301754p+4 +-0x1.05d158p+5 +0x1.08eb28p+5 +-0x1.5c5d5p+4 +-0x1.9cffd2p+4 +-0x1.285654p+4 +0x1.e001e8p+3 +0x1.04076p+2 +0x1.0c6a04p+4 +0x1.7bb8p-2 +-0x1.0f0518p+5 +-0x1.3567a8p+2 +-0x1.1ebdp-1 +-0x1.8ef22p+3 +-0x1.0a1d5ap+5 +0x1.8a9edp+3 +0x1.00c0e4p+5 +-0x1.32c98p-1 +-0x1.e081c8p+3 +-0x1.226ea4p+4 +0x1.bf0b7p+4 +0x1.c4d04p+0 +0x1.f48ddp+2 +-0x1.f9f398p+2 +-0x1.24d42p+2 +0x1.0c776p+4 +0x1.8a98ep+3 +-0x1.86d128p+4 +-0x1.dda632p+4 +0x1.b3ad38p+4 +0x1.0dac4p+3 +0x1.9fc00cp+4 +-0x1.93bfccp+4 +-0x1.6e659p+2 +-0x1.60dap-1 +-0x1.50fd46p+4 +0x1.1d5078p+4 +0x1.b69efp+3 +0x1.e31d3p+3 +-0x1.0541cp+5 +0x1.3a1648p+3 +0x1.a0c63p+3 +0x1.ea3ff8p+4 +0x1.58ea1cp+4 +0x1.a5509cp+4 +-0x1.30dc1p+3 +-0x1.6a0c2ep+4 +0x1.017178p+3 +0x1.3f598p+0 +0x1.33b4e8p+4 +-0x1.74f184p+4 +0x1.05baep+2 +0x1.b8792p+1 +0x1.638c68p+4 +0x1.94a15cp+4 +-0x1.43fc96p+4 +-0x1.21606cp+3 +0x1.9b3a58p+3 +0x1.e4a05p+4 +0x1.bfa8d8p+4 +-0x1.9076acp+4 +-0x1.967568p+4 +0x1.ac7a58p+3 +0x1.51c12p+2 +0x1.769c4p+1 +-0x1.a53708p+4 +-0x1.fcd6dp+1 +0x1.9b57p+2 +-0x1.f69b8p+0 +-0x1.b953p+2 +0x1.0ec4fcp+5 +-0x1.cf1dcp+0 +0x1.8084b8p+4 +0x1.62db78p+3 +-0x1.485c98p+2 +-0x1.576414p+4 +-0x1.fcc948p+3 +0x1.9d863p+3 +-0x1.08b39ep+5 +0x1.795ep-3 +0x1.99e26p+2 +0x1.fb6d6p+4 +-0x1.55d16p+1 +0x1.41071p+3 +0x1.549abcp+4 +0x1.4e88p-3 +0x1.10bfcp+2 +0x1.97b3cp+3 +-0x1.4580cp+3 +-0x1.df2fp+0 +-0x1.09a2dcp+5 +-0x1.7e1124p+3 +-0x1.14f35ep+5 +0x1.2956cp+4 +0x1.c7b8e8p+4 +-0x1.ebba08p+3 +-0x1.fdfd3p+3 +0x1.46906p+1 +0x1.c1318p+0 +0x1.79f444p+4 +0x1.6012bcp+4 +0x1.fd49ap+2 +-0x1.11612cp+4 +0x1.ea3cdp+4 +-0x1.a053ccp+4 +-0x1.995764p+3 +0x1.bec2e8p+4 +-0x1.7aa898p+2 +0x1.6b6edp+2 +0x1.9b6774p+4 +0x1.e85738p+3 +0x1.974ad4p+4 +-0x1.554564p+4 +-0x1.383ap+3 +-0x1.7576dcp+4 +-0x1.7e8308p+4 +-0x1.786086p+4 +-0x1.31641p+2 +-0x1.591184p+4 +0x1.1ef65p+4 +-0x1.39bc08p+2 +-0x1.1672b4p+4 +-0x1.4aa7f4p+4 +0x1.201d4p+1 +-0x1.afecp-3 +-0x1.163698p+3 +-0x1.7660cp+2 +-0x1.c7fb44p+4 +-0x1.8e0cbp+3 +-0x1.d2a9p-2 +0x1.d0d51p+4 +0x1.d1ea38p+4 +0x1.9741bp+3 +0x1.d90b08p+3 +0x1.6608f8p+4 +-0x1.019936p+5 +-0x1.bd980ep+4 +0x1.c8ad9p+2 +-0x1.a33178p+2 +-0x1.957c74p+4 +0x1.1adc7p+4 +-0x1.329bcp+2 +0x1.4df538p+3 +0x1.ce0544p+4 +0x1.09ab3p+5 +-0x1.937bp+4 +0x1.029744p+5 +0x1.f899f8p+4 +0x1.8140e8p+4 +0x1.e035p+2 +0x1.1418a4p+5 +0x1.183664p+5 +0x1.9ac948p+4 +0x1.7be72p+3 +0x1.3145d8p+4 +0x1.a88598p+3 +-0x1.15d71p+5 +-0x1.cfe5dp+3 +-0x1.3259b4p+3 +0x1.eb17fp+4 +-0x1.c4d158p+3 +-0x1.a0004cp+4 +0x1.b62a1p+3 +-0x1.320a1cp+4 +0x1.99bd1cp+4 +0x1.36e0ap+4 +-0x1.da762p+1 +0x1.91eep+2 +0x1.18d928p+3 +0x1.956c5cp+4 +0x1.4226e8p+4 diff --git a/math/w_tgammaf_compat.c b/math/w_tgammaf_compat.c index 34e0e096e0..addbdb1109 100644 --- a/math/w_tgammaf_compat.c +++ b/math/w_tgammaf_compat.c @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -22,8 +23,7 @@ float __tgammaf(float x) { - int local_signgam; - float y = __ieee754_gammaf_r(x,&local_signgam); + float y = __ieee754_gammaf_r(x, NULL); if(__glibc_unlikely (!isfinite (y) || y == 0) && (isfinite (x) || (isinf (x) && x < 0.0)) @@ -41,7 +41,7 @@ __tgammaf(float x) /* tgammaf overflow */ return __kernel_standard_f(x, x, 140); } - return local_signgam < 0 ? - y : y; + return y; } libm_alias_float (__tgamma, tgamma) #endif diff --git a/sysdeps/aarch64/libm-test-ulps b/sysdeps/aarch64/libm-test-ulps index 846fb2c29e..8c333fcd29 100644 --- a/sysdeps/aarch64/libm-test-ulps +++ b/sysdeps/aarch64/libm-test-ulps @@ -1653,22 +1653,18 @@ ldouble: 3 Function: "tgamma": double: 9 -float: 8 ldouble: 4 Function: "tgamma_downward": double: 9 -float: 7 ldouble: 5 Function: "tgamma_towardzero": double: 9 -float: 7 ldouble: 5 Function: "tgamma_upward": double: 9 -float: 8 ldouble: 4 Function: "y0": diff --git a/sysdeps/alpha/fpu/libm-test-ulps b/sysdeps/alpha/fpu/libm-test-ulps index e28c2af683..5c6175406b 100644 --- a/sysdeps/alpha/fpu/libm-test-ulps +++ b/sysdeps/alpha/fpu/libm-test-ulps @@ -1410,22 +1410,18 @@ ldouble: 3 Function: "tgamma": double: 9 -float: 8 ldouble: 4 Function: "tgamma_downward": double: 9 -float: 7 ldouble: 5 Function: "tgamma_towardzero": double: 9 -float: 7 ldouble: 5 Function: "tgamma_upward": double: 9 -float: 8 ldouble: 4 Function: "y0": diff --git a/sysdeps/arc/fpu/libm-test-ulps b/sysdeps/arc/fpu/libm-test-ulps index 7e2c2dff13..d1665b9b72 100644 --- a/sysdeps/arc/fpu/libm-test-ulps +++ b/sysdeps/arc/fpu/libm-test-ulps @@ -1157,19 +1157,15 @@ float: 3 Function: "tgamma": double: 9 -float: 9 Function: "tgamma_downward": double: 9 -float: 9 Function: "tgamma_towardzero": double: 9 -float: 8 Function: "tgamma_upward": double: 9 -float: 9 Function: "y0": double: 3 diff --git a/sysdeps/arc/nofpu/libm-test-ulps b/sysdeps/arc/nofpu/libm-test-ulps index d9d6c76c3e..e768024eb5 100644 --- a/sysdeps/arc/nofpu/libm-test-ulps +++ b/sysdeps/arc/nofpu/libm-test-ulps @@ -279,7 +279,6 @@ float: 2 Function: "tgamma": double: 9 -float: 8 Function: "y0": double: 3 diff --git a/sysdeps/arm/libm-test-ulps b/sysdeps/arm/libm-test-ulps index 100e9d1956..21fe98a7bd 100644 --- a/sysdeps/arm/libm-test-ulps +++ b/sysdeps/arm/libm-test-ulps @@ -1152,19 +1152,15 @@ float: 3 Function: "tgamma": double: 9 -float: 8 Function: "tgamma_downward": double: 9 -float: 7 Function: "tgamma_towardzero": double: 9 -float: 7 Function: "tgamma_upward": double: 9 -float: 8 Function: "y0": double: 3 diff --git a/sysdeps/csky/fpu/libm-test-ulps b/sysdeps/csky/fpu/libm-test-ulps index fc634f89ca..151df00638 100644 --- a/sysdeps/csky/fpu/libm-test-ulps +++ b/sysdeps/csky/fpu/libm-test-ulps @@ -1061,19 +1061,15 @@ float: 3 Function: "tgamma": double: 9 -float: 8 Function: "tgamma_downward": double: 8 -float: 7 Function: "tgamma_towardzero": double: 9 -float: 7 Function: "tgamma_upward": double: 9 -float: 8 Function: "y0": double: 3 diff --git a/sysdeps/csky/nofpu/libm-test-ulps b/sysdeps/csky/nofpu/libm-test-ulps index a1e28c8ee0..48697a7b09 100644 --- a/sysdeps/csky/nofpu/libm-test-ulps +++ b/sysdeps/csky/nofpu/libm-test-ulps @@ -1092,19 +1092,15 @@ float: 3 Function: "tgamma": double: 9 -float: 8 Function: "tgamma_downward": double: 5 -float: 5 Function: "tgamma_towardzero": double: 5 -float: 4 Function: "tgamma_upward": double: 4 -float: 4 Function: "y0": double: 3 diff --git a/sysdeps/hppa/fpu/libm-test-ulps b/sysdeps/hppa/fpu/libm-test-ulps index 4f0709c817..57c1155e8b 100644 --- a/sysdeps/hppa/fpu/libm-test-ulps +++ b/sysdeps/hppa/fpu/libm-test-ulps @@ -1181,20 +1181,16 @@ float: 3 Function: "tgamma": double: 9 -float: 8 ldouble: 1 Function: "tgamma_downward": double: 9 -float: 7 Function: "tgamma_towardzero": double: 9 -float: 7 Function: "tgamma_upward": double: 9 -float: 8 Function: "y0": double: 3 diff --git a/sysdeps/i386/fpu/libm-test-ulps b/sysdeps/i386/fpu/libm-test-ulps index 9e46244752..d13b05a220 100644 --- a/sysdeps/i386/fpu/libm-test-ulps +++ b/sysdeps/i386/fpu/libm-test-ulps @@ -1699,25 +1699,21 @@ ldouble: 4 Function: "tgamma": double: 9 -float: 8 float128: 4 ldouble: 5 Function: "tgamma_downward": double: 9 -float: 7 float128: 5 ldouble: 6 Function: "tgamma_towardzero": double: 9 -float: 7 float128: 5 ldouble: 6 Function: "tgamma_upward": double: 9 -float: 8 float128: 4 ldouble: 5 diff --git a/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps b/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps index 5c41bf36dc..0a813aa8dd 100644 --- a/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps +++ b/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps @@ -1701,25 +1701,21 @@ ldouble: 4 Function: "tgamma": double: 9 -float: 8 float128: 4 ldouble: 5 Function: "tgamma_downward": double: 9 -float: 7 float128: 5 ldouble: 6 Function: "tgamma_towardzero": double: 9 -float: 7 float128: 5 ldouble: 6 Function: "tgamma_upward": double: 8 -float: 8 float128: 4 ldouble: 5 diff --git a/sysdeps/ieee754/dbl-64/gamma_productf.c b/sysdeps/ieee754/dbl-64/gamma_productf.c index f3596eeae4..1cc8931700 100644 --- a/sysdeps/ieee754/dbl-64/gamma_productf.c +++ b/sysdeps/ieee754/dbl-64/gamma_productf.c @@ -1,44 +1 @@ -/* Compute a product of X, X+1, ..., with an error estimate. - Copyright (C) 2013-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#include - -/* Compute the product of X + X_EPS, X + X_EPS + 1, ..., X + X_EPS + N - - 1, in the form R * (1 + *EPS) where the return value R is an - approximation to the product and *EPS is set to indicate the - approximate error in the return value. X is such that all the - values X + 1, ..., X + N - 1 are exactly representable, and X_EPS / - X is small enough that factors quadratic in it can be - neglected. */ - -float -__gamma_productf (float x, float x_eps, int n, float *eps) -{ - double x_full = (double) x + (double) x_eps; - double ret = x_full; - for (int i = 1; i < n; i++) - ret *= x_full + i; - - float fret = math_narrow_eval ((float) ret); - *eps = (ret - fret) / fret; - - return fret; -} +/* Not needed. */ diff --git a/sysdeps/ieee754/flt-32/e_gammaf_r.c b/sysdeps/ieee754/flt-32/e_gammaf_r.c index a9730d61c1..90ed3b4890 100644 --- a/sysdeps/ieee754/flt-32/e_gammaf_r.c +++ b/sysdeps/ieee754/flt-32/e_gammaf_r.c @@ -1,215 +1,150 @@ -/* Implementation of gamma function according to ISO C. - Copyright (C) 1997-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. +/* Implementation of the gamma function for binary32. - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. +Copyright (c) 2023-2024 Alexei Sibidanov. - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. +The original version of this file was copied from the CORE-MATH +project (file src/binary32/tgamma/tgammaf.c, revision a48e352). - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + */ + +/* Changes with respect to the original CORE-MATH code: + - removed the dealing with errno + (this is done in the wrapper math/w_tgammaf_compat.c) + - usage of math_narrow_eval to deal with underflow/overflow + - deal with signgamp + */ #include -#include -#include -#include -#include #include +#include +#include #include +#include -/* Coefficients B_2k / 2k(2k-1) of x^-(2k-1) inside exp in Stirling's - approximation to gamma function. */ - -static const float gamma_coeff[] = - { - 0x1.555556p-4f, - -0xb.60b61p-12f, - 0x3.403404p-12f, - }; - -#define NCOEFF (sizeof (gamma_coeff) / sizeof (gamma_coeff[0])) - -/* Return gamma (X), for positive X less than 42, in the form R * - 2^(*EXP2_ADJ), where R is the return value and *EXP2_ADJ is set to - avoid overflow or underflow in intermediate calculations. */ - -static float -gammaf_positive (float x, int *exp2_adj) -{ - int local_signgam; - if (x < 0.5f) - { - *exp2_adj = 0; - return __ieee754_expf (__ieee754_lgammaf_r (x + 1, &local_signgam)) / x; - } - else if (x <= 1.5f) - { - *exp2_adj = 0; - return __ieee754_expf (__ieee754_lgammaf_r (x, &local_signgam)); - } - else if (x < 2.5f) - { - *exp2_adj = 0; - float x_adj = x - 1; - return (__ieee754_expf (__ieee754_lgammaf_r (x_adj, &local_signgam)) - * x_adj); - } - else - { - float eps = 0; - float x_eps = 0; - float x_adj = x; - float prod = 1; - if (x < 4.0f) - { - /* Adjust into the range for applying Stirling's - approximation. */ - float n = ceilf (4.0f - x); - x_adj = math_narrow_eval (x + n); - x_eps = (x - (x_adj - n)); - prod = __gamma_productf (x_adj - n, x_eps, n, &eps); - } - /* The result is now gamma (X_ADJ + X_EPS) / (PROD * (1 + EPS)). - Compute gamma (X_ADJ + X_EPS) using Stirling's approximation, - starting by computing pow (X_ADJ, X_ADJ) with a power of 2 - factored out. */ - float exp_adj = -eps; - float x_adj_int = roundf (x_adj); - float x_adj_frac = x_adj - x_adj_int; - int x_adj_log2; - float x_adj_mant = __frexpf (x_adj, &x_adj_log2); - if (x_adj_mant < M_SQRT1_2f) - { - x_adj_log2--; - x_adj_mant *= 2.0f; - } - *exp2_adj = x_adj_log2 * (int) x_adj_int; - float ret = (__ieee754_powf (x_adj_mant, x_adj) - * __ieee754_exp2f (x_adj_log2 * x_adj_frac) - * __ieee754_expf (-x_adj) - * sqrtf (2 * M_PIf / x_adj) - / prod); - exp_adj += x_eps * __ieee754_logf (x_adj); - float bsum = gamma_coeff[NCOEFF - 1]; - float x_adj2 = x_adj * x_adj; - for (size_t i = 1; i <= NCOEFF - 1; i++) - bsum = bsum / x_adj2 + gamma_coeff[NCOEFF - 1 - i]; - exp_adj += bsum / x_adj; - return ret + ret * __expm1f (exp_adj); - } -} +typedef union {float f; uint32_t u;} b32u32_u; +typedef union {double f; uint64_t u;} b64u64_u; float __ieee754_gammaf_r (float x, int *signgamp) { - int32_t hx; - float ret; + /* The wrapper in math/w_tgamma_template.c expects *signgamp to be set to a + non-negative value if the returned value is gamma(x), and to a negative + value if it is -gamma(x). + Since the code here directly computes gamma(x), we set it to 1. + */ + if (signgamp != NULL) + *signgamp = 1; - GET_FLOAT_WORD (hx, x); + /* List of exceptional cases. Each entry contains the 32-bit encoding u of x, + a binary32 approximation f of gamma(x), and a correction term df. */ + static const struct {uint32_t u; float f, df;} tb[] = { + {0x27de86a9u, 0x1.268266p+47f, 0x1p22f}, // x = 0x1.bd0d52p-48 + {0x27e05475u, 0x1.242422p+47f, 0x1p22f}, // x = 0x1.c0a8eap-48 + {0xb63befb3u, -0x1.5cb6e4p+18f, 0x1p-7f}, // x = -0x1.77df66p-19 + {0x3c7bb570u, 0x1.021d9p+6f, 0x1p-19f}, // x = 0x1.f76aep-7 + {0x41e886d1u, 0x1.33136ap+98f, 0x1p73f}, // x = 0x1.d10da2p+4 + {0xc067d177u, 0x1.f6850cp-3f, 0x1p-28f}, // x = -0x1.cfa2eep+1 + {0xbd99da31u, -0x1.befe66p+3, -0x1p-22f}, // x = -0x1.33b462p-4 + {0xbf54c45au, -0x1.a6b4ecp+2, +0x1p-23f}, // x = -0x1.a988b4p-1 + {0x41ee77feu, 0x1.d3631cp+101, -0x1p-76f}, // x = 0x1.dceffcp+4 + {0x3f843a64u, 0x1.f6c638p-1, 0x1p-26f}, // x = 0x1.0874c8p+0 + }; - if (__glibc_unlikely ((hx & 0x7fffffff) == 0)) - { - /* Return value for x == 0 is Inf with divide by zero exception. */ - *signgamp = 0; - return 1.0 / x; + b32u32_u t = {.f = x}; + uint32_t ax = t.u<<1; + if(__builtin_expect(ax>=(0xffu<<24), 0)){ /* x=NaN or +/-Inf */ + if(ax==(0xffu<<24)){ /* x=+/-Inf */ + if(t.u>>31){ /* x=-Inf */ + return x / x; /* will raise the "Invalid operation" exception */ + } + return x; /* x=+Inf */ } - if (__builtin_expect (hx < 0, 0) - && (uint32_t) hx < 0xff800000 && rintf (x) == x) - { - /* Return value for integer x < 0 is NaN with invalid exception. */ - *signgamp = 0; - return (x - x) / (x - x); + return x + x; /* x=NaN, where x+x ensures the "Invalid operation" + exception is set if x is sNaN */ + } + double z = x; + if(__builtin_expect(ax<0x6d000000u, 0)){ /* |x| < 0x1p-18 */ + volatile double d = (0x1.fa658c23b1578p-1 - 0x1.d0a118f324b63p-1*z)*z - 0x1.2788cfc6fb619p-1; + double f = 1.0/z + d; + float r = f; + b64u64_u rt = {.f = f}; + if(((rt.u+2)&0xfffffff) < 4){ + for(unsigned i=0;i= 0x1.18522p+5f, 0)){ + /* Overflow case. The original CORE-MATH code returns 0x1p127f * 0x1p127f, + but apparently some compilers replace this by +Inf. */ + return math_narrow_eval (x * 0x1p127f); + } + /* compute k only after the overflow check, otherwise the case to integer + might overflow */ + int k = fx; + if(__builtin_expect(fx==x, 0)){ /* x is integer */ + if(x == 0.0f){ + return 1.0f/x; } - if (__glibc_unlikely ((hx & 0x7f800000) == 0x7f800000)) - { - /* Positive infinity (return positive infinity) or NaN (return - NaN). */ - *signgamp = 0; - return x + x; + if(x < 0.0f){ + return 0.0f / 0.0f; /* should raise the "Invalid operation" exception */ } + double t0 = 1, x0 = 1; + for(int i=1; i= 36.0f) - { - /* Overflow. */ - *signgamp = 0; - ret = math_narrow_eval (FLT_MAX * FLT_MAX); - return ret; + double m = z - 0x1.7p+1, i = __builtin_roundeven(m), step = __builtin_copysign(1.0,i); + double d = m - i, d2 = d*d, d4 = d2*d2, d8 = d4*d4; + double f = (c[0] + d*c[1]) + d2*(c[2] + d*c[3]) + d4*((c[4] + d*c[5]) + d2*(c[6] + d*c[7])) + + d8*((c[8] + d*c[9]) + d2*(c[10] + d*c[11]) + d4*((c[12] + d*c[13]) + d2*(c[14] + d*c[15]))); + int jm = __builtin_fabs(i); + double w = 1; + if(jm){ + z -= 0.5 + step*0.5; + w = z; + for(int j=jm-1; j; j--) {z -= step; w *= z;} + } + if(i<=-0.5) w = 1/w; + f *= w; + b64u64_u rt = {.f = f}; + float r = f; + /* Deal with exceptional cases. */ + if(__builtin_expect(((rt.u+2)&0xfffffff) < 8, 0)){ + for(unsigned j=0;j 0.0f) - { - *signgamp = 0; - int exp2_adj; - float tret = gammaf_positive (x, &exp2_adj); - ret = __scalbnf (tret, exp2_adj); - } - else if (x >= -FLT_EPSILON / 4.0f) - { - *signgamp = 0; - ret = 1.0f / x; - } - else - { - float tx = truncf (x); - *signgamp = (tx == 2.0f * truncf (tx / 2.0f)) ? -1 : 1; - if (x <= -42.0f) - /* Underflow. */ - ret = FLT_MIN * FLT_MIN; - else - { - float frac = tx - x; - if (frac > 0.5f) - frac = 1.0f - frac; - float sinpix = (frac <= 0.25f - ? __sinf (M_PIf * frac) - : __cosf (M_PIf * (0.5f - frac))); - int exp2_adj; - float tret = M_PIf / (-x * sinpix - * gammaf_positive (-x, &exp2_adj)); - ret = __scalbnf (tret, -exp2_adj); - math_check_force_underflow_nonneg (ret); - } - } - ret = math_narrow_eval (ret); - } - if (isinf (ret) && x != 0) - { - if (*signgamp < 0) - { - ret = math_narrow_eval (-copysignf (FLT_MAX, ret) * FLT_MAX); - ret = -ret; - } - else - ret = math_narrow_eval (copysignf (FLT_MAX, ret) * FLT_MAX); - return ret; - } - else if (ret == 0) - { - if (*signgamp < 0) - { - ret = math_narrow_eval (-copysignf (FLT_MIN, ret) * FLT_MIN); - ret = -ret; - } - else - ret = math_narrow_eval (copysignf (FLT_MIN, ret) * FLT_MIN); - return ret; - } - else - return ret; + } + return r; } libm_alias_finite (__ieee754_gammaf_r, __gammaf_r) diff --git a/sysdeps/loongarch/lp64/libm-test-ulps b/sysdeps/loongarch/lp64/libm-test-ulps index 833dca40e4..75e21ee2a8 100644 --- a/sysdeps/loongarch/lp64/libm-test-ulps +++ b/sysdeps/loongarch/lp64/libm-test-ulps @@ -1432,22 +1432,18 @@ ldouble: 3 Function: "tgamma": double: 9 -float: 8 ldouble: 4 Function: "tgamma_downward": double: 9 -float: 7 ldouble: 5 Function: "tgamma_towardzero": double: 9 -float: 7 ldouble: 5 Function: "tgamma_upward": double: 9 -float: 8 ldouble: 4 Function: "y0": diff --git a/sysdeps/m68k/coldfire/fpu/libm-test-ulps b/sysdeps/m68k/coldfire/fpu/libm-test-ulps index 1b25a70e3f..ae05498719 100644 --- a/sysdeps/m68k/coldfire/fpu/libm-test-ulps +++ b/sysdeps/m68k/coldfire/fpu/libm-test-ulps @@ -146,7 +146,6 @@ double: 1 Function: "tgamma": double: 1 -float: 1 Function: "y0": double: 2 diff --git a/sysdeps/m68k/m680x0/fpu/libm-test-ulps b/sysdeps/m68k/m680x0/fpu/libm-test-ulps index 6eacfb6b6f..73e98eb479 100644 --- a/sysdeps/m68k/m680x0/fpu/libm-test-ulps +++ b/sysdeps/m68k/m680x0/fpu/libm-test-ulps @@ -1208,22 +1208,18 @@ float: 1 Function: "tgamma": double: 3 -float: 9 ldouble: 9 Function: "tgamma_downward": double: 3 -float: 9 ldouble: 9 Function: "tgamma_towardzero": double: 3 -float: 9 ldouble: 9 Function: "tgamma_upward": double: 2 -float: 9 ldouble: 9 Function: "y0": diff --git a/sysdeps/microblaze/libm-test-ulps b/sysdeps/microblaze/libm-test-ulps index d3666eb7d4..98ea940ccc 100644 --- a/sysdeps/microblaze/libm-test-ulps +++ b/sysdeps/microblaze/libm-test-ulps @@ -257,7 +257,6 @@ float: 2 Function: "tgamma": double: 5 -float: 4 Function: "y0": double: 2 diff --git a/sysdeps/mips/mips32/libm-test-ulps b/sysdeps/mips/mips32/libm-test-ulps index d95230724b..cc1600c2ab 100644 --- a/sysdeps/mips/mips32/libm-test-ulps +++ b/sysdeps/mips/mips32/libm-test-ulps @@ -1156,19 +1156,15 @@ float: 3 Function: "tgamma": double: 9 -float: 8 Function: "tgamma_downward": double: 9 -float: 7 Function: "tgamma_towardzero": double: 9 -float: 7 Function: "tgamma_upward": double: 9 -float: 8 Function: "y0": double: 3 diff --git a/sysdeps/mips/mips64/libm-test-ulps b/sysdeps/mips/mips64/libm-test-ulps index ce33d9b4b3..88dbb20401 100644 --- a/sysdeps/mips/mips64/libm-test-ulps +++ b/sysdeps/mips/mips64/libm-test-ulps @@ -1444,22 +1444,18 @@ ldouble: 3 Function: "tgamma": double: 9 -float: 8 ldouble: 4 Function: "tgamma_downward": double: 9 -float: 7 ldouble: 5 Function: "tgamma_towardzero": double: 9 -float: 7 ldouble: 5 Function: "tgamma_upward": double: 9 -float: 8 ldouble: 4 Function: "y0": diff --git a/sysdeps/nios2/libm-test-ulps b/sysdeps/nios2/libm-test-ulps index c8d1a722f7..df6e932cb6 100644 --- a/sysdeps/nios2/libm-test-ulps +++ b/sysdeps/nios2/libm-test-ulps @@ -266,7 +266,6 @@ float: 2 Function: "tgamma": double: 9 -float: 8 Function: "y0": double: 3 diff --git a/sysdeps/or1k/fpu/libm-test-ulps b/sysdeps/or1k/fpu/libm-test-ulps index 59b9f072f5..4ccb136298 100644 --- a/sysdeps/or1k/fpu/libm-test-ulps +++ b/sysdeps/or1k/fpu/libm-test-ulps @@ -1066,19 +1066,15 @@ float: 3 Function: "tgamma": double: 9 -float: 8 Function: "tgamma_downward": double: 9 -float: 9 Function: "tgamma_towardzero": double: 9 -float: 8 Function: "tgamma_upward": double: 9 -float: 8 Function: "y0": double: 3 diff --git a/sysdeps/or1k/nofpu/libm-test-ulps b/sysdeps/or1k/nofpu/libm-test-ulps index 726855faaa..7087cf9add 100644 --- a/sysdeps/or1k/nofpu/libm-test-ulps +++ b/sysdeps/or1k/nofpu/libm-test-ulps @@ -1064,19 +1064,15 @@ float: 3 Function: "tgamma": double: 9 -float: 8 Function: "tgamma_downward": double: 9 -float: 9 Function: "tgamma_towardzero": double: 9 -float: 8 Function: "tgamma_upward": double: 9 -float: 8 Function: "y0": double: 3 diff --git a/sysdeps/powerpc/fpu/libm-test-ulps b/sysdeps/powerpc/fpu/libm-test-ulps index 2b5d2b940d..dcefbcefcf 100644 --- a/sysdeps/powerpc/fpu/libm-test-ulps +++ b/sysdeps/powerpc/fpu/libm-test-ulps @@ -1828,25 +1828,21 @@ ldouble: 6 Function: "tgamma": double: 9 -float: 8 float128: 4 ldouble: 5 Function: "tgamma_downward": double: 9 -float: 7 float128: 5 ldouble: 6 Function: "tgamma_towardzero": double: 9 -float: 7 float128: 5 ldouble: 5 Function: "tgamma_upward": double: 9 -float: 8 float128: 4 ldouble: 5 diff --git a/sysdeps/powerpc/nofpu/libm-test-ulps b/sysdeps/powerpc/nofpu/libm-test-ulps index d56327ac33..14be978dc3 100644 --- a/sysdeps/powerpc/nofpu/libm-test-ulps +++ b/sysdeps/powerpc/nofpu/libm-test-ulps @@ -1560,22 +1560,18 @@ ldouble: 6 Function: "tgamma": double: 9 -float: 8 ldouble: 5 Function: "tgamma_downward": double: 9 -float: 7 ldouble: 5 Function: "tgamma_towardzero": double: 9 -float: 7 ldouble: 5 Function: "tgamma_upward": double: 9 -float: 8 ldouble: 4 Function: "y0": diff --git a/sysdeps/riscv/nofpu/libm-test-ulps b/sysdeps/riscv/nofpu/libm-test-ulps index 9ad64d1d85..4adad138b0 100644 --- a/sysdeps/riscv/nofpu/libm-test-ulps +++ b/sysdeps/riscv/nofpu/libm-test-ulps @@ -1361,22 +1361,18 @@ ldouble: 3 Function: "tgamma": double: 9 -float: 8 ldouble: 4 Function: "tgamma_downward": double: 5 -float: 5 ldouble: 5 Function: "tgamma_towardzero": double: 5 -float: 4 ldouble: 5 Function: "tgamma_upward": double: 4 -float: 4 ldouble: 4 Function: "y0": diff --git a/sysdeps/riscv/rvd/libm-test-ulps b/sysdeps/riscv/rvd/libm-test-ulps index 233186f29a..07a8794e48 100644 --- a/sysdeps/riscv/rvd/libm-test-ulps +++ b/sysdeps/riscv/rvd/libm-test-ulps @@ -1431,22 +1431,18 @@ ldouble: 3 Function: "tgamma": double: 9 -float: 8 ldouble: 4 Function: "tgamma_downward": double: 9 -float: 7 ldouble: 5 Function: "tgamma_towardzero": double: 9 -float: 7 ldouble: 5 Function: "tgamma_upward": double: 8 -float: 8 ldouble: 4 Function: "y0": diff --git a/sysdeps/s390/fpu/libm-test-ulps b/sysdeps/s390/fpu/libm-test-ulps index e10b5c69ae..6e4084ae37 100644 --- a/sysdeps/s390/fpu/libm-test-ulps +++ b/sysdeps/s390/fpu/libm-test-ulps @@ -1429,22 +1429,18 @@ ldouble: 3 Function: "tgamma": double: 9 -float: 8 ldouble: 4 Function: "tgamma_downward": double: 9 -float: 7 ldouble: 5 Function: "tgamma_towardzero": double: 9 -float: 7 ldouble: 5 Function: "tgamma_upward": double: 9 -float: 8 ldouble: 4 Function: "y0": diff --git a/sysdeps/sh/libm-test-ulps b/sysdeps/sh/libm-test-ulps index 3c84259941..36f21ed395 100644 --- a/sysdeps/sh/libm-test-ulps +++ b/sysdeps/sh/libm-test-ulps @@ -532,11 +532,9 @@ float: 2 Function: "tgamma": double: 9 -float: 8 Function: "tgamma_towardzero": double: 9 -float: 7 Function: "y0": double: 3 diff --git a/sysdeps/sparc/fpu/libm-test-ulps b/sysdeps/sparc/fpu/libm-test-ulps index 1bb8b7c5f4..ccb6c794e7 100644 --- a/sysdeps/sparc/fpu/libm-test-ulps +++ b/sysdeps/sparc/fpu/libm-test-ulps @@ -1444,22 +1444,18 @@ ldouble: 3 Function: "tgamma": double: 9 -float: 8 ldouble: 4 Function: "tgamma_downward": double: 9 -float: 7 ldouble: 5 Function: "tgamma_towardzero": double: 9 -float: 7 ldouble: 5 Function: "tgamma_upward": double: 9 -float: 8 ldouble: 4 Function: "y0": diff --git a/sysdeps/x86_64/fpu/libm-test-ulps b/sysdeps/x86_64/fpu/libm-test-ulps index c2e36dcbdf..80d0125642 100644 --- a/sysdeps/x86_64/fpu/libm-test-ulps +++ b/sysdeps/x86_64/fpu/libm-test-ulps @@ -2263,25 +2263,21 @@ double: 1 Function: "tgamma": double: 9 -float: 8 float128: 4 ldouble: 5 Function: "tgamma_downward": double: 9 -float: 7 float128: 5 ldouble: 6 Function: "tgamma_towardzero": double: 9 -float: 7 float128: 5 ldouble: 6 Function: "tgamma_upward": double: 9 -float: 8 float128: 4 ldouble: 5