Skip to content

Commit 4829545

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 <[email protected]> Upstream-Status: Inappropriate [non-standard]
1 parent 27e7d24 commit 4829545

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
@@ -2227,117 +2227,131 @@ AC_DEFUN([GLIBCXX_CHECK_C99_TR1], [
22272227
typedef float_t my_float_t;
22282228
acosh(0.0);
22292229
acoshf(0.0f);
2230-
acoshl(0.0l);
22312230
asinh(0.0);
22322231
asinhf(0.0f);
2233-
asinhl(0.0l);
22342232
atanh(0.0);
22352233
atanhf(0.0f);
2236-
atanhl(0.0l);
22372234
cbrt(0.0);
22382235
cbrtf(0.0f);
2239-
cbrtl(0.0l);
22402236
copysign(0.0, 0.0);
22412237
copysignf(0.0f, 0.0f);
2242-
copysignl(0.0l, 0.0l);
22432238
erf(0.0);
22442239
erff(0.0f);
2245-
erfl(0.0l);
22462240
erfc(0.0);
22472241
erfcf(0.0f);
2248-
erfcl(0.0l);
22492242
exp2(0.0);
22502243
exp2f(0.0f);
2251-
exp2l(0.0l);
22522244
expm1(0.0);
22532245
expm1f(0.0f);
2254-
expm1l(0.0l);
22552246
fdim(0.0, 0.0);
22562247
fdimf(0.0f, 0.0f);
2257-
fdiml(0.0l, 0.0l);
22582248
fma(0.0, 0.0, 0.0);
22592249
fmaf(0.0f, 0.0f, 0.0f);
2260-
fmal(0.0l, 0.0l, 0.0l);
22612250
fmax(0.0, 0.0);
22622251
fmaxf(0.0f, 0.0f);
2263-
fmaxl(0.0l, 0.0l);
22642252
fmin(0.0, 0.0);
22652253
fminf(0.0f, 0.0f);
2266-
fminl(0.0l, 0.0l);
22672254
hypot(0.0, 0.0);
22682255
hypotf(0.0f, 0.0f);
2269-
hypotl(0.0l, 0.0l);
22702256
ilogb(0.0);
22712257
ilogbf(0.0f);
2272-
ilogbl(0.0l);
22732258
lgamma(0.0);
22742259
lgammaf(0.0f);
2275-
lgammal(0.0l);
22762260
#ifndef __APPLE__ /* see below */
22772261
llrint(0.0);
22782262
llrintf(0.0f);
2279-
llrintl(0.0l);
22802263
llround(0.0);
22812264
llroundf(0.0f);
2282-
llroundl(0.0l);
22832265
#endif
22842266
log1p(0.0);
22852267
log1pf(0.0f);
2286-
log1pl(0.0l);
22872268
log2(0.0);
22882269
log2f(0.0f);
2289-
log2l(0.0l);
22902270
logb(0.0);
22912271
logbf(0.0f);
2292-
logbl(0.0l);
22932272
lrint(0.0);
22942273
lrintf(0.0f);
2295-
lrintl(0.0l);
22962274
lround(0.0);
22972275
lroundf(0.0f);
2298-
lroundl(0.0l);
22992276
nan("");
23002277
nanf("");
2301-
nanl("");
23022278
nearbyint(0.0);
23032279
nearbyintf(0.0f);
2304-
nearbyintl(0.0l);
23052280
nextafter(0.0, 0.0);
23062281
nextafterf(0.0f, 0.0f);
2307-
nextafterl(0.0l, 0.0l);
2308-
nexttoward(0.0, 0.0);
2309-
nexttowardf(0.0f, 0.0f);
2310-
nexttowardl(0.0l, 0.0l);
23112282
remainder(0.0, 0.0);
23122283
remainderf(0.0f, 0.0f);
2313-
remainderl(0.0l, 0.0l);
23142284
remquo(0.0, 0.0, 0);
23152285
remquof(0.0f, 0.0f, 0);
2316-
remquol(0.0l, 0.0l, 0);
23172286
rint(0.0);
23182287
rintf(0.0f);
2319-
rintl(0.0l);
23202288
round(0.0);
23212289
roundf(0.0f);
2322-
roundl(0.0l);
23232290
scalbln(0.0, 0l);
23242291
scalblnf(0.0f, 0l);
2325-
scalblnl(0.0l, 0l);
23262292
scalbn(0.0, 0);
23272293
scalbnf(0.0f, 0);
2328-
scalbnl(0.0l, 0);
23292294
tgamma(0.0);
23302295
tgammaf(0.0f);
2331-
tgammal(0.0l);
23322296
trunc(0.0);
23332297
truncf(0.0f);
2334-
truncl(0.0l);
23352298
],[glibcxx_cv_c99_math_tr1=yes], [glibcxx_cv_c99_math_tr1=no])
23362299
])
23372300
if test x"$glibcxx_cv_c99_math_tr1" = x"yes"; then
23382301
AC_DEFINE(_GLIBCXX_USE_C99_MATH_TR1, 1,
23392302
[Define if C99 functions or macros in <math.h> should be imported
23402303
in <tr1/cmath> in namespace std::tr1.])
2304+
2305+
AC_CACHE_CHECK([for ISO C99 long double math functions in <math.h>],
2306+
glibcxx_cv_c99_math_long_double, [
2307+
AC_TRY_COMPILE([#include <math.h>],
2308+
[acoshl(0.0l);
2309+
asinhl(0.0l);
2310+
atanhl(0.0l);
2311+
cbrtl(0.0l);
2312+
copysignl(0.0l, 0.0l);
2313+
erfl(0.0l);
2314+
erfcl(0.0l);
2315+
exp2l(0.0l);
2316+
expm1l(0.0l);
2317+
fdiml(0.0l, 0.0l);
2318+
fmal(0.0l, 0.0l, 0.0l);
2319+
fmaxl(0.0l, 0.0l);
2320+
fminl(0.0l, 0.0l);
2321+
hypotl(0.0l, 0.0l);
2322+
ilogbl(0.0l);
2323+
lgammal(0.0l);
2324+
#ifndef __APPLE__ /* see below */
2325+
llrintl(0.0l);
2326+
llroundl(0.0l);
2327+
#endif
2328+
log1pl(0.0l);
2329+
log2l(0.0l);
2330+
logbl(0.0l);
2331+
lrintl(0.0l);
2332+
lroundl(0.0l);
2333+
nanl("");
2334+
nearbyintl(0.0l);
2335+
nextafterl(0.0l, 0.0l);
2336+
nexttoward(0.0, 0.0);
2337+
nexttowardf(0.0f, 0.0f);
2338+
nexttowardl(0.0l, 0.0l);
2339+
remainderl(0.0l, 0.0l);
2340+
remquol(0.0l, 0.0l, 0);
2341+
rintl(0.0l);
2342+
roundl(0.0l);
2343+
scalblnl(0.0l, 0l);
2344+
scalbnl(0.0l, 0);
2345+
tgammal(0.0l);
2346+
truncl(0.0l);
2347+
],
2348+
[glibcxx_cv_c99_math_long_double=yes],
2349+
[glibcxx_cv_c99_math_long_double=no])
2350+
])
2351+
if test x"$glibcxx_cv_c99_math_long_double" = x"yes"; then
2352+
AC_DEFINE(_GLIBCXX_USE_C99_MATH_LONG_DOUBLE_FUNCS, 1,
2353+
[Define if C99 long double math functions are available in <math.h>.])
2354+
fi
23412355
fi
23422356
23432357
# Check for the existence of <inttypes.h> functions (NB: doesn't make

libstdc++-v3/config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,9 @@
766766
namespace std for C++11. */
767767
#undef _GLIBCXX_USE_C99_MATH_FUNCS
768768

769+
/* Define if C99 long double math functions are available in <math.h>. */
770+
#undef _GLIBCXX_USE_C99_MATH_LONG_DOUBLE_FUNCS
771+
769772
/* Define if C99 functions or macros in <math.h> should be imported in
770773
<tr1/cmath> in namespace std::tr1. */
771774
#undef _GLIBCXX_USE_C99_MATH_TR1

libstdc++-v3/configure

Lines changed: 72 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20845,111 +20845,74 @@ typedef double_t my_double_t;
2084520845
typedef float_t my_float_t;
2084620846
acosh(0.0);
2084720847
acoshf(0.0f);
20848-
acoshl(0.0l);
2084920848
asinh(0.0);
2085020849
asinhf(0.0f);
20851-
asinhl(0.0l);
2085220850
atanh(0.0);
2085320851
atanhf(0.0f);
20854-
atanhl(0.0l);
2085520852
cbrt(0.0);
2085620853
cbrtf(0.0f);
20857-
cbrtl(0.0l);
2085820854
copysign(0.0, 0.0);
2085920855
copysignf(0.0f, 0.0f);
20860-
copysignl(0.0l, 0.0l);
2086120856
erf(0.0);
2086220857
erff(0.0f);
20863-
erfl(0.0l);
2086420858
erfc(0.0);
2086520859
erfcf(0.0f);
20866-
erfcl(0.0l);
2086720860
exp2(0.0);
2086820861
exp2f(0.0f);
20869-
exp2l(0.0l);
2087020862
expm1(0.0);
2087120863
expm1f(0.0f);
20872-
expm1l(0.0l);
2087320864
fdim(0.0, 0.0);
2087420865
fdimf(0.0f, 0.0f);
20875-
fdiml(0.0l, 0.0l);
2087620866
fma(0.0, 0.0, 0.0);
2087720867
fmaf(0.0f, 0.0f, 0.0f);
20878-
fmal(0.0l, 0.0l, 0.0l);
2087920868
fmax(0.0, 0.0);
2088020869
fmaxf(0.0f, 0.0f);
20881-
fmaxl(0.0l, 0.0l);
2088220870
fmin(0.0, 0.0);
2088320871
fminf(0.0f, 0.0f);
20884-
fminl(0.0l, 0.0l);
2088520872
hypot(0.0, 0.0);
2088620873
hypotf(0.0f, 0.0f);
20887-
hypotl(0.0l, 0.0l);
2088820874
ilogb(0.0);
2088920875
ilogbf(0.0f);
20890-
ilogbl(0.0l);
2089120876
lgamma(0.0);
2089220877
lgammaf(0.0f);
20893-
lgammal(0.0l);
2089420878
#ifndef __APPLE__ /* see below */
2089520879
llrint(0.0);
2089620880
llrintf(0.0f);
20897-
llrintl(0.0l);
2089820881
llround(0.0);
2089920882
llroundf(0.0f);
20900-
llroundl(0.0l);
2090120883
#endif
2090220884
log1p(0.0);
2090320885
log1pf(0.0f);
20904-
log1pl(0.0l);
2090520886
log2(0.0);
2090620887
log2f(0.0f);
20907-
log2l(0.0l);
2090820888
logb(0.0);
2090920889
logbf(0.0f);
20910-
logbl(0.0l);
2091120890
lrint(0.0);
2091220891
lrintf(0.0f);
20913-
lrintl(0.0l);
2091420892
lround(0.0);
2091520893
lroundf(0.0f);
20916-
lroundl(0.0l);
2091720894
nan("");
2091820895
nanf("");
20919-
nanl("");
2092020896
nearbyint(0.0);
2092120897
nearbyintf(0.0f);
20922-
nearbyintl(0.0l);
2092320898
nextafter(0.0, 0.0);
2092420899
nextafterf(0.0f, 0.0f);
20925-
nextafterl(0.0l, 0.0l);
20926-
nexttoward(0.0, 0.0);
20927-
nexttowardf(0.0f, 0.0f);
20928-
nexttowardl(0.0l, 0.0l);
2092920900
remainder(0.0, 0.0);
2093020901
remainderf(0.0f, 0.0f);
20931-
remainderl(0.0l, 0.0l);
2093220902
remquo(0.0, 0.0, 0);
2093320903
remquof(0.0f, 0.0f, 0);
20934-
remquol(0.0l, 0.0l, 0);
2093520904
rint(0.0);
2093620905
rintf(0.0f);
20937-
rintl(0.0l);
2093820906
round(0.0);
2093920907
roundf(0.0f);
20940-
roundl(0.0l);
2094120908
scalbln(0.0, 0l);
2094220909
scalblnf(0.0f, 0l);
20943-
scalblnl(0.0l, 0l);
2094420910
scalbn(0.0, 0);
2094520911
scalbnf(0.0f, 0);
20946-
scalbnl(0.0l, 0);
2094720912
tgamma(0.0);
2094820913
tgammaf(0.0f);
20949-
tgammal(0.0l);
2095020914
trunc(0.0);
2095120915
truncf(0.0f);
20952-
truncl(0.0l);
2095320916

2095420917
;
2095520918
return 0;
@@ -20969,6 +20932,78 @@ $as_echo "$glibcxx_cv_c99_math_tr1" >&6; }
2096920932

