Skip to content

Commit 5d6d1f9

Browse files
committed
libstdc++: Allow C99 long double math functions to be optional
The C99 math functions in the <cmath> header file are declared if and only if the `_GLIBCXX_USE_C99_MATH_TR1` is defined, whose autoconf check, `glibcxx_cv_c99_math_tr1`, requires all C99 math functions, including the `long double` math functions, to be available. Some C library implementations (for instance, newlib) may omit the C99 long double math function support when the type of `long double` is different from the type of `double` and, in such cases, the <cmath> header file ends up omitting the entirety of the C99 math functions. This commit reworks the `glibcxx_cv_c99_math_tr1` check such that it only tests the non-`long double` math functions, and adds a new check, `glibcxx_cv_c99_math_long_double`, that tests the `long double` math functions and defines `_GLIBCXX_USE_C99_MATH_LONG_DOUBLE_FUNCS` when these functions are available; which is then used by the <cmath> header file to conditionally import the C99 `long double` math functions, effectively making the C99 long double math function support in <cmath> an optional feature. libstdc++-v3/ChangeLog: * acinclude.m4 (_GLIBCXX_USE_C99_MATH_LONG_DOUBLE_FUNCS): New macro. (_GLIBCXX_USE_C99_MATH_TR1): Remove long double function tests. * config.h.in: Regenerate. * configure: Regenerate. * include/c_global/cmath: Use _GLIBCXX_USE_C99_MATH_LONG_DOUBLE_FUNCS. * include/tr1/cmath: Likewise. Signed-off-by: Stephanos Ioannidis <root@stephanos.io> Upstream-Status: Inappropriate [non-standard]
1 parent ebc0b98 commit 5d6d1f9

File tree

5 files changed

+206
-148
lines changed

5 files changed

+206
-148
lines changed

