11constexpr float inf = std::numeric_limits<float>::infinity();
20 if (x == -std::numeric_limits<float>::infinity()) {
22 }
else if (x == std::numeric_limits<float>::infinity() || std::isnan(x)) {
28 x = std::max(-80.f, std::min(x, 80.f));
29 ipart = std::floor(x + 0.5);
32 x = 1.535336188319500e-4f;
33 x = x * fpart + 1.339887440266574e-3f;
34 x = x * fpart + 9.618437357674640e-3f;
35 x = x * fpart + 5.550332471162809e-2f;
36 x = x * fpart + 2.402264791363012e-1f;
37 x = x * fpart + 6.931472028550421e-1f;
38 x = x * fpart + 1.000000000000000f;
42 epart.
i = (int(ipart) + 127) << 23;
51 if (t > 0.927734375f) {
54 -1.72853470e-5f, t, 3.83197126e-4f);
56 -3.88396438e-3f, t, 2.42546219e-2f);
57 r = std::fma(r, s,
u);
58 r = std::fma(r, t, -1.06777877e-1f);
59 r = std::fma(r, t, -6.34846687e-1f);
60 r = std::fma(r, t, -1.28717512e-1f);
61 r = std::fma(r, t, -t);
63 r = 1.0f - std::exp(r);
64 r = std::copysign(r, a);
68 r = std::fma(r, s, 4.99119423e-3f);
69 r = std::fma(r, s, -2.67681349e-2f);
70 r = std::fma(r, s, 1.12819925e-1f);
71 r = std::fma(r, s, -3.76125336e-1f);
72 r = std::fma(r, s, 1.28379166e-1f);
73 r = std::fma(r, a, a);
79 auto t = std::fma(a, 0.0f - a, 1.0f);
82 if (std::abs(t) > 6.125f) {
84 p = std::fma(p, t, 2.93243101e-8f);
85 p = std::fma(p, t, 1.22150334e-6f);
86 p = std::fma(p, t, 2.84108955e-5f);
87 p = std::fma(p, t, 3.93552968e-4f);
88 p = std::fma(p, t, 3.02698812e-3f);
89 p = std::fma(p, t, 4.83185798e-3f);
90 p = std::fma(p, t, -2.64646143e-1f);
91 p = std::fma(p, t, 8.40016484e-1f);
94 p = std::fma(p, t, 1.43285448e-7f);
95 p = std::fma(p, t, 1.22774793e-6f);
96 p = std::fma(p, t, 1.12963626e-7f);
97 p = std::fma(p, t, -5.61530760e-5f);
98 p = std::fma(p, t, -1.47697632e-4f);
99 p = std::fma(p, t, 2.31468678e-3f);
100 p = std::fma(p, t, 1.15392581e-2f);
101 p = std::fma(p, t, -2.32015476e-1f);
102 p = std::fma(p, t, 8.86226892e-1f);
108 template <
typename T>
130 template <
typename T>
137 template <
typename T>
139 return std::acosh(x);
144 template <
typename T>
151 template <
typename T>
153 return std::asinh(x);
158 template <
typename T>
165 template <
typename T>
167 return std::atan2(y, x);
172 template <
typename T>
174 return std::atanh(x);
179 template <
typename T>
219 template <
typename T>
226 template <
typename T>
233 template <
typename T>
235 return static_cast<T
>(
fast_erf(
static_cast<float>(x)));
240 template <
typename T>
242 return static_cast<T
>(
fast_erfinv(
static_cast<float>(x)));
247 template <
typename T>
258 template <
typename T>
265 template <
typename T>
267 return std::floor(x);
299 template <
typename T>
306 template <
typename T>
313 template <
typename T>
315 return std::log10(x);
320 template <
typename T>
327 template <
typename T>
334 template <
typename T>
341 template <
typename T>
347 return {std::rint(x.real()), std::rint(x.imag())};
352 template <
typename T>
354 auto one =
static_cast<decltype(x)
>(1.0);
360 template <
typename T>
362 return (x > T(0)) - (x < T(0));
379 template <
typename T>
386 template <
typename T>
393 template <
typename T>
400 template <
typename T>
407 template <
typename T>
409 return static_cast<decltype(x)
>(1.0) / std::sqrt(x);
414 template <
typename T>
421 template <
typename T>
428 template <
typename T>
435 template <
typename T>
442 template <
typename T>
443 std::enable_if_t<std::is_integral_v<T> & !std::is_signed_v<T>, T>
operator()(
446 return numerator % denominator;
449 template <
typename T>
450 std::enable_if_t<std::is_integral_v<T> & std::is_signed_v<T>, T>
operator()(
453 auto r = numerator % denominator;
454 if (r != 0 && (r < 0 != denominator < 0))
459 template <
typename T>
463 auto r = std::fmod(numerator, denominator);
464 if (r != 0 && (r < 0 != denominator < 0)) {
471 return numerator % denominator;
476 template <
typename T>
483 template <
typename T>
485 return x == y || (std::isnan(x) && std::isnan(y));
490 template <
typename T>
497 template <
typename T>
504 template <
typename T>
511 template <
typename T>
518 template <
typename T>
519 std::enable_if_t<std::is_integral_v<T>, T>
operator()(T x, T y) {
520 return (x > y) ? x : y;
523 template <
typename T>
524 std::enable_if_t<!std::is_integral_v<T>, T>
operator()(T x, T y) {
528 return (x > y) ? x : y;
533 template <
typename T>
534 std::enable_if_t<std::is_integral_v<T>, T>
operator()(T x, T y) {
535 return x < y ? x : y;
538 template <
typename T>
539 std::enable_if_t<!std::is_integral_v<T>, T>
operator()(T x, T y) {
543 return x < y ? x : y;
548 template <
typename T>
550 constexpr float inf = std::numeric_limits<float>::infinity();
553 return (minval == -inf || maxval == inf)
555 :
static_cast<decltype(x)
>(
556 maxval + std::log1p(
fast_exp(minval - maxval)));
561 template <
typename T>
568 template <
typename T>
575 template <
typename T>
577 return std::pow(base,
exp);
580 template <
typename T>
595 template <
typename T>
602 template <
typename T>
609 template <
typename T>
616 template <
typename T>
618 return condition ? x : y;
623 template <
typename T>
630 template <
typename T>
637 template <
typename T>
644 template <
typename T>
651 template <
typename T>
array log1p(const array &a, StreamOrDevice s={})
Natural logarithm of one plus elements in the array: log(1 + a).
array expm1(const array &a, StreamOrDevice s={})
Computes the expm1 function of the elements of an array.
array exp(const array &a, StreamOrDevice s={})
Exponential of the elements of an array.
float fast_exp(float x)
Definition ops.h:19
float fast_erf(float a)
Definition ops.h:47
float fast_erfinv(float a)
Definition ops.h:78
T operator()(T x)
Definition ops.h:109
uint8_t operator()(uint8_t x)
Definition ops.h:112
uint64_t operator()(uint64_t x)
Definition ops.h:121
uint16_t operator()(uint16_t x)
Definition ops.h:115
bool operator()(bool x)
Definition ops.h:124
uint32_t operator()(uint32_t x)
Definition ops.h:118
T operator()(T x, T y)
Definition ops.h:429
T operator()(T x)
Definition ops.h:131
T operator()(T x)
Definition ops.h:138
T operator()(T x)
Definition ops.h:145
T operator()(T x)
Definition ops.h:152
T operator()(T y, T x)
Definition ops.h:166
T operator()(T x)
Definition ops.h:159
T operator()(T x)
Definition ops.h:173
T operator()(T x, T y)
Definition ops.h:624
T operator()(T x, T y)
Definition ops.h:631
T operator()(T x, T y)
Definition ops.h:638
uint8_t operator()(uint8_t x)
Definition ops.h:195
T operator()(T x)
Definition ops.h:180
uint32_t operator()(uint32_t x)
Definition ops.h:201
int8_t operator()(int8_t x)
Definition ops.h:183
int16_t operator()(int16_t x)
Definition ops.h:186
bool operator()(bool x)
Definition ops.h:207
uint16_t operator()(uint16_t x)
Definition ops.h:198
uint64_t operator()(uint64_t x)
Definition ops.h:204
int32_t operator()(int32_t x)
Definition ops.h:189
int64_t operator()(int64_t x)
Definition ops.h:192
complex64_t operator()(complex64_t x)
Definition ops.h:213
T operator()(T x)
Definition ops.h:220
T operator()(T x)
Definition ops.h:227
T operator()(T x, T y)
Definition ops.h:436
bool operator()(T x, T y)
Definition ops.h:477
T operator()(T x)
Definition ops.h:234
T operator()(T x)
Definition ops.h:241
T operator()(T x)
Definition ops.h:248
complex64_t operator()(complex64_t x)
Definition ops.h:252
T operator()(T x)
Definition ops.h:259
T operator()(T x)
Definition ops.h:266
uint32_t operator()(uint32_t x)
Definition ops.h:287
uint16_t operator()(uint16_t x)
Definition ops.h:284
uint8_t operator()(uint8_t x)
Definition ops.h:281
int32_t operator()(int32_t x)
Definition ops.h:275
int64_t operator()(int64_t x)
Definition ops.h:278
bool operator()(bool x)
Definition ops.h:293
int8_t operator()(int8_t x)
Definition ops.h:269
uint64_t operator()(uint64_t x)
Definition ops.h:290
int16_t operator()(int16_t x)
Definition ops.h:272
bool operator()(T x, T y)
Definition ops.h:498
bool operator()(T x, T y)
Definition ops.h:491
T operator()(T x, T y)
Definition ops.h:645
bool operator()(T x, T y)
Definition ops.h:512
bool operator()(T x, T y)
Definition ops.h:505
T operator()(T x)
Definition ops.h:314
T operator()(T x)
Definition ops.h:321
T operator()(T x)
Definition ops.h:307
T operator()(T x, T y)
Definition ops.h:549
T operator()(T x)
Definition ops.h:300
T operator()(T x, T y)
Definition ops.h:603
T operator()(T x)
Definition ops.h:328
T operator()(T x, T y)
Definition ops.h:610
std::enable_if_t< std::is_integral_v< T >, T > operator()(T x, T y)
Definition ops.h:519
std::enable_if_t<!std::is_integral_v< T >, T > operator()(T x, T y)
Definition ops.h:524
std::enable_if_t<!std::is_integral_v< T >, T > operator()(T x, T y)
Definition ops.h:539
std::enable_if_t< std::is_integral_v< T >, T > operator()(T x, T y)
Definition ops.h:534
T operator()(T x, T y)
Definition ops.h:562
bool operator()(T x, T y)
Definition ops.h:484
T operator()(T x)
Definition ops.h:335
bool operator()(T x, T y)
Definition ops.h:569
std::enable_if_t<!std::is_integral_v< T >, T > operator()(T base, T exp)
Definition ops.h:576
std::enable_if_t< std::is_integral_v< T >, T > operator()(T base, T exp)
Definition ops.h:581
std::enable_if_t<!std::is_integral_v< T >, T > operator()(T numerator, T denominator)
Definition ops.h:460
std::enable_if_t< std::is_integral_v< T > &!std::is_signed_v< T >, T > operator()(T numerator, T denominator)
Definition ops.h:443
std::enable_if_t< std::is_integral_v< T > &std::is_signed_v< T >, T > operator()(T numerator, T denominator)
Definition ops.h:450
complex64_t operator()(complex64_t numerator, complex64_t denominator)
Definition ops.h:470
T operator()(T x, T y)
Definition ops.h:652
T operator()(T x)
Definition ops.h:342
complex64_t operator()(complex64_t x)
Definition ops.h:346
T operator()(T x)
Definition ops.h:408
T operator()(bool condition, T x, T y)
Definition ops.h:617
T operator()(T x)
Definition ops.h:353
uint64_t operator()(uint64_t x)
Definition ops.h:373
T operator()(T x)
Definition ops.h:361
uint8_t operator()(uint8_t x)
Definition ops.h:364
uint16_t operator()(uint16_t x)
Definition ops.h:367
uint32_t operator()(uint32_t x)
Definition ops.h:370
T operator()(T x)
Definition ops.h:380
T operator()(T x)
Definition ops.h:387
T operator()(T x)
Definition ops.h:401
T operator()(T x)
Definition ops.h:394
T operator()(T x, T y)
Definition ops.h:596
T operator()(T x)
Definition ops.h:415
T operator()(T x)
Definition ops.h:422
uint32_t u
Definition bf16.h:17
float f
Definition ops.h:16