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>
320 template <
typename T>
322 return std::log10(x);
327 template <
typename T>
334 template <
typename T>
341 template <
typename T>
348 template <
typename T>
355 template <
typename T>
361 return {std::rint(x.real()), std::rint(x.imag())};
366 template <
typename T>
368 auto one =
static_cast<decltype(x)
>(1.0);
374 template <
typename T>
376 return (x > T(0)) - (x < T(0));
397 template <
typename T>
404 template <
typename T>
411 template <
typename T>
418 template <
typename T>
425 template <
typename T>
427 return static_cast<decltype(x)
>(1.0) / std::sqrt(x);
432 template <
typename T>
439 template <
typename T>
446 template <
typename T>
453 template <
typename T>
460 template <
typename T>
461 std::enable_if_t<std::is_integral_v<T> & !std::is_signed_v<T>, T>
operator()(
464 return numerator % denominator;
467 template <
typename T>
468 std::enable_if_t<std::is_integral_v<T> & std::is_signed_v<T>, T>
operator()(
471 auto r = numerator % denominator;
472 if (r != 0 && (r < 0 != denominator < 0))
477 template <
typename T>
481 auto r = std::fmod(numerator, denominator);
482 if (r != 0 && (r < 0 != denominator < 0)) {
489 return numerator % denominator;
494 template <
typename T>
501 template <
typename T>
503 return x == y || (std::isnan(x) && std::isnan(y));
508 template <
typename T>
515 template <
typename T>
522 template <
typename T>
529 template <
typename T>
536 template <
typename T>
537 std::enable_if_t<std::is_integral_v<T>, T>
operator()(T x, T y) {
538 return (x > y) ? x : y;
541 template <
typename T>
542 std::enable_if_t<!std::is_integral_v<T>, T>
operator()(T x, T y) {
546 return (x > y) ? x : y;
551 template <
typename T>
552 std::enable_if_t<std::is_integral_v<T>, T>
operator()(T x, T y) {
553 return x < y ? x : y;
556 template <
typename T>
557 std::enable_if_t<!std::is_integral_v<T>, T>
operator()(T x, T y) {
561 return x < y ? x : y;
566 template <
typename T>
568 constexpr float inf = std::numeric_limits<float>::infinity();
571 return (minval == -inf || maxval == inf)
573 :
static_cast<decltype(x)
>(
574 maxval + std::log1p(
fast_exp(minval - maxval)));
579 template <
typename T>
586 template <
typename T>
593 template <
typename T>
595 return std::pow(base,
exp);
598 template <
typename T>
613 template <
typename T>
620 template <
typename T>
627 template <
typename T>
634 template <
typename T>
636 return condition ? x : y;
641 template <
typename T>
648 template <
typename T>
655 template <
typename T>
662 template <
typename T>
669 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:447
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:642
T operator()(T x, T y)
Definition ops.h:649
T operator()(T x, T y)
Definition ops.h:656
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:454
bool operator()(T x, T y)
Definition ops.h:495
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:516
bool operator()(T x, T y)
Definition ops.h:509
T operator()(T x)
Definition ops.h:300
T operator()(T x, T y)
Definition ops.h:663
bool operator()(T x, T y)
Definition ops.h:530
bool operator()(T x, T y)
Definition ops.h:523
T operator()(T x)
Definition ops.h:321
T operator()(T x)
Definition ops.h:328
T operator()(T x)
Definition ops.h:314
T operator()(T x, T y)
Definition ops.h:567
T operator()(T x)
Definition ops.h:307
T operator()(T x, T y)
Definition ops.h:621
T operator()(T x)
Definition ops.h:335
T operator()(T x, T y)
Definition ops.h:628
std::enable_if_t< std::is_integral_v< T >, T > operator()(T x, T y)
Definition ops.h:537
std::enable_if_t<!std::is_integral_v< T >, T > operator()(T x, T y)
Definition ops.h:542
std::enable_if_t<!std::is_integral_v< T >, T > operator()(T x, T y)
Definition ops.h:557
std::enable_if_t< std::is_integral_v< T >, T > operator()(T x, T y)
Definition ops.h:552
T operator()(T x, T y)
Definition ops.h:580
bool operator()(T x, T y)
Definition ops.h:502
T operator()(T x)
Definition ops.h:342
bool operator()(T x, T y)
Definition ops.h:587
std::enable_if_t<!std::is_integral_v< T >, T > operator()(T base, T exp)
Definition ops.h:594
std::enable_if_t< std::is_integral_v< T >, T > operator()(T base, T exp)
Definition ops.h:599
T operator()(T x)
Definition ops.h:349
std::enable_if_t<!std::is_integral_v< T >, T > operator()(T numerator, T denominator)
Definition ops.h:478
std::enable_if_t< std::is_integral_v< T > &!std::is_signed_v< T >, T > operator()(T numerator, T denominator)
Definition ops.h:461
std::enable_if_t< std::is_integral_v< T > &std::is_signed_v< T >, T > operator()(T numerator, T denominator)
Definition ops.h:468
complex64_t operator()(complex64_t numerator, complex64_t denominator)
Definition ops.h:488
T operator()(T x, T y)
Definition ops.h:670
T operator()(T x)
Definition ops.h:356
complex64_t operator()(complex64_t x)
Definition ops.h:360
T operator()(T x)
Definition ops.h:426
T operator()(bool condition, T x, T y)
Definition ops.h:635
T operator()(T x)
Definition ops.h:367
uint64_t operator()(uint64_t x)
Definition ops.h:387
T operator()(T x)
Definition ops.h:375
uint8_t operator()(uint8_t x)
Definition ops.h:378
uint16_t operator()(uint16_t x)
Definition ops.h:381
complex64_t operator()(complex64_t x)
Definition ops.h:391
uint32_t operator()(uint32_t x)
Definition ops.h:384
T operator()(T x)
Definition ops.h:398
T operator()(T x)
Definition ops.h:405
T operator()(T x)
Definition ops.h:419
T operator()(T x)
Definition ops.h:412
T operator()(T x, T y)
Definition ops.h:614
T operator()(T x)
Definition ops.h:433
T operator()(T x)
Definition ops.h:440
uint32_t u
Definition bf16.h:17
float f
Definition ops.h:16