Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===---------------------------- cmath -----------------------------------===// |
| 3 | // |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_CMATH |
| 11 | #define _LIBCPP_CMATH |
| 12 | |
| 13 | /* |
| 14 | cmath synopsis |
| 15 | |
| 16 | Macros: |
| 17 | |
| 18 | HUGE_VAL |
| 19 | HUGE_VALF // C99 |
| 20 | HUGE_VALL // C99 |
| 21 | INFINITY // C99 |
| 22 | NAN // C99 |
| 23 | FP_INFINITE // C99 |
| 24 | FP_NAN // C99 |
| 25 | FP_NORMAL // C99 |
| 26 | FP_SUBNORMAL // C99 |
| 27 | FP_ZERO // C99 |
| 28 | FP_FAST_FMA // C99 |
| 29 | FP_FAST_FMAF // C99 |
| 30 | FP_FAST_FMAL // C99 |
| 31 | FP_ILOGB0 // C99 |
| 32 | FP_ILOGBNAN // C99 |
| 33 | MATH_ERRNO // C99 |
| 34 | MATH_ERREXCEPT // C99 |
| 35 | math_errhandling // C99 |
| 36 | |
| 37 | namespace std |
| 38 | { |
| 39 | |
| 40 | Types: |
| 41 | |
| 42 | float_t // C99 |
| 43 | double_t // C99 |
| 44 | |
| 45 | // C90 |
| 46 | |
| 47 | floating_point abs(floating_point x); |
| 48 | |
| 49 | floating_point acos (arithmetic x); |
| 50 | float acosf(float x); |
| 51 | long double acosl(long double x); |
| 52 | |
| 53 | floating_point asin (arithmetic x); |
| 54 | float asinf(float x); |
| 55 | long double asinl(long double x); |
| 56 | |
| 57 | floating_point atan (arithmetic x); |
| 58 | float atanf(float x); |
| 59 | long double atanl(long double x); |
| 60 | |
| 61 | floating_point atan2 (arithmetic y, arithmetic x); |
| 62 | float atan2f(float y, float x); |
| 63 | long double atan2l(long double y, long double x); |
| 64 | |
| 65 | floating_point ceil (arithmetic x); |
| 66 | float ceilf(float x); |
| 67 | long double ceill(long double x); |
| 68 | |
| 69 | floating_point cos (arithmetic x); |
| 70 | float cosf(float x); |
| 71 | long double cosl(long double x); |
| 72 | |
| 73 | floating_point cosh (arithmetic x); |
| 74 | float coshf(float x); |
| 75 | long double coshl(long double x); |
| 76 | |
| 77 | floating_point exp (arithmetic x); |
| 78 | float expf(float x); |
| 79 | long double expl(long double x); |
| 80 | |
| 81 | floating_point fabs (arithmetic x); |
| 82 | float fabsf(float x); |
| 83 | long double fabsl(long double x); |
| 84 | |
| 85 | floating_point floor (arithmetic x); |
| 86 | float floorf(float x); |
| 87 | long double floorl(long double x); |
| 88 | |
| 89 | floating_point fmod (arithmetic x, arithmetic y); |
| 90 | float fmodf(float x, float y); |
| 91 | long double fmodl(long double x, long double y); |
| 92 | |
| 93 | floating_point frexp (arithmetic value, int* exp); |
| 94 | float frexpf(float value, int* exp); |
| 95 | long double frexpl(long double value, int* exp); |
| 96 | |
| 97 | floating_point ldexp (arithmetic value, int exp); |
| 98 | float ldexpf(float value, int exp); |
| 99 | long double ldexpl(long double value, int exp); |
| 100 | |
| 101 | floating_point log (arithmetic x); |
| 102 | float logf(float x); |
| 103 | long double logl(long double x); |
| 104 | |
| 105 | floating_point log10 (arithmetic x); |
| 106 | float log10f(float x); |
| 107 | long double log10l(long double x); |
| 108 | |
| 109 | floating_point modf (floating_point value, floating_point* iptr); |
| 110 | float modff(float value, float* iptr); |
| 111 | long double modfl(long double value, long double* iptr); |
| 112 | |
| 113 | floating_point pow (arithmetic x, arithmetic y); |
| 114 | float powf(float x, float y); |
| 115 | long double powl(long double x, long double y); |
| 116 | |
| 117 | floating_point sin (arithmetic x); |
| 118 | float sinf(float x); |
| 119 | long double sinl(long double x); |
| 120 | |
| 121 | floating_point sinh (arithmetic x); |
| 122 | float sinhf(float x); |
| 123 | long double sinhl(long double x); |
| 124 | |
| 125 | floating_point sqrt (arithmetic x); |
| 126 | float sqrtf(float x); |
| 127 | long double sqrtl(long double x); |
| 128 | |
| 129 | floating_point tan (arithmetic x); |
| 130 | float tanf(float x); |
| 131 | long double tanl(long double x); |
| 132 | |
| 133 | floating_point tanh (arithmetic x); |
| 134 | float tanhf(float x); |
| 135 | long double tanhl(long double x); |
| 136 | |
| 137 | // C99 |
| 138 | |
Howard Hinnant | e95552c | 2013-01-14 20:56:22 +0000 | [diff] [blame] | 139 | bool signbit(arithmetic x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 140 | |
Howard Hinnant | e95552c | 2013-01-14 20:56:22 +0000 | [diff] [blame] | 141 | int fpclassify(arithmetic x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 142 | |
Howard Hinnant | e95552c | 2013-01-14 20:56:22 +0000 | [diff] [blame] | 143 | bool isfinite(arithmetic x); |
| 144 | bool isinf(arithmetic x); |
| 145 | bool isnan(arithmetic x); |
| 146 | bool isnormal(arithmetic x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 147 | |
Howard Hinnant | e95552c | 2013-01-14 20:56:22 +0000 | [diff] [blame] | 148 | bool isgreater(arithmetic x, arithmetic y); |
| 149 | bool isgreaterequal(arithmetic x, arithmetic y); |
| 150 | bool isless(arithmetic x, arithmetic y); |
| 151 | bool islessequal(arithmetic x, arithmetic y); |
| 152 | bool islessgreater(arithmetic x, arithmetic y); |
| 153 | bool isunordered(arithmetic x, arithmetic y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 154 | |
| 155 | floating_point acosh (arithmetic x); |
| 156 | float acoshf(float x); |
| 157 | long double acoshl(long double x); |
| 158 | |
| 159 | floating_point asinh (arithmetic x); |
| 160 | float asinhf(float x); |
| 161 | long double asinhl(long double x); |
| 162 | |
| 163 | floating_point atanh (arithmetic x); |
| 164 | float atanhf(float x); |
| 165 | long double atanhl(long double x); |
| 166 | |
| 167 | floating_point cbrt (arithmetic x); |
| 168 | float cbrtf(float x); |
| 169 | long double cbrtl(long double x); |
| 170 | |
| 171 | floating_point copysign (arithmetic x, arithmetic y); |
| 172 | float copysignf(float x, float y); |
| 173 | long double copysignl(long double x, long double y); |
| 174 | |
| 175 | floating_point erf (arithmetic x); |
| 176 | float erff(float x); |
| 177 | long double erfl(long double x); |
| 178 | |
| 179 | floating_point erfc (arithmetic x); |
| 180 | float erfcf(float x); |
| 181 | long double erfcl(long double x); |
| 182 | |
| 183 | floating_point exp2 (arithmetic x); |
| 184 | float exp2f(float x); |
| 185 | long double exp2l(long double x); |
| 186 | |
| 187 | floating_point expm1 (arithmetic x); |
| 188 | float expm1f(float x); |
| 189 | long double expm1l(long double x); |
| 190 | |
| 191 | floating_point fdim (arithmetic x, arithmetic y); |
| 192 | float fdimf(float x, float y); |
| 193 | long double fdiml(long double x, long double y); |
| 194 | |
| 195 | floating_point fma (arithmetic x, arithmetic y, arithmetic z); |
| 196 | float fmaf(float x, float y, float z); |
| 197 | long double fmal(long double x, long double y, long double z); |
| 198 | |
| 199 | floating_point fmax (arithmetic x, arithmetic y); |
| 200 | float fmaxf(float x, float y); |
| 201 | long double fmaxl(long double x, long double y); |
| 202 | |
| 203 | floating_point fmin (arithmetic x, arithmetic y); |
| 204 | float fminf(float x, float y); |
| 205 | long double fminl(long double x, long double y); |
| 206 | |
| 207 | floating_point hypot (arithmetic x, arithmetic y); |
| 208 | float hypotf(float x, float y); |
| 209 | long double hypotl(long double x, long double y); |
| 210 | |
Marshall Clow | e52b002 | 2016-05-17 14:52:19 +0000 | [diff] [blame] | 211 | double hypot(double x, double y, double z); // C++17 |
| 212 | float hypot(float x, float y, float z); // C++17 |
| 213 | long double hypot(long double x, long double y, long double z); // C++17 |
| 214 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 215 | int ilogb (arithmetic x); |
| 216 | int ilogbf(float x); |
| 217 | int ilogbl(long double x); |
| 218 | |
| 219 | floating_point lgamma (arithmetic x); |
| 220 | float lgammaf(float x); |
| 221 | long double lgammal(long double x); |
| 222 | |
| 223 | long long llrint (arithmetic x); |
| 224 | long long llrintf(float x); |
| 225 | long long llrintl(long double x); |
| 226 | |
| 227 | long long llround (arithmetic x); |
| 228 | long long llroundf(float x); |
| 229 | long long llroundl(long double x); |
| 230 | |
| 231 | floating_point log1p (arithmetic x); |
| 232 | float log1pf(float x); |
| 233 | long double log1pl(long double x); |
| 234 | |
| 235 | floating_point log2 (arithmetic x); |
| 236 | float log2f(float x); |
| 237 | long double log2l(long double x); |
| 238 | |
| 239 | floating_point logb (arithmetic x); |
| 240 | float logbf(float x); |
| 241 | long double logbl(long double x); |
| 242 | |
| 243 | long lrint (arithmetic x); |
| 244 | long lrintf(float x); |
| 245 | long lrintl(long double x); |
| 246 | |
| 247 | long lround (arithmetic x); |
| 248 | long lroundf(float x); |
| 249 | long lroundl(long double x); |
| 250 | |
| 251 | double nan (const char* str); |
| 252 | float nanf(const char* str); |
| 253 | long double nanl(const char* str); |
| 254 | |
| 255 | floating_point nearbyint (arithmetic x); |
| 256 | float nearbyintf(float x); |
| 257 | long double nearbyintl(long double x); |
| 258 | |
| 259 | floating_point nextafter (arithmetic x, arithmetic y); |
| 260 | float nextafterf(float x, float y); |
| 261 | long double nextafterl(long double x, long double y); |
| 262 | |
| 263 | floating_point nexttoward (arithmetic x, long double y); |
| 264 | float nexttowardf(float x, long double y); |
| 265 | long double nexttowardl(long double x, long double y); |
| 266 | |
| 267 | floating_point remainder (arithmetic x, arithmetic y); |
| 268 | float remainderf(float x, float y); |
| 269 | long double remainderl(long double x, long double y); |
| 270 | |
| 271 | floating_point remquo (arithmetic x, arithmetic y, int* pquo); |
| 272 | float remquof(float x, float y, int* pquo); |
| 273 | long double remquol(long double x, long double y, int* pquo); |
| 274 | |
| 275 | floating_point rint (arithmetic x); |
| 276 | float rintf(float x); |
| 277 | long double rintl(long double x); |
| 278 | |
| 279 | floating_point round (arithmetic x); |
| 280 | float roundf(float x); |
| 281 | long double roundl(long double x); |
| 282 | |
| 283 | floating_point scalbln (arithmetic x, long ex); |
| 284 | float scalblnf(float x, long ex); |
| 285 | long double scalblnl(long double x, long ex); |
| 286 | |
| 287 | floating_point scalbn (arithmetic x, int ex); |
| 288 | float scalbnf(float x, int ex); |
| 289 | long double scalbnl(long double x, int ex); |
| 290 | |
| 291 | floating_point tgamma (arithmetic x); |
| 292 | float tgammaf(float x); |
| 293 | long double tgammal(long double x); |
| 294 | |
| 295 | floating_point trunc (arithmetic x); |
| 296 | float truncf(float x); |
| 297 | long double truncl(long double x); |
| 298 | |
Marek Kurdej | d0eb416 | 2020-05-25 22:26:50 +0200 | [diff] [blame] | 299 | constexpr float lerp(float a, float b, float t) noexcept; // C++20 |
| 300 | constexpr double lerp(double a, double b, double t) noexcept; // C++20 |
| 301 | constexpr long double lerp(long double a, long double b, long double t) noexcept; // C++20 |
| 302 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 303 | } // std |
| 304 | |
| 305 | */ |
| 306 | |
| 307 | #include <__config> |
| 308 | #include <math.h> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 309 | #include <version> |
Louis Dionne | 4000a2a | 2019-09-04 13:35:03 +0000 | [diff] [blame] | 310 | #include <type_traits> |
Howard Hinnant | 69d8070 | 2011-10-27 16:24:42 +0000 | [diff] [blame] | 311 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 312 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 313 | #pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 314 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 315 | |
Louis Dionne | 4000a2a | 2019-09-04 13:35:03 +0000 | [diff] [blame] | 316 | _LIBCPP_PUSH_MACROS |
| 317 | #include <__undef_macros> |
| 318 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 319 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 320 | |
Howard Hinnant | c8827ba | 2011-05-13 21:52:40 +0000 | [diff] [blame] | 321 | using ::signbit; |
| 322 | using ::fpclassify; |
| 323 | using ::isfinite; |
| 324 | using ::isinf; |
| 325 | using ::isnan; |
| 326 | using ::isnormal; |
| 327 | using ::isgreater; |
| 328 | using ::isgreaterequal; |
| 329 | using ::isless; |
| 330 | using ::islessequal; |
| 331 | using ::islessgreater; |
| 332 | using ::isunordered; |
| 333 | using ::isunordered; |
| 334 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 335 | using ::float_t; |
| 336 | using ::double_t; |
| 337 | |
Eric Fiselier | eaad27b | 2015-03-18 15:24:18 +0000 | [diff] [blame] | 338 | using ::abs; |
Eric Fiselier | eaad27b | 2015-03-18 15:24:18 +0000 | [diff] [blame] | 339 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 340 | using ::acos; |
| 341 | using ::acosf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 342 | using ::asin; |
| 343 | using ::asinf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 344 | using ::atan; |
| 345 | using ::atanf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 346 | using ::atan2; |
| 347 | using ::atan2f; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 348 | using ::ceil; |
| 349 | using ::ceilf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 350 | using ::cos; |
| 351 | using ::cosf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 352 | using ::cosh; |
| 353 | using ::coshf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 354 | |
| 355 | using ::exp; |
| 356 | using ::expf; |
| 357 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 358 | using ::fabs; |
| 359 | using ::fabsf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 360 | using ::floor; |
| 361 | using ::floorf; |
Richard Smith | 081bb59 | 2015-10-08 20:40:34 +0000 | [diff] [blame] | 362 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 363 | using ::fmod; |
| 364 | using ::fmodf; |
Richard Smith | 081bb59 | 2015-10-08 20:40:34 +0000 | [diff] [blame] | 365 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 366 | using ::frexp; |
| 367 | using ::frexpf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 368 | using ::ldexp; |
| 369 | using ::ldexpf; |
Richard Smith | 081bb59 | 2015-10-08 20:40:34 +0000 | [diff] [blame] | 370 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 371 | using ::log; |
| 372 | using ::logf; |
Richard Smith | 081bb59 | 2015-10-08 20:40:34 +0000 | [diff] [blame] | 373 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 374 | using ::log10; |
| 375 | using ::log10f; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 376 | using ::modf; |
| 377 | using ::modff; |
Richard Smith | 081bb59 | 2015-10-08 20:40:34 +0000 | [diff] [blame] | 378 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 379 | using ::pow; |
| 380 | using ::powf; |
| 381 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 382 | using ::sin; |
| 383 | using ::sinf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 384 | using ::sinh; |
| 385 | using ::sinhf; |
Richard Smith | 081bb59 | 2015-10-08 20:40:34 +0000 | [diff] [blame] | 386 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 387 | using ::sqrt; |
| 388 | using ::sqrtf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 389 | using ::tan; |
| 390 | using ::tanf; |
Richard Smith | 081bb59 | 2015-10-08 20:40:34 +0000 | [diff] [blame] | 391 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 392 | using ::tanh; |
| 393 | using ::tanhf; |
| 394 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 395 | using ::acosh; |
| 396 | using ::acoshf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 397 | using ::asinh; |
| 398 | using ::asinhf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 399 | using ::atanh; |
| 400 | using ::atanhf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 401 | using ::cbrt; |
| 402 | using ::cbrtf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 403 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 404 | using ::copysign; |
| 405 | using ::copysignf; |
| 406 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 407 | using ::erf; |
| 408 | using ::erff; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 409 | using ::erfc; |
| 410 | using ::erfcf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 411 | using ::exp2; |
| 412 | using ::exp2f; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 413 | using ::expm1; |
| 414 | using ::expm1f; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 415 | using ::fdim; |
| 416 | using ::fdimf; |
Marshall Clow | 48313ff | 2014-03-05 17:09:51 +0000 | [diff] [blame] | 417 | using ::fmaf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 418 | using ::fma; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 419 | using ::fmax; |
| 420 | using ::fmaxf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 421 | using ::fmin; |
| 422 | using ::fminf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 423 | using ::hypot; |
| 424 | using ::hypotf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 425 | using ::ilogb; |
| 426 | using ::ilogbf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 427 | using ::lgamma; |
| 428 | using ::lgammaf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 429 | using ::llrint; |
| 430 | using ::llrintf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 431 | using ::llround; |
| 432 | using ::llroundf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 433 | using ::log1p; |
| 434 | using ::log1pf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 435 | using ::log2; |
| 436 | using ::log2f; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 437 | using ::logb; |
| 438 | using ::logbf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 439 | using ::lrint; |
| 440 | using ::lrintf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 441 | using ::lround; |
| 442 | using ::lroundf; |
Howard Hinnant | 13d8bc1 | 2013-08-01 18:17:34 +0000 | [diff] [blame] | 443 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 444 | using ::nan; |
| 445 | using ::nanf; |
Howard Hinnant | 13d8bc1 | 2013-08-01 18:17:34 +0000 | [diff] [blame] | 446 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 447 | using ::nearbyint; |
| 448 | using ::nearbyintf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 449 | using ::nextafter; |
| 450 | using ::nextafterf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 451 | using ::nexttoward; |
| 452 | using ::nexttowardf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 453 | using ::remainder; |
| 454 | using ::remainderf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 455 | using ::remquo; |
| 456 | using ::remquof; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 457 | using ::rint; |
| 458 | using ::rintf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 459 | using ::round; |
| 460 | using ::roundf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 461 | using ::scalbln; |
| 462 | using ::scalblnf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 463 | using ::scalbn; |
| 464 | using ::scalbnf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 465 | using ::tgamma; |
| 466 | using ::tgammaf; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 467 | using ::trunc; |
| 468 | using ::truncf; |
Howard Hinnant | 69d8070 | 2011-10-27 16:24:42 +0000 | [diff] [blame] | 469 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 470 | using ::acosl; |
| 471 | using ::asinl; |
| 472 | using ::atanl; |
| 473 | using ::atan2l; |
| 474 | using ::ceill; |
| 475 | using ::cosl; |
| 476 | using ::coshl; |
| 477 | using ::expl; |
| 478 | using ::fabsl; |
| 479 | using ::floorl; |
| 480 | using ::fmodl; |
| 481 | using ::frexpl; |
| 482 | using ::ldexpl; |
| 483 | using ::logl; |
| 484 | using ::log10l; |
| 485 | using ::modfl; |
| 486 | using ::powl; |
| 487 | using ::sinl; |
| 488 | using ::sinhl; |
| 489 | using ::sqrtl; |
| 490 | using ::tanl; |
Richard Smith | 081bb59 | 2015-10-08 20:40:34 +0000 | [diff] [blame] | 491 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 492 | using ::tanhl; |
| 493 | using ::acoshl; |
| 494 | using ::asinhl; |
| 495 | using ::atanhl; |
| 496 | using ::cbrtl; |
Richard Smith | 081bb59 | 2015-10-08 20:40:34 +0000 | [diff] [blame] | 497 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 498 | using ::copysignl; |
Richard Smith | 081bb59 | 2015-10-08 20:40:34 +0000 | [diff] [blame] | 499 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 500 | using ::erfl; |
| 501 | using ::erfcl; |
| 502 | using ::exp2l; |
| 503 | using ::expm1l; |
| 504 | using ::fdiml; |
| 505 | using ::fmal; |
| 506 | using ::fmaxl; |
| 507 | using ::fminl; |
| 508 | using ::hypotl; |
| 509 | using ::ilogbl; |
| 510 | using ::lgammal; |
| 511 | using ::llrintl; |
| 512 | using ::llroundl; |
| 513 | using ::log1pl; |
| 514 | using ::log2l; |
| 515 | using ::logbl; |
| 516 | using ::lrintl; |
| 517 | using ::lroundl; |
| 518 | using ::nanl; |
| 519 | using ::nearbyintl; |
| 520 | using ::nextafterl; |
| 521 | using ::nexttowardl; |
| 522 | using ::remainderl; |
| 523 | using ::remquol; |
| 524 | using ::rintl; |
| 525 | using ::roundl; |
| 526 | using ::scalblnl; |
| 527 | using ::scalbnl; |
| 528 | using ::tgammal; |
| 529 | using ::truncl; |
| 530 | |
Marshall Clow | e52b002 | 2016-05-17 14:52:19 +0000 | [diff] [blame] | 531 | #if _LIBCPP_STD_VER > 14 |
| 532 | inline _LIBCPP_INLINE_VISIBILITY float hypot( float x, float y, float z ) { return sqrt(x*x + y*y + z*z); } |
| 533 | inline _LIBCPP_INLINE_VISIBILITY double hypot( double x, double y, double z ) { return sqrt(x*x + y*y + z*z); } |
| 534 | inline _LIBCPP_INLINE_VISIBILITY long double hypot( long double x, long double y, long double z ) { return sqrt(x*x + y*y + z*z); } |
| 535 | |
| 536 | template <class _A1, class _A2, class _A3> |
| 537 | inline _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 3906a13 | 2019-06-23 20:28:29 +0000 | [diff] [blame] | 538 | typename _EnableIf |
Marshall Clow | e52b002 | 2016-05-17 14:52:19 +0000 | [diff] [blame] | 539 | < |
Hal Finkel | ba7fef3 | 2016-10-01 20:38:44 +0000 | [diff] [blame] | 540 | is_arithmetic<_A1>::value && |
| 541 | is_arithmetic<_A2>::value && |
| 542 | is_arithmetic<_A3>::value, |
| 543 | __promote<_A1, _A2, _A3> |
Marshall Clow | e52b002 | 2016-05-17 14:52:19 +0000 | [diff] [blame] | 544 | >::type |
| 545 | hypot(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT |
| 546 | { |
Hal Finkel | ba7fef3 | 2016-10-01 20:38:44 +0000 | [diff] [blame] | 547 | typedef typename __promote<_A1, _A2, _A3>::type __result_type; |
| 548 | static_assert((!(is_same<_A1, __result_type>::value && |
| 549 | is_same<_A2, __result_type>::value && |
| 550 | is_same<_A3, __result_type>::value)), ""); |
Marshall Clow | e52b002 | 2016-05-17 14:52:19 +0000 | [diff] [blame] | 551 | return hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z); |
| 552 | } |
| 553 | #endif |
| 554 | |
Hal Finkel | 5d74120 | 2016-10-01 20:38:31 +0000 | [diff] [blame] | 555 | template <class _A1> |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 556 | _LIBCPP_INLINE_VISIBILITY |
Justin Lebar | 24c1a07 | 2016-11-15 19:15:57 +0000 | [diff] [blame] | 557 | _LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type |
Duncan P. N. Exon Smith | 4a29720 | 2017-07-07 05:13:36 +0000 | [diff] [blame] | 558 | __libcpp_isnan_or_builtin(_A1 __lcpp_x) _NOEXCEPT |
Hal Finkel | 5d74120 | 2016-10-01 20:38:31 +0000 | [diff] [blame] | 559 | { |
| 560 | #if __has_builtin(__builtin_isnan) |
| 561 | return __builtin_isnan(__lcpp_x); |
| 562 | #else |
| 563 | return isnan(__lcpp_x); |
| 564 | #endif |
| 565 | } |
| 566 | |
| 567 | template <class _A1> |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 568 | _LIBCPP_INLINE_VISIBILITY |
Justin Lebar | 24c1a07 | 2016-11-15 19:15:57 +0000 | [diff] [blame] | 569 | _LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type |
Duncan P. N. Exon Smith | 4a29720 | 2017-07-07 05:13:36 +0000 | [diff] [blame] | 570 | __libcpp_isnan_or_builtin(_A1 __lcpp_x) _NOEXCEPT |
Hal Finkel | 5d74120 | 2016-10-01 20:38:31 +0000 | [diff] [blame] | 571 | { |
| 572 | return isnan(__lcpp_x); |
| 573 | } |
| 574 | |
| 575 | template <class _A1> |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 576 | _LIBCPP_INLINE_VISIBILITY |
Justin Lebar | 24c1a07 | 2016-11-15 19:15:57 +0000 | [diff] [blame] | 577 | _LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type |
Duncan P. N. Exon Smith | 4a29720 | 2017-07-07 05:13:36 +0000 | [diff] [blame] | 578 | __libcpp_isinf_or_builtin(_A1 __lcpp_x) _NOEXCEPT |
Hal Finkel | 5d74120 | 2016-10-01 20:38:31 +0000 | [diff] [blame] | 579 | { |
| 580 | #if __has_builtin(__builtin_isinf) |
| 581 | return __builtin_isinf(__lcpp_x); |
| 582 | #else |
| 583 | return isinf(__lcpp_x); |
| 584 | #endif |
| 585 | } |
| 586 | |
| 587 | template <class _A1> |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 588 | _LIBCPP_INLINE_VISIBILITY |
Justin Lebar | 24c1a07 | 2016-11-15 19:15:57 +0000 | [diff] [blame] | 589 | _LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type |
Duncan P. N. Exon Smith | 4a29720 | 2017-07-07 05:13:36 +0000 | [diff] [blame] | 590 | __libcpp_isinf_or_builtin(_A1 __lcpp_x) _NOEXCEPT |
Hal Finkel | 5d74120 | 2016-10-01 20:38:31 +0000 | [diff] [blame] | 591 | { |
| 592 | return isinf(__lcpp_x); |
| 593 | } |
| 594 | |
| 595 | template <class _A1> |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 596 | _LIBCPP_INLINE_VISIBILITY |
Justin Lebar | 24c1a07 | 2016-11-15 19:15:57 +0000 | [diff] [blame] | 597 | _LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type |
Duncan P. N. Exon Smith | 4a29720 | 2017-07-07 05:13:36 +0000 | [diff] [blame] | 598 | __libcpp_isfinite_or_builtin(_A1 __lcpp_x) _NOEXCEPT |
Hal Finkel | 5d74120 | 2016-10-01 20:38:31 +0000 | [diff] [blame] | 599 | { |
| 600 | #if __has_builtin(__builtin_isfinite) |
| 601 | return __builtin_isfinite(__lcpp_x); |
| 602 | #else |
| 603 | return isfinite(__lcpp_x); |
| 604 | #endif |
| 605 | } |
| 606 | |
| 607 | template <class _A1> |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 608 | _LIBCPP_INLINE_VISIBILITY |
Justin Lebar | 24c1a07 | 2016-11-15 19:15:57 +0000 | [diff] [blame] | 609 | _LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type |
Duncan P. N. Exon Smith | 4a29720 | 2017-07-07 05:13:36 +0000 | [diff] [blame] | 610 | __libcpp_isfinite_or_builtin(_A1 __lcpp_x) _NOEXCEPT |
Hal Finkel | 5d74120 | 2016-10-01 20:38:31 +0000 | [diff] [blame] | 611 | { |
| 612 | return isfinite(__lcpp_x); |
| 613 | } |
| 614 | |
Marshall Clow | f5860ad | 2019-04-25 17:44:18 +0000 | [diff] [blame] | 615 | #if _LIBCPP_STD_VER > 17 |
| 616 | template <typename _Fp> |
| 617 | constexpr |
| 618 | _Fp __lerp(_Fp __a, _Fp __b, _Fp __t) noexcept { |
| 619 | if ((__a <= 0 && __b >= 0) || (__a >= 0 && __b <= 0)) |
| 620 | return __t * __b + (1 - __t) * __a; |
| 621 | |
| 622 | if (__t == 1) return __b; |
| 623 | const _Fp __x = __a + __t * (__b - __a); |
| 624 | if (__t > 1 == __b > __a) |
| 625 | return __b < __x ? __x : __b; |
| 626 | else |
| 627 | return __x < __b ? __x : __b; |
| 628 | } |
| 629 | |
| 630 | constexpr float |
| 631 | lerp(float __a, float __b, float __t) _NOEXCEPT { return __lerp(__a, __b, __t); } |
| 632 | |
| 633 | constexpr double |
| 634 | lerp(double __a, double __b, double __t) _NOEXCEPT { return __lerp(__a, __b, __t); } |
| 635 | |
| 636 | constexpr long double |
| 637 | lerp(long double __a, long double __b, long double __t) _NOEXCEPT { return __lerp(__a, __b, __t); } |
| 638 | |
| 639 | #endif // _LIBCPP_STD_VER > 17 |
| 640 | |
Louis Dionne | 4000a2a | 2019-09-04 13:35:03 +0000 | [diff] [blame] | 641 | template <class _IntT, class _FloatT, |
| 642 | bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits), |
| 643 | int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)> |
| 644 | _LIBCPP_INLINE_VISIBILITY |
| 645 | _LIBCPP_CONSTEXPR _IntT __max_representable_int_for_float() _NOEXCEPT { |
| 646 | static_assert(is_floating_point<_FloatT>::value, "must be a floating point type"); |
| 647 | static_assert(is_integral<_IntT>::value, "must be an integral type"); |
| 648 | static_assert(numeric_limits<_FloatT>::radix == 2, "FloatT has incorrect radix"); |
Louis Dionne | ac4b2c4 | 2019-10-01 12:12:21 +0000 | [diff] [blame] | 649 | static_assert((_IsSame<_FloatT, float>::value || _IsSame<_FloatT, double>::value |
| 650 | || _IsSame<_FloatT,long double>::value), "unsupported floating point type"); |
Louis Dionne | 4000a2a | 2019-09-04 13:35:03 +0000 | [diff] [blame] | 651 | return _FloatBigger ? numeric_limits<_IntT>::max() : (numeric_limits<_IntT>::max() >> _Bits << _Bits); |
| 652 | } |
| 653 | |
| 654 | // Convert a floating point number to the specified integral type after |
| 655 | // clamping to the integral types representable range. |
| 656 | // |
| 657 | // The behavior is undefined if `__r` is NaN. |
| 658 | template <class _IntT, class _RealT> |
| 659 | _LIBCPP_INLINE_VISIBILITY |
| 660 | _IntT __clamp_to_integral(_RealT __r) _NOEXCEPT { |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 661 | using _Lim = numeric_limits<_IntT>; |
| 662 | const _IntT _MaxVal = __max_representable_int_for_float<_IntT, _RealT>(); |
Louis Dionne | 4000a2a | 2019-09-04 13:35:03 +0000 | [diff] [blame] | 663 | if (__r >= ::nextafter(static_cast<_RealT>(_MaxVal), INFINITY)) { |
| 664 | return _Lim::max(); |
| 665 | } else if (__r <= _Lim::lowest()) { |
| 666 | return _Lim::min(); |
| 667 | } |
| 668 | return static_cast<_IntT>(__r); |
| 669 | } |
| 670 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 671 | _LIBCPP_END_NAMESPACE_STD |
| 672 | |
Louis Dionne | 4000a2a | 2019-09-04 13:35:03 +0000 | [diff] [blame] | 673 | _LIBCPP_POP_MACROS |
| 674 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 675 | #endif // _LIBCPP_CMATH |