2097020933
$as_echo "#define _GLIBCXX_USE_C99_MATH_TR1 1" >>confdefs.h
2097120934

20935+
20936+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ISO C99 long double math functions in <math.h>" >&5
20937+
$as_echo_n "checking for ISO C99 long double math functions in <math.h>... " >&6; }
20938+
if ${glibcxx_cv_c99_math_long_double+:} false; then :
20939+
$as_echo_n "(cached) " >&6
20940+
else
20941+
20942+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
20943+
/* end confdefs.h. */
20944+
#include <math.h>
20945+
int
20946+
main ()
20947+
{
20948+
acoshl(0.0l);
20949+
asinhl(0.0l);
20950+
atanhl(0.0l);
20951+
cbrtl(0.0l);
20952+
copysignl(0.0l, 0.0l);
20953+
erfl(0.0l);
20954+
erfcl(0.0l);
20955+
exp2l(0.0l);
20956+
expm1l(0.0l);
20957+
fdiml(0.0l, 0.0l);
20958+
fmal(0.0l, 0.0l, 0.0l);
20959+
fmaxl(0.0l, 0.0l);
20960+
fminl(0.0l, 0.0l);
20961+
hypotl(0.0l, 0.0l);
20962+
ilogbl(0.0l);
20963+
lgammal(0.0l);
20964+
#ifndef __APPLE__ /* see below */
20965+
llrintl(0.0l);
20966+
llroundl(0.0l);
20967+
#endif
20968+
log1pl(0.0l);
20969+
log2l(0.0l);
20970+
logbl(0.0l);
20971+
lrintl(0.0l);
20972+
lroundl(0.0l);
20973+
nanl("");
20974+
nearbyintl(0.0l);
20975+
nextafterl(0.0l, 0.0l);
20976+
nexttoward(0.0, 0.0);
20977+
nexttowardf(0.0f, 0.0f);
20978+
nexttowardl(0.0l, 0.0l);
20979+
remainderl(0.0l, 0.0l);
20980+
remquol(0.0l, 0.0l, 0);
20981+
rintl(0.0l);
20982+
roundl(0.0l);
20983+
scalblnl(0.0l, 0l);
20984+
scalbnl(0.0l, 0);
20985+
tgammal(0.0l);
20986+
truncl(0.0l);
20987+
20988+
;
20989+
return 0;
20990+
}
20991+
_ACEOF
20992+
if ac_fn_cxx_try_compile "$LINENO"; then :
20993+
glibcxx_cv_c99_math_long_double=yes
20994+
else
20995+
glibcxx_cv_c99_math_long_double=no
20996+
fi
20997+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
20998+
20999+
fi
21000+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_c99_math_long_double" >&5
21001+
$as_echo "$glibcxx_cv_c99_math_long_double" >&6; }
21002+
if test x"$glibcxx_cv_c99_math_long_double" = x"yes"; then
21003+
21004+
$as_echo "#define _GLIBCXX_USE_C99_MATH_LONG_DOUBLE_FUNCS 1" >>confdefs.h
21005+
21006+
fi
2097221007
fi
2097321008

2097421009
# Check for the existence of <inttypes.h> functions (NB: doesn't make

0 commit comments

Comments
 (0)