8namespace uni20::detail::native_math::airy_detail
12template <NativeReal R>
class Expansion {
13 static constexpr int words_ = 4;
14 std::array<R, 2 * words_ * words_ + 2> terms_{};
19 for (
int i = 0; i < size_; ++i)
21 R s = v + terms_[i],
p = s - v, e = (v - (s -
p)) + (terms_[i] -
p);
22 if (e != 0) terms_[n++] = e;
25 if (v != 0 || n == 0) terms_[n++] = v;
30 R carry = this->high();
32 for (
int i = size_ - 2; i >= 0; --i)
34 R s = carry + terms_[i], e = terms_[i] - (s - carry);
44 for (
int i = bottom; i < size_; ++i)
46 R s = terms_[i] + carry, e = carry - (s - terms_[i]);
47 if (e != 0) terms_[n++] = e;
54 std::copy(terms_.begin() + size_ - words_, terms_.begin() + size_, terms_.begin());
60 Expansion(R x = 0) { this->
add(x); }
61 R high()
const {
return terms_[size_ - 1]; }
62 Expansion scaled(
int n)
const
65 for (
int k = 0; k < size_; ++k)
66 r.terms_[k] = std::ldexp(r.terms_[k], n);
72 for (
int i = 0; i < size_; ++i)
76 friend Expansion
operator+(Expansion a, Expansion
const& b)
78 for (
int i = 0; i < b.size_; ++i)
85 for (
int i = 0; i < a.size_; ++i)
86 a.terms_[i] = -a.terms_[i];
89 friend Expansion
operator-(Expansion a, Expansion
const& b) {
return a + -b; }
90 friend Expansion
operator*(Expansion
const& a, Expansion
const& b)
93 for (
int i = 0; i < a.size_; ++i)
94 for (
int j = 0; j < b.size_; ++j)
96 R
p = a.terms_[i] * b.terms_[j];
97 r.add(std::fma(a.terms_[i], b.terms_[j], -
p));
103 friend Expansion
operator/(Expansion a, Expansion
const& b)
106 for (
int i = 0; i < words_; ++i)
108 R next = a.high() / b.high();
115 friend Expansion
operator/(Expansion a, R b)
118 for (
int i = 0; i < words_; ++i)
120 R next = a.high() / b;
123 a = a - v * Expansion(b);
auto operator-(Async< T > const &x)
Unary negation overload for Async values.
Definition async_ops.hpp:477
Var< T > operator*(T x, Var< T > y)
Computes x * y with reverse-mode gradient propagation.
Definition var_toys.hpp:176
Var< T > operator+(Var< T > x, T y)
Computes x + y with reverse-mode gradient propagation.
Definition var_toys.hpp:136
Definition data_table.cpp:8
int add(int a, int b)
Definition dummy.cpp:6
constexpr auto operator/(basic_half_int< T > lhs, U rhs) -> U
Divide a half-integer value by a floating-point scalar.
Definition half_int.hpp:422