libstdc++-v3/acinclude.m4

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,118 +1819,132 @@ AC_DEFUN([GLIBCXX_CHECK_C99_TR1], [
18191819
typedef float_t my_float_t;
18201820
acosh(0.0);
18211821
acoshf(0.0f);
1822-
acoshl(0.0l);
18231822
asinh(0.0);
18241823
asinhf(0.0f);
1825-
asinhl(0.0l);
18261824
atanh(0.0);
18271825
atanhf(0.0f);
1828-
atanhl(0.0l);
18291826
cbrt(0.0);
18301827
cbrtf(0.0f);
1831-
cbrtl(0.0l);
18321828
copysign(0.0, 0.0);
18331829
copysignf(0.0f, 0.0f);
1834-
copysignl(0.0l, 0.0l);
18351830
erf(0.0);
18361831
erff(0.0f);
1837-
erfl(0.0l);
18381832
erfc(0.0);
18391833
erfcf(0.0f);
1840-
erfcl(0.0l);
18411834
exp2(0.0);
18421835
exp2f(0.0f);
1843-
exp2l(0.0l);
18441836
expm1(0.0);
18451837
expm1f(0.0f);
1846-
expm1l(0.0l);
18471838
fdim(0.0, 0.0);
18481839
fdimf(0.0f, 0.0f);
1849-
fdiml(0.0l, 0.0l);
18501840
fma(0.0, 0.0, 0.0);
18511841
fmaf(0.0f, 0.0f, 0.0f);
1852-
fmal(0.0l, 0.0l, 0.0l);
18531842
fmax(0.0, 0.0);
18541843
fmaxf(0.0f, 0.0f);
1855-
fmaxl(0.0l, 0.0l);
18561844
fmin(0.0, 0.0);
18571845
fminf(0.0f, 0.0f);
1858-
fminl(0.0l, 0.0l);
18591846
hypot(0.0, 0.0);
18601847
hypotf(0.0f, 0.0f);
1861-
hypotl(0.0l, 0.0l);
18621848
ilogb(0.0);
18631849
ilogbf(0.0f);
1864-
ilogbl(0.0l);
18651850
lgamma(0.0);
18661851
lgammaf(0.0f);
1867-
lgammal(0.0l);
18681852
#ifndef __APPLE__ /* see below */
18691853
llrint(0.0);
18701854
llrintf(0.0f);
1871-
llrintl(0.0l);
18721855
llround(0.0);
18731856
llroundf(0.0f);
1874-
llroundl(0.0l);
18751857
#endif
18761858
log1p(0.0);
18771859
log1pf(0.0f);
1878-
log1pl(0.0l);
18791860
log2(0.0);
18801861
log2f(0.0f);
1881-
log2l(0.0l);
18821862
logb(0.0);
18831863
logbf(0.0f);
1884-
logbl(0.0l);
18851864
lrint(0.0);
18861865
lrintf(0.0f);
1887-
lrintl(0.0l);
18881866
lround(0.0);
18891867
lroundf(0.0f);
1890-
lroundl(0.0l);
18911868
nan(0);
18921869
nanf(0);
1893-
nanl(0);
18941870
nearbyint(0.0);
18951871
nearbyintf(0.0f);
1896-
nearbyintl(0.0l);
18971872
nextafter(0.0, 0.0);
18981873
nextafterf(0.0f, 0.0f);
1899-
nextafterl(0.0l, 0.0l);
1900-
nexttoward(0.0, 0.0);
1901-
nexttowardf(0.0f, 0.0f);
1902-
nexttowardl(0.0l, 0.0l);
19031874
remainder(0.0, 0.0);
19041875
remainderf(0.0f, 0.0f);
1905-
remainderl(0.0l, 0.0l);
19061876
remquo(0.0, 0.0, 0);
19071877
remquof(0.0f, 0.0f, 0);
1908-
remquol(0.0l, 0.0l, 0);
19091878
rint(0.0);
19101879
rintf(0.0f);
1911-
rintl(0.0l);
19121880
round(0.0);
19131881
roundf(0.0f);
1914-
roundl(0.0l);
19151882
scalbln(0.0, 0l);
19161883
scalblnf(0.0f, 0l);
1917-
scalblnl(0.0l, 0l);
19181884
scalbn(0.0, 0);
19191885
scalbnf(0.0f, 0);
1920-
scalbnl(0.0l, 0);
19211886
tgamma(0.0);
19221887
tgammaf(0.0f);
1923-
tgammal(0.0l);
19241888
trunc(0.0);
19251889
truncf(0.0f);
1926-
truncl(0.0l);
19271890
],[glibcxx_cv_c99_math_tr1=yes], [glibcxx_cv_c99_math_tr1=no])
19281891
])
19291892
if test x"$glibcxx_cv_c99_math_tr1" = x"yes"; then
19301893
AC_DEFINE(_GLIBCXX_USE_C99_MATH_TR1, 1,
19311894
[Define if C99 functions or macros in <math.h> should be imported
19321895
in <tr1/cmath> in namespace std::tr1.])
19331896
1897+
AC_CACHE_CHECK([for ISO C99 long double math functions in <math.h>],
1898+
glibcxx_cv_c99_math_long_double, [
1899+
AC_TRY_COMPILE([#include <math.h>],
1900+
[acoshl(0.0l);
1901+
asinhl(0.0l);
1902+
atanhl(0.0l);
1903+
cbrtl(0.0l);
1904+
copysignl(0.0l, 0.0l);
1905+
erfl(0.0l);
1906+
erfcl(0.0l);
1907+
exp2l(0.0l);
1908+
expm1l(0.0l);
1909+
fdiml(0.0l, 0.0l);
1910+
fmal(0.0l, 0.0l, 0.0l);
1911+
fmaxl(0.0l, 0.0l);
1912+
fminl(0.0l, 0.0l);
1913+
hypotl(0.0l, 0.0l);
1914+
ilogbl(0.0l);
1915+
lgammal(0.0l);
1916+
#ifndef __APPLE__ /* see below */
1917+
llrintl(0.0l);
1918+
llroundl(0.0l);
1919+
#endif
1920+
log1pl(0.0l);
1921+
log2l(0.0l);
1922+
logbl(0.0l);
1923+
lrintl(0.0l);
1924+
lroundl(0.0l);
1925+
nanl(0);
1926+
nearbyintl(0.0l);
1927+
nextafterl(0.0l, 0.0l);
1928+
nexttoward(0.0, 0.0);
1929+
nexttowardf(0.0f, 0.0f);
1930+
nexttowardl(0.0l, 0.0l);
1931+
remainderl(0.0l, 0.0l);
1932+
remquol(0.0l, 0.0l, 0);
1933+
rintl(0.0l);
1934+
roundl(0.0l);
1935+
scalblnl(0.0l, 0l);
1936+
scalbnl(0.0l, 0);
1937+
tgammal(0.0l);
1938+
truncl(0.0l);
1939+
],
1940+
[glibcxx_cv_c99_math_long_double=yes],
1941+
[glibcxx_cv_c99_math_long_double=no])
1942+
])
1943+
if test x"$glibcxx_cv_c99_math_long_double" = x"yes"; then
1944+
AC_DEFINE(_GLIBCXX_USE_C99_MATH_LONG_DOUBLE_FUNCS, 1,
1945+
[Define if C99 long double math functions are available in <math.h>.])
1946+
fi
1947+
19341948
case "${target_os}" in
19351949
darwin*)
19361950
AC_CACHE_CHECK([for ISO C99 rounding functions in <math.h>],

libstdc++-v3/config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,9 @@
925925
<tr1/cinttypes> in namespace std::tr1. */
926926
#undef _GLIBCXX_USE_C99_INTTYPES_WCHAR_T_TR1
927927

928+
/* Define if C99 long double math functions are available in <math.h>. */
929+
#undef _GLIBCXX_USE_C99_MATH_LONG_DOUBLE_FUNCS
930+
928931
/* Define if C99 functions or macros in <math.h> should be imported in
929932
<tr1/cmath> in namespace std::tr1. */
930933
#undef _GLIBCXX_USE_C99_MATH_TR1

libstdc++-v3/configure

Lines changed: 72 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20001,111 +20001,74 @@ typedef double_t my_double_t;
2000120001
typedef float_t my_float_t;
2000220002
acosh(0.0);
2000320003
acoshf(0.0f);
20004-
acoshl(0.0l);
2000520004
asinh(0.0);
2000620005
asinhf(0.0f);
20007-
asinhl(0.0l);
2000820006
atanh(0.0);
2000920007
atanhf(0.0f);
20010-
atanhl(0.0l);
2001120008
cbrt(0.0);
2001220009
cbrtf(0.0f);
20013-
cbrtl(0.0l);
2001420010
copysign(0.0, 0.0);
2001520011
copysignf(0.0f, 0.0f);
20016-
copysignl(0.0l, 0.0l);
2001720012
erf(0.0);
2001820013
erff(0.0f);
20019-
erfl(0.0l);
2002020014
erfc(0.0);
2002120015
erfcf(0.0f);
20022-
erfcl(0.0l);
2002320016
exp2(0.0);
2002420017
exp2f(0.0f);
20025-
exp2l(0.0l);
2002620018
expm1(0.0);
2002720019
expm1f(0.0f);
20028-
expm1l(0.0l);
2002920020
fdim(0.0, 0.0);
2003020021
fdimf(0.0f, 0.0f);
20031-
fdiml(0.0l, 0.0l);
2003220022
fma(0.0, 0.0, 0.0);
2003320023
fmaf(0.0f, 0.0f, 0.0f);
20034-
fmal(0.0l, 0.0l, 0.0l);
2003520024
fmax(0.0, 0.0);
2003620025
fmaxf(0.0f, 0.0f);
20037-
fmaxl(0.0l, 0.0l);
2003820026
fmin(0.0, 0.0);
2003920027
fminf(0.0f, 0.0f);
20040-
fminl(0.0l, 0.0l);
2004120028
hypot(0.0, 0.0);
2004220029
hypotf(0.0f, 0.0f);
20043-
hypotl(0.0l, 0.0l);
2004420030
ilogb(0.0);
2004520031
ilogbf(0.0f);
20046-
ilogbl(0.0l);
2004720032
lgamma(0.0);
2004820033
lgammaf(0.0f);
20049-
lgammal(0.0l);
2005020034
#ifndef __APPLE__ /* see below */
2005120035
llrint(0.0);
2005220036
llrintf(0.0f);
20053-
llrintl(0.0l);
2005420037
llround(0.0);
2005520038
llroundf(0.0f);
20056-
llroundl(0.0l);
2005720039
#endif
2005820040
log1p(0.0);
2005920041
log1pf(0.0f);
20060-
log1pl(0.0l);
2006120042
log2(0.0);
2006220043
log2f(0.0f);
20063-
log2l(0.0l);
2006420044
logb(0.0);
2006520045
logbf(0.0f);
20066-
logbl(0.0l);
2006720046
lrint(0.0);
2006820047
lrintf(0.0f);
20069-
lrintl(0.0l);
2007020048
lround(0.0);
2007120049
lroundf(0.0f);
20072-
lroundl(0.0l);
2007320050
nan(0);
2007420051
nanf(0);
20075-
nanl(0);
2007620052
nearbyint(0.0);
2007720053
nearbyintf(0.0f);
20078-
nearbyintl(0.0l);
2007920054
nextafter(0.0, 0.0);
2008020055
nextafterf(0.0f, 0.0f);
20081-
nextafterl(0.0l, 0.0l);
20082-
nexttoward(0.0, 0.0);
20083-
nexttowardf(0.0f, 0.0f);
20084-
nexttowardl(0.0l, 0.0l);
2008520056
remainder(0.0, 0.0);
2008620057
remainderf(0.0f, 0.0f);
20087-
remainderl(0.0l, 0.0l);
2008820058
remquo(0.0, 0.0, 0);
2008920059
remquof(0.0f, 0.0f, 0);
20090-
remquol(0.0l, 0.0l, 0);
2009120060
rint(0.0);
2009220061
rintf(0.0f);
20093-
rintl(0.0l);
2009420062
round(0.0);
2009520063
roundf(0.0f);
20096-
roundl(0.0l);
2009720064
scalbln(0.0, 0l);
2009820065
scalblnf(0.0f, 0l);
20099-
scalblnl(0.0l, 0l);
2010020066
scalbn(0.0, 0);
2010120067
scalbnf(0.0f, 0);
20102-
scalbnl(0.0l, 0);
2010320068
tgamma(0.0);
2010420069
tgammaf(0.0f);
20105-
tgammal(0.0l);
2010620070
trunc(0.0);
2010720071
truncf(0.0f);
20108-
truncl(0.0l);
2010920072

2011020073
;
2011120074
return 0;
@@ -20126,6 +20089,78 @@ $as_echo "$glibcxx_cv_c99_math_tr1" >&6; }
2012620089
$as_echo "#define _GLIBCXX_USE_C99_MATH_TR1 1" >>confdefs.h
2012720090

