@@ -12,38 +12,113 @@ namespace std {
1212using ::float_t ;
1313using ::double_t ;
1414
15- inline bool signbit (float __x) { return static_cast <bool >(_signbitf (__x)); }
16- inline bool signbit (double __x) { return static_cast <bool >(_signbitf (__x)); }
17- inline bool signbit (long double __x) { return static_cast <bool >(_signbitl (__x)); }
18- template <typename _Tp> inline
15+ inline constexpr bool signbit (float __x) {
16+ if (__builtin_constant_p (__x)) {
17+ return __builtin_signbitf (__x);
18+ }
19+ return static_cast <bool >(_signbitf (__x));
20+ }
21+ inline constexpr bool signbit (double __x) {
22+ if (__builtin_constant_p (__x)) {
23+ return __builtin_signbit (__x);
24+ }
25+ return static_cast <bool >(_signbitf (__x));
26+ }
27+ inline constexpr bool signbit (long double __x) {
28+ if (__builtin_constant_p (__x)) {
29+ return __builtin_signbitl (__x);
30+ }
31+ return static_cast <bool >(_signbitl (__x));
32+ }
33+ template <typename _Tp> inline constexpr
1934__cmath_enable_if_t <__cmath_is_integral_v<_Tp>, bool >
2035signbit (_Tp __x) { return signbit (__x); }
2136
22- inline bool isinf (float __x) { return static_cast <bool >(_isinff (__x)); }
23- inline bool isinf (double __x) { return static_cast <bool >(_isinff (__x)); }
24- inline bool isinf (long double __x) { return static_cast <bool >(_isinfl (__x)); }
25- template <typename _Tp> inline
37+ inline constexpr bool isinf (float __x) {
38+ if (__builtin_constant_p (__x)) {
39+ return __builtin_isinf (__x);
40+ }
41+ return static_cast <bool >(_isinff (__x));
42+ }
43+ inline constexpr bool isinf (double __x) {
44+ if (__builtin_constant_p (__x)) {
45+ return __builtin_isinf (__x);
46+ }
47+ return static_cast <bool >(_isinff (__x));
48+ }
49+ inline constexpr bool isinf (long double __x) {
50+ if (__builtin_constant_p (__x)) {
51+ return __builtin_isinf (__x);
52+ }
53+ return static_cast <bool >(_isinfl (__x));
54+ }
55+ template <typename _Tp> inline constexpr
2656__cmath_enable_if_t <__cmath_is_integral_v<_Tp>, bool >
2757isinf (_Tp __x) { return isinf (__x); }
2858
29- inline bool isnan (float __x) { return static_cast <bool >(_isnanf (__x)); }
30- inline bool isnan (double __x) { return static_cast <bool >(_isnanf (__x)); }
31- inline bool isnan (long double __x) { return static_cast <bool >(_isnanl (__x)); }
32- template <typename _Tp> inline
59+ inline constexpr bool isnan (float __x) {
60+ if (__builtin_constant_p (__x)) {
61+ return __builtin_isnan (__x);
62+ }
63+ return static_cast <bool >(_isnanf (__x));
64+ }
65+ inline constexpr bool isnan (double __x) {
66+ if (__builtin_constant_p (__x)) {
67+ return __builtin_isnan (__x);
68+ }
69+ return static_cast <bool >(_isnanf (__x));
70+ }
71+ inline constexpr bool isnan (long double __x) {
72+ if (__builtin_constant_p (__x)) {
73+ return __builtin_isnan (__x);
74+ }
75+ return static_cast <bool >(_isnanl (__x));
76+ }
77+ template <typename _Tp> inline constexpr
3378__cmath_enable_if_t <__cmath_is_integral_v<_Tp>, bool >
3479isnan (_Tp __x) { return isnan (__x); }
3580
36- inline bool isnormal (float __x) { return static_cast <bool >(_isnormalf (__x)); }
37- inline bool isnormal (double __x) { return static_cast <bool >(_isnormalf (__x)); }
38- inline bool isnormal (long double __x) { return static_cast <bool >(_isnormall (__x)); }
39- template <typename _Tp> inline
81+ inline constexpr bool isnormal (float __x) {
82+ if (__builtin_constant_p (__x)) {
83+ return __builtin_isnormal (__x);
84+ }
85+ return static_cast <bool >(_isnormalf (__x));
86+ }
87+ inline constexpr bool isnormal (double __x) {
88+ if (__builtin_constant_p (__x)) {
89+ return __builtin_isnormal (__x);
90+ }
91+ return static_cast <bool >(_isnormalf (__x));
92+ }
93+ inline constexpr bool isnormal (long double __x) {
94+ if (__builtin_constant_p (__x)) {
95+ return __builtin_isnormal (__x);
96+ }
97+ return static_cast <bool >(_isnormall (__x));
98+ }
99+ template <typename _Tp> inline constexpr
40100__cmath_enable_if_t <__cmath_is_integral_v<_Tp>, bool >
41101isnormal (_Tp __x) { return isnormal (__x); }
42102
43- inline bool isfinite (float __x) { return static_cast <bool >(_isfinitef (__x)); }
44- inline bool isfinite (double __x) { return static_cast <bool >(_isfinitef (__x)); }
45- inline bool isfinite (long double __x) { return static_cast <bool >(_isfinitel (__x)); }
46- template <typename _Tp> inline
103+ inline constexpr bool isfinite (float __x) {
104+ if (__builtin_constant_p (__x)) {
105+ return __builtin_isfinite (__x);
106+ }
107+ return static_cast <bool >(_isfinitef (__x));
108+ }
109+ inline constexpr bool isfinite (double __x) {
110+ if (__builtin_constant_p (__x)) {
111+ return __builtin_isfinite (__x);
112+ }
113+ return static_cast <bool >(_isfinitef (__x));
114+ }
115+ inline constexpr bool isfinite (long double __x) {
116+ if (__builtin_constant_p (__x)) {
117+ return __builtin_isfinite (__x);
118+ }
119+ return static_cast <bool >(_isfinitel (__x));
120+ }
121+ template <typename _Tp> inline constexpr
47122__cmath_enable_if_t <__cmath_is_integral_v<_Tp>, bool >
48123isfinite (_Tp __x) { return isfinite (__x); }
49124
@@ -61,10 +136,28 @@ template<typename _Tp> inline
61136__cmath_enable_if_t <__cmath_is_integral_v<_Tp>, bool >
62137issubnormal (_Tp __x) { return issubnormal (__x); }
63138
64- inline int fpclassify (float __x) { return _fpclassifyf (__x); }
65- inline int fpclassify (double __x) { return _fpclassifyf (__x); }
66- inline int fpclassify (long double __x) { return _fpclassifyl (__x); }
67- template <typename _Tp> inline
139+ inline constexpr int fpclassify (float __x) {
140+ if (__builtin_constant_p (__x)) {
141+ return __builtin_fpclassify (FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
142+ } else {
143+ return _fpclassifyf (__x);
144+ }
145+ }
146+ inline constexpr int fpclassify (double __x) {
147+ if (__builtin_constant_p (__x)) {
148+ return __builtin_fpclassify (FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
149+ } else {
150+ return _fpclassifyf (__x);
151+ }
152+ }
153+ inline constexpr int fpclassify (long double __x) {
154+ if (__builtin_constant_p (__x)) {
155+ return __builtin_fpclassify (FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
156+ } else {
157+ return _fpclassifyl (__x);
158+ }
159+ }
160+ template <typename _Tp> inline constexpr
68161__cmath_enable_if_t <__cmath_is_integral_v<_Tp>, int >
69162fpclassify (_Tp __x) { return fpclassify (__x); }
70163
0 commit comments