2012820091

20092+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ISO C99 long double math functions in <math.h>" >&5
20093+
$as_echo_n "checking for ISO C99 long double math functions in <math.h>... " >&6; }
20094+
if ${glibcxx_cv_c99_math_long_double+:} false; then :
20095+
$as_echo_n "(cached) " >&6
20096+
else
20097+
20098+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
20099+
/* end confdefs.h. */
20100+
#include <math.h>
20101+
int
20102+
main ()
20103+
{
20104+
acoshl(0.0l);
20105+
asinhl(0.0l);
20106+
atanhl(0.0l);
20107+
cbrtl(0.0l);
20108+
copysignl(0.0l, 0.0l);
20109+
erfl(0.0l);
20110+
erfcl(0.0l);
20111+
exp2l(0.0l);
20112+
expm1l(0.0l);
20113+
fdiml(0.0l, 0.0l);
20114+
fmal(0.0l, 0.0l, 0.0l);
20115+
fmaxl(0.0l, 0.0l);
20116+
fminl(0.0l, 0.0l);
20117+
hypotl(0.0l, 0.0l);
20118+
ilogbl(0.0l);
20119+
lgammal(0.0l);
20120+
#ifndef __APPLE__ /* see below */
20121+
llrintl(0.0l);
20122+
llroundl(0.0l);
20123+
#endif
20124+
log1pl(0.0l);
20125+
log2l(0.0l);
20126+
logbl(0.0l);
20127+
lrintl(0.0l);
20128+
lroundl(0.0l);
20129+
nanl(0);
20130+
nearbyintl(0.0l);
20131+
nextafterl(0.0l, 0.0l);
20132+
nexttoward(0.0, 0.0);
20133+
nexttowardf(0.0f, 0.0f);
20134+
nexttowardl(0.0l, 0.0l);
20135+
remainderl(0.0l, 0.0l);
20136+
remquol(0.0l, 0.0l, 0);
20137+
rintl(0.0l);
20138+
roundl(0.0l);
20139+
scalblnl(0.0l, 0l);
20140+
scalbnl(0.0l, 0);
20141+
tgammal(0.0l);
20142+
truncl(0.0l);
20143+
20144+
;
20145+
return 0;
20146+
}
20147+
_ACEOF
20148+
if ac_fn_cxx_try_compile "$LINENO"; then :
20149+
glibcxx_cv_c99_math_long_double=yes
20150+
else
20151+
glibcxx_cv_c99_math_long_double=no
20152+
fi
20153+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
20154+
20155+
fi
20156+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_c99_math_long_double" >&5
20157+
$as_echo "$glibcxx_cv_c99_math_long_double" >&6; }
20158+
if test x"$glibcxx_cv_c99_math_long_double" = x"yes"; then
20159+
20160+
$as_echo "#define _GLIBCXX_USE_C99_MATH_LONG_DOUBLE_FUNCS 1" >>confdefs.h
20161+
20162+
fi
20163+
2012920164
case "${target_os}" in
2013020165
darwin*)
2013120166
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ISO C99 rounding functions in <math.h>" >&5

0 commit comments

Comments
 (0)