63#pragma warning(disable : 26472)
64#pragma warning(disable : 26485)
65#pragma warning(disable : 26481)
66#pragma warning(disable : 26446)
67#pragma warning(disable : 26482)
68#pragma warning(disable : 26408)
71#ifndef FP128_FIXED_POINT128_T_H
72#define FP128_FIXED_POINT128_T_H
160[[nodiscard]]
inline bool Divide256By128(uint64_t* q, uint64_t* r,
const uint64_t* u,
const uint64_t* v)
noexcept
173 {0x1000000000000000ull, 0x0000000000000000ull},
174 {0x0555555555555555ull, 0x5555555555555555ull},
175 {0x02AAAAAAAAAAAAAAull, 0xAAAAAAAAAAAAAAABull},
176 {0x0199999999999999ull, 0x999999999999999Aull},
177 {0x0111111111111111ull, 0x1111111111111111ull},
178 {0x00C30C30C30C30C3ull, 0x0C30C30C30C30C31ull},
179 {0x0092492492492492ull, 0x4924924924924925ull},
180 {0x0071C71C71C71C71ull, 0xC71C71C71C71C71Cull},
181 {0x005B05B05B05B05Bull, 0x05B05B05B05B05B0ull},
182 {0x004A7904A7904A79ull, 0x04A7904A7904A790ull},
183 {0x003E0F83E0F83E0Full, 0x83E0F83E0F83E0F8ull},
184 {0x0034834834834834ull, 0x8348348348348348ull},
185 {0x002D02D02D02D02Dull, 0x02D02D02D02D02D0ull},
186 {0x0027027027027027ull, 0x0270270270270270ull},
187 {0x0022222222222222ull, 0x2222222222222222ull},
188 {0x001E1E1E1E1E1E1Eull, 0x1E1E1E1E1E1E1E1Eull},
189 {0x001AC5701AC5701Aull, 0xC5701AC5701AC570ull},
190 {0x0017F405FD017F40ull, 0x5FD017F405FD017Full},
191 {0x00158ED2308158EDull, 0x2308158ED2308159ull},
192 {0x0013813813813813ull, 0x8138138138138138ull},
193 {0x0011BB4A4046ED29ull, 0x011BB4A4046ED290ull},
194 {0x00103091B51F5E1Aull, 0x4EECC652F8EAC041ull},
195 {0x000ED7303B5CC0EDull, 0x7303B5CC0ED7303Bull},
196 {0x000DA740DA740DA7ull, 0x40DA740DA740DA74ull},
197 {0x000C9A633FCD9673ull, 0x00C9A633FCD96730ull},
198 {0x000BAB656100BAB6ull, 0x56100BAB656100BBull},
199 {0x000AD602B580AD60ull, 0x2B580AD602B580ADull},
200 {0x000A16B312EA8FC3ull, 0x77CD8E80A16B312Full},
201 {0x00096A850096A850ull, 0x096A850096A85009ull},
202 {0x0008CF008CF008CFull, 0x008CF008CF008CF0ull},
203 {0x0008421084210842ull, 0x1084210842108421ull},
204 {0x0007C1F07C1F07C1ull, 0xF07C1F07C1F07C1Full},
205 {0x00074D1E92F0074Dull, 0x1E92F0074D1E92F0ull},
206 {0x0006E25006E25006ull, 0xE25006E25006E250ull},
207 {0x0006806806806806ull, 0x8068068068068068ull},
208 {0x000626703D806267ull, 0x03D80626703D8062ull},
209 {0x0005D392C1005D39ull, 0x2C1005D392C1005Dull},
210 {0x0005871513005871ull, 0x5130058715130058ull},
211 {0x0005405405405405ull, 0x4054054054054054ull},
212 {0x0004FEC04FEC04FEull, 0xC04FEC04FEC04FECull},
305 static_assert(1 <= I && I <= 63,
"Template parameter <I> must be in the [1,63] range!");
306 static_assert(
sizeof(
void*) == 8,
"fixed_point128 is supported in 64 bit builds only!");
322 static constexpr int32_t
F = 127 - I;
327 static constexpr int32_t upper_frac_bits =
F - 64;
328 static constexpr uint64_t unity = 1ull << upper_frac_bits;
329 static inline const double upper_unity =
::pow(2, 64 -
F);
330 static inline const double lower_unity_l =
::pow(2, -
F);
331 static inline const double lower_unity_h =
::pow(2, 32 -
F);
332 static constexpr uint64_t int_mask = UINT64_MAX << upper_frac_bits;
337 static constexpr int32_t max_frac_digits =
static_cast<int32_t
>(
F * 0.30102999566398119521) + 1;
341 static constexpr int32_t parsed_frac_digits = 130;
342 static constexpr uint64_t sign_mask = 1ull << 63;
363 [[nodiscard]]
static int32_t ParseDecimal(
const char* first,
const char* last, uint64_t& l, uint64_t& h,
const char*& end)
noexcept
367 const char* p = first;
368 bool negative =
false;
369 if (p < last && (*p ==
'-' || *p ==
'+')) {
370 negative = (*p ==
'-');
375 uint64_t integer = 0;
376 bool integer_overflow =
false;
377 bool any_digit =
false;
378 while (p < last && *p >=
'0' && *p <=
'9') {
379 const uint64_t digit =
static_cast<uint64_t
>(*p -
'0');
380 if (integer > (UINT64_MAX - digit) / 10) {
381 integer_overflow =
true;
383 integer = integer * 10 + digit;
391 if (p < last && *p ==
'.') {
393 while (p < last && *p >=
'0' && *p <=
'9') {
394 if (digits < parsed_frac_digits) {
395 fraction.mul_small(10u);
396 fraction.add_small(
static_cast<uint32_t
>(*p -
'0'));
409 fraction.shift_left(
F + 1);
411 uint64_t q_low =
static_cast<uint64_t
>(fraction.at(0)) | (
static_cast<uint64_t
>(fraction.at(1)) << 32);
412 uint64_t q_high =
static_cast<uint64_t
>(fraction.at(2)) | (
static_cast<uint64_t
>(fraction.at(3)) << 32);
414 const uint8_t carry = addcarryx_u64(0, q_low, 1, &q_low);
415 addcarryx_u64(carry, q_high, 0, &q_high);
419 uint64_t m_low = q_low, m_high = 0;
420 const uint8_t carry2 = addcarryx_u64(0, q_high, integer << upper_frac_bits, &m_high);
423 const bool integer_too_large = integer_overflow || integer > (1ull << I);
424 const uint64_t limit_high = negative ? (1ull << 63) : (UINT64_MAX >> 1);
425 const uint64_t limit_low = negative ? 0 : UINT64_MAX;
426 const bool too_large = integer_too_large || carry2 != 0 || m_high > limit_high || (m_high == limit_high && m_low > limit_low);
432 return too_large ? 2 : 1;
456 [[nodiscard]]
FP128_FORCE_INLINE constexpr uint64_t GetMagnitude(uint64_t& l, uint64_t& h)
const noexcept
460 const uint64_t sign_bits =
static_cast<uint64_t
>(
static_cast<int64_t
>(high) >> 63);
493 const uint64_t sign_bits =
static_cast<uint64_t
>(
static_cast<int64_t
>(high) >> 63);
511 [[nodiscard]]
FP128_INLINE static constexpr uint64_t DigitTimesTen(uint64_t low, uint64_t high)
noexcept
513 uint64_t carry_low = 0, carry_high = 0;
514 (void)mulx_u64(low, 10ull, &carry_low);
515 uint64_t middle = mulx_u64(high, 10ull, &carry_high);
516 const uint64_t top = carry_high + addcarryx_u64(0, middle, carry_low, &middle);
539 [[nodiscard]]
FP128_INLINE static constexpr uint64_t RoundedMantissa(uint64_t low, uint64_t high, int32_t msb, int32_t frac_bits)
noexcept
541 const int32_t shift = msb - frac_bits;
554 }
else if (shift <= 64) {
555 sticky = (low << (65 - shift)) != 0;
556 }
else if (shift == 65) {
559 sticky = low != 0 || (high << (129 - shift)) != 0;
563 if (sticky || (mant & 1))
606 if constexpr (I == I2) {
611 else if constexpr (I < I2) {
613 constexpr int shift = I2 - I;
614 low = rhs.low << shift;
621 constexpr int shift = I - I2;
653 const uint32_t negative =
static_cast<uint32_t
>(d.
s());
654 const int32_t
e =
static_cast<int32_t
>(d.
e()) - 1023;
659 low = (negative) ? 0 : UINT64_MAX;
660 high = (negative) ? sign_mask : ~sign_mask;
673 if (bits_to_shift >= 0) {
674 high = f << bits_to_shift;
679 bits_to_shift = -bits_to_shift;
681 if (bits_to_shift <= 53) {
682 high = f >> bits_to_shift;
684 low <<= 64ll - bits_to_shift;
692 low = f >> bits_to_shift;
712 high = x << upper_frac_bits;
724 high =
static_cast<uint64_t
>(x) << upper_frac_bits;
733 high =
static_cast<uint64_t
>(x) << upper_frac_bits;
743 high =
static_cast<uint64_t
>(
static_cast<int64_t
>(x)) << upper_frac_bits;
771 while (*x && isspace(
static_cast<unsigned char>(*x)))
774 const char* end =
nullptr;
775 (void)ParseDecimal(x, x + strlen(x), low, high, end);
832 if constexpr (I == I2) {
837 else if constexpr (I < I2) {
839 constexpr int shift = I2 - I;
840 low = rhs.low << shift;
846 constexpr int shift = I - I2;
869 uint64_t l = 0, h = 0;
870 const uint64_t sign_bits = GetMagnitude(l, h);
871 const uint64_t magnitude = h >> upper_frac_bits;
874 return static_cast<int64_t
>((magnitude ^ sign_bits) - sign_bits);
881 [[nodiscard]]
FP128_FORCE_INLINE constexpr operator uint64_t() const noexcept {
return static_cast<uint64_t
>(
operator int64_t()); }
886 [[nodiscard]]
FP128_FORCE_INLINE constexpr operator int32_t() const noexcept {
return static_cast<int32_t
>(
operator int64_t()); }
891 [[nodiscard]]
FP128_FORCE_INLINE constexpr operator uint32_t() const noexcept {
return static_cast<uint32_t
>(
operator int64_t()); }
904 uint64_t l = 0, h = 0;
905 const uint32_t s =
static_cast<uint32_t
>(GetMagnitude(l, h) & 1);
906 const int32_t msb = 127 -
static_cast<int32_t
>(
lzcnt128(l, h));
907 const int32_t expo = msb -
F;
921 const uint64_t mant = RoundedMantissa(l, h, msb,
flt_frac_bits);
923 return Float::make(s,
static_cast<uint32_t
>(expo +
static_cast<int32_t
>(carry) + 127),
static_cast<uint32_t
>(mant >> carry));
939 uint64_t l = 0, h = 0;
940 const uint64_t s = GetMagnitude(l, h) & 1;
941 const int32_t msb = 127 -
static_cast<int32_t
>(
lzcnt128(l, h));
942 const int32_t expo = msb -
F;
953 const uint64_t mant = RoundedMantissa(l, h, msb,
dbl_frac_bits);
955 return Double::make(s,
static_cast<uint64_t
>(expo +
static_cast<int32_t
>(carry) + 1023), mant >> carry);
961 [[nodiscard]]
FP128_FORCE_INLINE constexpr operator long double() const noexcept {
return operator double(); }
966 [[nodiscard]]
FP128_INLINE operator std::string() const noexcept {
return operator char*(); }
973 static thread_local char str[128];
977 uint64_t l = 0, h = 0;
978 if (GetMagnitude(l, h))
983 p += snprintf(p,
sizeof(str) -
static_cast<size_t>(p - str),
"%llu", integer);
992 while (digits++ < max_frac_digits && temp) {
993 if constexpr (I < 4) {
994 integer = DigitTimesTen(temp.low, temp.high);
1000 *p++ =
'0' + (char)integer;
1001 temp.high &= ~int_mask;
1006 uint64_t next_digit;
1007 if constexpr (I < 4) {
1008 next_digit = DigitTimesTen(temp.low, temp.high);
1014 if (next_digit >= 5) {
1018 while (carry && q >= &str[0]) {
1019 if (*q >=
'0' && *q <=
'9') {
1033 char* start = str + (str[0] ==
'-' ? 1 : 0);
1034 memmove(start + 1, start, p - start + 1);
1042 if (
char* dot = strchr(str + (str[0] ==
'-' ? 1 : 0),
'.')) {
1044 while (last > dot && *last ==
'0')
1073 return temp >>=
static_cast<int32_t
>(shift);
1084 return temp <<= static_cast<int32_t>(shift);
1095 const uint8_t carry = addcarryx_u64(0, low, rhs.low, &low);
1096 addcarryx_u64(carry, high, rhs.high, &high);
1114 const uint8_t borrow = subborrow_u64(0, low, rhs.low, &low);
1115 subborrow_u64(borrow, high, rhs.high, &high);
1137 uint64_t r0, r1, r2, r3;
1146 uint64_t lhs_low = 0, lhs_high = 0, rhs_low = 0, rhs_high = 0;
1147 const uint64_t result_sign = GetMagnitude(lhs_low, lhs_high) ^ rhs.GetMagnitude(rhs_low, rhs_high);
1150 r0 = mulx_u64(lhs_low, rhs_low, &r1);
1153 r2 = mulx_u64(lhs_high, rhs_high, &r3);
1166 uint64_t cross_high = 0;
1167 uint64_t cross_low = mulx_u64(lhs_low, rhs_high, &cross_high);
1168 uint8_t carry = addcarryx_u64(0, r1, cross_low, &r1);
1169 carry = addcarryx_u64(carry, r2, cross_high, &r2);
1170 addcarryx_u64(carry, r3, 0, &r3);
1173 cross_low = mulx_u64(lhs_high, rhs_low, &cross_high);
1174 carry = addcarryx_u64(0, r1, cross_low, &r1);
1175 carry = addcarryx_u64(carry, r2, cross_high, &r2);
1176 addcarryx_u64(carry, r3, 0, &r3);
1180 constexpr int32_t index = (
F == 64) ? 0 :
F / 64;
1182 constexpr uint64_t
half = 1ull << (lsb - 1);
1187 const uint64_t w0 = (index == 0) ? r0 : r1;
1188 const uint64_t w1 = (index == 0) ? r1 : r2;
1189 const uint64_t w2 = (index == 0) ? r2 : r3;
1190 const bool need_rounding = (w0 &
half) != 0;
1197 NegateIf(result_sign);
1218 uint64_t r0, r1, r2, r3;
1222 uint64_t l = 0, h = 0;
1223 (void)GetMagnitude(l, h);
1226 r0 = mulx_u64(l, l, &r1);
1229 r2 = mulx_u64(h, h, &r3);
1232 uint64_t cross_high = 0;
1233 const uint64_t cross_low = mulx_u64(l, h, &cross_high);
1235 uint8_t carry = addcarryx_u64(0, r1, cross_low, &r1);
1236 carry = addcarryx_u64(carry, r2, cross_high, &r2);
1237 addcarryx_u64(carry, r3, 0, &r3);
1239 carry = addcarryx_u64(0, r1, cross_low, &r1);
1240 carry = addcarryx_u64(carry, r2, cross_high, &r2);
1241 addcarryx_u64(carry, r3, 0, &r3);
1245 constexpr int32_t index = (
F == 64) ? 0 :
F / 64;
1247 constexpr uint64_t
half = 1ull << (lsb - 1);
1250 const uint64_t w0 = (index == 0) ? r0 : r1;
1251 const uint64_t w1 = (index == 0) ? r1 : r2;
1252 const uint64_t w2 = (index == 0) ? r2 : r3;
1253 const bool need_rounding = (w0 &
half) != 0;
1270 if constexpr (std::is_floating_point_v<T>) {
1276 uint64_t magnitude =
static_cast<uint64_t
>(x);
1277 bool negate_result =
false;
1278 if constexpr (std::is_signed_v<T>) {
1281 magnitude = 0ull - magnitude;
1282 negate_result =
true;
1305 low = mulx_u64(low, x, &temp);
1306 high = high * x + temp;
1320 bool need_rounding =
false;
1327 uint64_t denom_low = 0, denom_high = 0;
1328 const uint64_t result_sign = TakeMagnitude() ^ rhs.GetMagnitude(denom_low, denom_high);
1331 if (1 ==
popcnt128(denom_low, denom_high)) {
1333 const int32_t expo = I -
static_cast<int32_t
>(
lzcnt128(denom_low, denom_high));
1343 const uint64_t nom[2] = {low, high};
1344 const uint64_t denom = denom_high >> upper_frac_bits;
1346 if (
div_64bit((uint64_t*)q, &r, (uint64_t*)nom, denom, 2)) {
1349 need_rounding = r >= denom - r;
1356 bool use_long_division =
true;
1363 use_long_division = high >= sign_mask;
1364 if (!use_long_division)
1368 if (use_long_division)
1369 need_rounding = DivideMagnitude(denom_low, denom_high);
1376 if (need_rounding) {
1380 NegateIf(result_sign);
1390 if constexpr (std::is_floating_point_v<T>) {
1396 uint64_t magnitude =
static_cast<uint64_t
>(x);
1397 bool negate_result =
false;
1398 if constexpr (std::is_signed_v<T>) {
1401 magnitude = 0ull - magnitude;
1402 negate_result =
true;
1429 const int32_t
e =
static_cast<int32_t
>(d.
e()) - 1023;
1430 return (
e >= 0) ? *
this >>=
e : *
this <<= -
e;
1450 const uint64_t sign_bits = TakeMagnitude();
1452 const uint64_t nom[2] = {low, high};
1465 NegateIf(sign_bits);
1487 uint64_t denom_low = 0, denom_high = 0;
1488 (void)rhs.GetMagnitude(denom_low, denom_high);
1489 const uint64_t sign_bits = TakeMagnitude();
1492 if (denom_high != 0) {
1495 const uint64_t nom[4] = {low, high, 0, 0};
1496 const uint64_t denom[2] = {denom_low, denom_high};
1500 const uint64_t nom[2] = {low, high};
1502 (void)
div_64bit(q, rem, nom, denom_low, 2);
1507 NegateIf(sign_bits);
1643 [[nodiscard]]
FP128_FORCE_INLINE constexpr operator bool() const noexcept {
return high != 0 || low != 0; }
1688 if constexpr (I == 63) {
1693 return 0 == low && 0 == (high << (I + 1));
1731 const int32_t s =
static_cast<int32_t
>(
lzcnt128(*
this));
1741 static_assert(I >= 2,
"pi() needs template parameter <I> to be at least 2: 3.14159... does not fit in one integer bit!");
1742 static const fixed_point128 pi =
"3.14159265358979323846264338327950288419716939937510";
1752 static_assert(I >= 3,
"pi2() needs template parameter <I> to be at least 3: 6.28318... does not fit in fewer integer bits!");
1753 static const fixed_point128 pi2 =
"6.28318530717958647692528676655900576839433879875021";
1781 static_assert(I >= 2,
"e() needs template parameter <I> to be at least 2: 2.71828... does not fit in one integer bit!");
1782 static const fixed_point128 e =
"2.71828182845904523536028747135266249775724709369";
1827 static constexpr uint64_t ln2_fraction[2] = {0xB17217F7D1CF79ABull, 0xC9E3B39803F2F6AFull};
1830 static constexpr uint64_t log10_2_fraction[2] = {0x4D104D427DE7FBCCull, 0x47C4ACD605BE48BCull};
1846 uint64_t l = 0, h = 0;
1847 const uint64_t sign_bits = GetMagnitude(l, h);
1849 uint64_t r1 = 0, r2 = 0, r3 = 0;
1850 (void)mulx_u64(l, c_low, &r1);
1851 r2 = mulx_u64(h, c_high, &r3);
1852 uint64_t cross_high = 0;
1853 uint64_t cross_low = mulx_u64(l, c_high, &cross_high);
1854 uint8_t carry = addcarryx_u64(0, r1, cross_low, &r1);
1855 carry = addcarryx_u64(carry, r2, cross_high, &r2);
1856 addcarryx_u64(carry, r3, 0, &r3);
1857 cross_low = mulx_u64(h, c_low, &cross_high);
1858 carry = addcarryx_u64(0, r1, cross_low, &r1);
1859 carry = addcarryx_u64(carry, r2, cross_high, &r2);
1860 addcarryx_u64(carry, r3, 0, &r3);
1865 res.NegateIf(sign_bits);
1870 static constexpr uint64_t inv_sqrt2_fraction[2] = {0xB504F333F9DE6484ull, 0x597D89B3754ABE9Full};
1902 constexpr int max_iterations = 6;
1906 for (
int i = 0; i < max_iterations; ++i) {
1910 if (
fabs(
e) <= eps) {
1918 if (candidate_residual >= residual)
1922 sin_res = sin_candidate;
1923 residual = candidate_residual;
1929 static constexpr uint64_t inv_e_fraction[2] = {0x5E2D58D8B3BCDF1Aull, 0xBADEC7829054F90Eull};
1958 uint64_t l = 0, h = 0;
1959 (void)x.GetMagnitude(l, h);
1964 uint64_t one_square[4] {};
1965 one_square[(2 *
F) / 64] = 1ull << ((2 *
F) % 64);
1967 for (int32_t i = 0; i < 4; ++i) {
1968 carry = (minus) ? subborrow_u64(carry, s[i], one_square[i], &s[i]) : addcarryx_u64(carry, s[i], one_square[i], &s[i]);
1972 RoundedSqrt256(s, res.low, res.high);
1990 uint64_t s_low = 0, s_high = 0;
1991 const uint8_t carry = addcarryx_u64(addcarryx_u64(0, x_low, r.low, &s_low), x_high, r.high, &s_high);
1992 if (carry == 0 && (s_high >> 63) == 0) {
1997 const uint64_t round_bit = (s_low >> 1) & 1;
1998 s_low = (s_low >> 2) | (s_high << 62);
1999 s_high = (s_high >> 2) | (
static_cast<uint64_t
>(carry) << 62);
2000 s_high += addcarryx_u64(0, s_low, round_bit, &s_low);
2001 const fixed_point128 ln2 = FromFraction128(ln2_fraction[0], ln2_fraction[1]);
2031 constexpr uint64_t cutoff = 1ull << ((I >= 5) ? (I - 5) : 0);
2033 const work_t xx =
sqr(x);
2034 work_t term = (cosine) ? work_t::one() : x;
2036 bool subtract =
true;
2041 uint64_t term_low = 0, term_high = 0;
2042 term.get_components(term_low, term_high);
2043 if (term_high == 0 && term_low < cutoff) {
2051 subtract = !subtract;
2114 uint64_t m_low = low, m_high = high;
2118 const size_t j =
static_cast<size_t>((m_high >> (63 - K)) & ((1ull << K) - 1));
2120 uint64_t p_low = 0, p_high = 0;
2129 constexpr uint64_t one_half = 1ull << 63;
2130 uint64_t z_low = p_low, z_high = p_high - one_half;
2132 const work_t z(z_low, z_high);
2135 work_t acc = Log2InvN(LOG2_TERMS - 1);
2136 for (int32_t n = LOG2_TERMS - 1; n >= 1; --n) {
2137 acc = Log2InvN(n - 1) - z * acc;
2139 const work_t series = z * acc;
2205 FP128_INLINE bool DivideMagnitude(uint64_t denom_low, uint64_t denom_high)
2208 const uint64_t nom[4] = {0, 0, low, high};
2209 const uint64_t denom[2] = {denom_low, denom_high};
2213 const bool ok = (denom_high != 0) ?
Divide256By128(q,
nullptr, nom, denom)
2221 constexpr uint64_t
half = 1ull << I;
2222 const bool need_rounding = (q[0] &
half) != 0;
2223 if constexpr (I == 63) {
2229 high = FP128_SHIFTRIGHT128(q[1], q[2], I + 1);
2230 low = FP128_SHIFTRIGHT128(q[0], q[1], I + 1);
2233 return need_rounding;
2242 FP128_INLINE static constexpr void Square256(uint64_t l, uint64_t h, uint64_t (&r)[4])
noexcept
2244 r[0] = mulx_u64(l, l, &r[1]);
2245 r[2] = mulx_u64(h, h, &r[3]);
2248 uint64_t cross_high = 0;
2249 const uint64_t cross_low = mulx_u64(l, h, &cross_high);
2250 const uint64_t doubled_low = cross_low << 1;
2251 const uint64_t doubled_high = (cross_high << 1) | (cross_low >> 63);
2252 const uint64_t doubled_top = cross_high >> 63;
2253 uint8_t carry = addcarryx_u64(0, r[1], doubled_low, &r[1]);
2254 carry = addcarryx_u64(carry, r[2], doubled_high, &r[2]);
2255 addcarryx_u64(carry, r[3], doubled_top, &r[3]);
2264 [[nodiscard]]
FP128_INLINE static constexpr int32_t Compare256(
const uint64_t (&a)[4],
const uint64_t (&b)[4])
noexcept
2266 for (int32_t i = 3; i >= 0; --i) {
2268 return (a[i] < b[i]) ? -1 : 1;
2293 FP128_INLINE static void RoundedSqrt256(
const uint64_t (&s)[4], uint64_t& res_low, uint64_t& res_high)
noexcept
2295 res_low = res_high = 0;
2297 while (top >= 0 && s[top] == 0) {
2305 const int32_t lz =
static_cast<int32_t
>(lzcnt64(s[top]));
2306 uint64_t lead = s[top] << lz;
2307 if (lz != 0 && top != 0) {
2308 lead |= s[top - 1] >> (64 - lz);
2310 const int32_t k = 64 * top - lz;
2313 const double estimate = std::ldexp(std::sqrt(std::ldexp(
static_cast<double>(lead), k & 1)), k >> 1) * (1.0 + 0x1p-45);
2315 uint64_t r_low = 0, r_high = 0;
2316 if (estimate < 0x1p64) {
2317 r_low =
static_cast<uint64_t
>(estimate) + 2;
2320 const double mantissa = std::frexp(estimate, &exponent);
2321 r_low =
static_cast<uint64_t
>(std::ldexp(mantissa, 64));
2323 r_high += addcarryx_u64(0, r_low, 1, &r_low);
2328 for (int32_t i = 0; i < 2; ++i) {
2331 const uint64_t divisor[2] = {r_low, r_high};
2334 (void)
div_64bit(q,
nullptr, s, r_low, 4);
2337 const uint8_t sum_carry = addcarryx_u64(addcarryx_u64(0, r_low, q[0], &r_low), r_high, q[1], &r_high);
2338 r_low = (r_low >> 1) | (r_high << 63);
2339 r_high = (r_high >> 1) | (
static_cast<uint64_t
>(sum_carry) << 63);
2344 Square256(r_low, r_high,
square);
2345 uint64_t below[4] {}, above[4] {};
2346 uint8_t borrow = subborrow_u64(0,
square[0], r_low, &below[0]);
2347 borrow = subborrow_u64(borrow,
square[1], r_high, &below[1]);
2348 borrow = subborrow_u64(borrow,
square[2], 0, &below[2]);
2349 (void)subborrow_u64(borrow,
square[3], 0, &below[3]);
2350 uint8_t carry = addcarryx_u64(0,
square[0], r_low, &above[0]);
2351 carry = addcarryx_u64(carry,
square[1], r_high, &above[1]);
2352 carry = addcarryx_u64(carry,
square[2], 0, &above[2]);
2353 (void)addcarryx_u64(carry,
square[3], 0, &above[3]);
2355 if (Compare256(s, below) <= 0) {
2356 r_high -= subborrow_u64(0, r_low, 1, &r_low);
2357 }
else if (Compare256(s, above) > 0) {
2358 r_high += addcarryx_u64(0, r_low, 1, &r_low);
2382 template <
typename T>
2394 template <
typename T>
2406 template <
typename T>
2490 template <
typename T>
2491 requires std::is_arithmetic_v<T>
2497 template <
typename T>
2498 requires std::is_arithmetic_v<T>
2504 template <
typename T>
2505 requires std::is_arithmetic_v<T>
2511 template <
typename T>
2512 requires std::is_arithmetic_v<T>
2518 template <
typename T>
2519 requires std::is_arithmetic_v<T>
2525 template <
typename T>
2526 requires std::is_arithmetic_v<T>
2532 template <
typename T>
2533 requires std::is_arithmetic_v<T>
2539 template <
typename T>
2540 requires std::is_arithmetic_v<T>
2559 template <
typename T>
2560 requires std::is_arithmetic_v<T>
2572 template <
typename T>
2573 requires std::is_arithmetic_v<T>
2592 return lhs.high == rhs.high && lhs.low == rhs.low;
2612 return lhs.high != rhs.high || lhs.low != rhs.low;
2634 if (lhs.high != rhs.high)
2635 return static_cast<int64_t
>(lhs.high) <
static_cast<int64_t
>(rhs.high);
2637 return lhs.low < rhs.low;
2675 if (lhs.high != rhs.high)
2676 return static_cast<int64_t
>(lhs.high) >
static_cast<int64_t
>(rhs.high);
2678 return lhs.low > rhs.low;
2795 return (y.
is_negative()) ? -magnitude : magnitude;
2815 if (iptr ==
nullptr)
2861 uint64_t x_low = 0, x_high = 0, y_low = 0, y_high = 0;
2862 (void)x.GetMagnitude(x_low, x_high);
2863 (void)y.GetMagnitude(y_low, y_high);
2866 uint64_t sum[4] {}, y_square[4] {};
2867 Square256(x_low, x_high, sum);
2868 Square256(y_low, y_high, y_square);
2870 for (int32_t i = 0; i < 4; ++i) {
2871 carry = addcarryx_u64(carry, sum[i], y_square[i], &sum[i]);
2875 RoundedSqrt256(sum, res.low, res.high);
2897 uint64_t l = 0, h = 0;
2898 (void)x.GetMagnitude(l, h);
2899 return (h != 0) ? lzcnt64(h) : 64 + lzcnt64(l);
2922 if constexpr (upper_frac_bits == 0) {
2926 s[1] = x.low << upper_frac_bits;
2927 s[2] = (x.high << upper_frac_bits) | (x.low >> (64 - upper_frac_bits));
2928 s[3] = x.high >> (64 - upper_frac_bits);
2932 RoundedSqrt256(s, root.low, root.high);
2951 "0.166666666666666666666666666666666666667",
2952 "0.041666666666666666666666666666666666667",
2953 "0.008333333333333333333333333333333333333",
2954 "0.001388888888888888888888888888888888889",
2955 "0.000198412698412698412698412698412698413",
2956 "0.000024801587301587301587301587301587302",
2957 "0.000002755731922398589065255731922398589",
2958 "0.000000275573192239858906525573192239859",
2959 "0.000000025052108385441718775052108385442",
2960 "0.000000002087675698786809897921009032120",
2961 "0.000000000160590438368216145993923771702",
2962 "0.000000000011470745597729724713851697979",
2963 "0.000000000000764716373181981647590113199",
2964 "0.000000000000047794773323873852974382075",
2965 "0.000000000000002811457254345520763198946",
2966 "0.000000000000000156192069685862264622164",
2967 "0.000000000000000008220635246624329716956",
2968 "0.000000000000000000411031762331216485848",
2969 "0.000000000000000000019572941063391261231",
2970 "0.000000000000000000000889679139245057329",
2971 "0.000000000000000000000038681701706306840",
2972 "0.000000000000000000000001611737571096118",
2973 "0.000000000000000000000000064469502843845",
2974 "0.000000000000000000000000002479596263225",
2975 "0.000000000000000000000000000091836898638",
2976 "0.000000000000000000000000000003279889237",
2977 "0.000000000000000000000000000000113099628",
2978 "0.000000000000000000000000000000003769988",
2979 "0.000000000000000000000000000000000121613",
2980 "0.000000000000000000000000000000000003800",
2981 "0.000000000000000000000000000000000000115",
2982 "0.000000000000000000000000000000000000003"
2986 if (x >= 0 && x < series_len) {
3008 uint64_t l = 0, h = 0;
3009 const uint64_t sign_bits = x.GetMagnitude(l, h);
3015 const int32_t msb = 127 -
static_cast<int32_t
>(
lzcnt128(l, h));
3025 const bool need_rounding = res.DivideMagnitude(l, h);
3027 res.NegateIf(sign_bits);
3044 "0.7853981633974483096156608458198757210492",
3045 "0.4636476090008061162142562314612144020285",
3046 "0.2449786631268641541720824812112758109141",
3047 "0.1243549945467614350313548491638710255731",
3048 "0.0624188099959573484739791129855051136062",
3049 "0.0312398334302682762537117448924909770324",
3050 "0.0156237286204768308028015212565703189111",
3051 "0.0078123410601011112964633918421992816212",
3052 "0.0039062301319669718276286653114243871403",
3053 "0.0019531225164788186851214826250767139316",
3054 "0.0009765621895593194304034301997172908516",
3055 "0.0004882812111948982754692396256448486661",
3056 "0.0002441406201493617640167229432596599862",
3057 "0.0001220703118936702042390586461179563009",
3058 "0.0000610351561742087750216625691738291537",
3059 "0.0000305175781155260968618259534385360197",
3060 "0.0000152587890613157621072319358126978851",
3061 "0.0000076293945311019702633884823401050905",
3062 "0.0000038146972656064962829230756163729937",
3063 "0.0000019073486328101870353653693059172441",
3064 "0.0000009536743164059608794206706899231123",
3065 "0.0000004768371582030888599275838214492470",
3066 "0.0000002384185791015579824909479772189326",
3067 "0.0000001192092895507806853113684971379221",
3068 "0.0000000596046447753905544139210621417888",
3069 "0.0000000298023223876953036767401327677095",
3070 "0.0000000149011611938476551470925165959632",
3071 "0.0000000074505805969238279871365645744953",
3072 "0.0000000037252902984619140452670705718119",
3073 "0.0000000018626451492309570290958838214764",
3074 "0.0000000009313225746154785153557354776845",
3075 "0.0000000004656612873077392577788419347105",
3076 "0.0000000002328306436538696289020427418388",
3077 "0.0000000001164153218269348144525990927298",
3078 "0.0000000000582076609134674072264967615912",
3079 "0.0000000000291038304567337036132730326989",
3080 "0.0000000000145519152283668518066395978373",
3081 "0.0000000000072759576141834259033201841046",
3082 "0.0000000000036379788070917129516601402005",
3083 "0.0000000000018189894035458564758300761188",
3084 "0.0000000000009094947017729282379150388117",
3085 "0.0000000000004547473508864641189575194999",
3086 "0.0000000000002273736754432320594787597617",
3087 "0.0000000000001136868377216160297393798823",
3088 "0.0000000000000568434188608080148696899413",
3089 "0.0000000000000284217094304040074348449706",
3090 "0.0000000000000142108547152020037174224853",
3091 "0.0000000000000071054273576010018587112426",
3092 "0.0000000000000035527136788005009293556213",
3093 "0.0000000000000017763568394002504646778106",
3094 "0.0000000000000008881784197001252323389053",
3095 "0.0000000000000004440892098500626161694526",
3096 "0.0000000000000002220446049250313080847263",
3097 "0.0000000000000001110223024625156540423631",
3098 "0.0000000000000000555111512312578270211815",
3099 "0.0000000000000000277555756156289135105907",
3100 "0.0000000000000000138777878078144567552953",
3101 "0.0000000000000000069388939039072283776476",
3102 "0.0000000000000000034694469519536141888238",
3103 "0.0000000000000000017347234759768070944119",
3104 "0.0000000000000000008673617379884035472059",
3105 "0.0000000000000000004336808689942017736029",
3106 "0.0000000000000000002168404344971008868015",
3107 "0.0000000000000000001084202172485504434007",
3129 constexpr uint32_t angles_count =
array_length(angles);
3130 static const fixed_point128 K =
"0.607252935008881256169446752504928263";
3135 auto angle = angles[0];
3137 for (uint32_t j = 1; j <= angles_count; ++j) {
3162 if (angles_count < j + 1) {
3170 if (apply_scale_factor) {
3187 static_assert(I >= 4,
"sin1() needs template parameter <I> to be at least 4: its callers reduce the argument with pi, which needs more than one integer bit!");
3193 return (negative) ? -res : res;
3208 static_assert(I >= 4,
"cos1() needs template parameter <I> to be at least 4: its callers reduce the argument with pi, which needs more than one integer bit!");
3226 static_assert(I >= 4,
"sin() needs template parameter <I> to be at least 4: it evaluates sin1() and cos1()!");
3230 int64_t n =
static_cast<int64_t
>((x /
half_pi) +
round);
3259 static_assert(I >= 4,
"asin() needs template parameter <I> to be at least 4: it evaluates sin() and cos()!");
3260 if (x < -1 || x > 1)
3267 res = AsinNewton(x);
3271 return (negative) ? -res : res;
3285 static_assert(I >= 4,
"cos() needs template parameter <I> to be at least 4: it evaluates sin1() and cos1()!");
3289 int64_t n =
static_cast<int64_t
>((x /
half_pi) +
round);
3316 static_assert(I >= 4,
"acos() needs template parameter <I> to be at least 4: it evaluates sin() and cos()!");
3317 if (x < -1 || x > 1)
3326 const fixed_point128 twice = AsinNewton(RootOfHalfComplement(magnitude)) << 1;
3341 static_assert(I >= 4,
"tan() needs template parameter <I> to be at least 4: it evaluates sin() and cos()!");
3342 constexpr bool use_cordic =
false;
3343 if constexpr (use_cordic) {
3348 return sin_x / cos_x;
3356 return sin(x) / cos_x;
3367 static_assert(I >= 4,
"atan() needs template parameter <I> to be at least 4: it evaluates sin() and cos()!");
3372 constexpr int max_iterations = 6;
3391 for (
int i = 0; i < max_iterations; ++i) {
3405 return (negative) ? -res : res;
3416 static_assert(I >= 4,
"atan2() needs template parameter <I> to be at least 4: it evaluates atan()!");
3462 static_assert(I >= 4,
"sinh() needs template parameter <I> to be at least 4!");
3463 return (
exp(x) -
exp(-x)) >> 1;
3505 uint64_t l = 0, h = 0;
3506 (void)x.GetMagnitude(l, h);
3507 const fixed_point128 res = LogOfSum(l, h, RootOfSquareAndOne(x,
false));
3523 static_assert(I >= 4,
"cosh() needs template parameter <I> to be at least 4!");
3524 return (
exp(x) +
exp(-x)) >> 1;
3567 return LogOfSum(x.low, x.high, RootOfSquareAndOne(x,
true));
3581 static_assert(I >= 2,
"tanh() needs template parameter <I> to be at least 2: it evaluates exp()!");
3588 e2 =
exp(-(magnitude << 1));
3591 e2 =
sqr(
exp(-magnitude));
3616 if (x <= -one || x >=
one)
3647 static_assert(I >= 2,
"exp() needs template parameter <I> to be at least 2: it multiplies by e(), which needs 2 integer bits!");
3655 uint64_t ix =
static_cast<uint64_t
>(int_part);
3659 fixed_point128 b = (negative) ? FromFraction128(inv_e_fraction[0], inv_e_fraction[1]) :
e;
3676 for (
int i = 2;; ++i) {
3682 if (negative && (i & 1)) {
3689 return exp_ix * exp_fx;
3701 static_assert(I >= 2,
"expm1() needs template parameter <I> to be at least 2: it evaluates exp()!");
3713 static_assert(I >= 2,
"exp2() needs template parameter <I> to be at least 2: it evaluates exp()!");
3720 return exp(x.MulByFraction128(ln2_fraction[1], ln2_fraction[0]));
3734 static_assert(I >= 2,
"pow() needs template parameter <I> to be at least 2: it evaluates exp()!");
3755 return exp(y * lan_x);
3770 throw std::domain_error(
"Math domain error! Function accepts positive, non-zero values only.");
3778 const int32_t leading_zeros =
static_cast<int32_t
>(
lzcnt128(x.low, x.high));
3779 const int32_t expo = 127 - leading_zeros -
F;
3783 const uint64_t below_low = x.low - 1;
3784 const uint64_t below_high = x.high - ((x.low == 0) ? 1ull : 0ull);
3785 if (((x.low & below_low) | (x.high & below_high)) == 0) {
3789 if (std::is_constant_evaluated()) {
3793 }
else if (expo > 0) {
3796 return iy + log2_fraction_bitwise(x);
3799 return iy + log2_fraction(x.low, x.high, leading_zeros);
3815 throw std::domain_error(
"Math domain error! Function accepts positive, non-zero values only.");
3820 return log2(x).MulByFraction128(ln2_fraction[1], ln2_fraction[0]);
3843 throw std::domain_error(
"Math domain error! Function accepts positive, non-zero values only.");
3850 return log2(x).MulByFraction128(log10_2_fraction[1], log10_2_fraction[0]);
3865 throw std::domain_error(
"Math domain error! logb() of zero is minus infinity.");
3881 std::string text =
static_cast<std::string
>(value);
3882 if ((os.flags() & std::ios_base::showpos) && !text.empty() && text[0] !=
'-')
3883 text.insert(text.begin(),
'+');
3885 const std::streamsize width = os.width();
3887 if (
static_cast<std::streamsize
>(text.size()) < width) {
3888 const size_t padding =
static_cast<size_t>(width) - text.size();
3889 const std::ios_base::fmtflags adjust = os.flags() & std::ios_base::adjustfield;
3890 if (adjust == std::ios_base::left)
3891 text.append(padding, os.fill());
3892 else if (adjust == std::ios_base::internal && !text.empty() && (text[0] ==
'-' || text[0] ==
'+'))
3893 text.insert(1, padding, os.fill());
3895 text.insert(0, padding, os.fill());
3915 const std::istream::sentry sentry(is);
3919 using traits = std::char_traits<char>;
3920 std::streambuf*
const buffer = is.rdbuf();
3922 int c = buffer->sgetc();
3923 const auto take = [&]() {
3924 text += traits::to_char_type(c);
3926 c = buffer->sgetc();
3928 if (c ==
'+' || c ==
'-') {
3931 while (c != traits::eof() && c >=
'0' && c <=
'9') {
3936 while (c != traits::eof() && c >=
'0' && c <=
'9') {
3940 if (c == traits::eof()) {
3941 is.setstate(std::ios_base::eofbit);
3944 uint64_t low = 0, high = 0;
3945 const char* end =
nullptr;
3946 const int32_t status = fixed_point128<I>::ParseDecimal(text.data(), text.data() + text.size(), low, high, end);
3949 is.setstate(std::ios_base::failbit);
3950 }
else if (status == 2) {
3951 value = (!text.empty() && text[0] ==
'-') ? std::numeric_limits<fixed_point128<I>>::lowest() : std::numeric_limits<fixed_point128<I>>::max();
3952 is.setstate(std::ios_base::failbit);
3980template <
int32_t I>
class numeric_limits<
fp128::fixed_point128<I>>
4025 static constexpr int min_exponent10 =
static_cast<int>((I - 127) * 0.30102999566398119521);
4040 [[nodiscard]]
static constexpr value_type
max() noexcept {
return value_type(UINT64_MAX, 0x7FFFFFFFFFFFFFFFull); }
4043 [[nodiscard]]
static constexpr value_type
lowest() noexcept {
return value_type(0, 1ull << 63); }
4048 [[nodiscard]]
static constexpr value_type
infinity() noexcept {
return value_type(); }
4049 [[nodiscard]]
static constexpr value_type
quiet_NaN() noexcept {
return value_type(); }
4050 [[nodiscard]]
static constexpr value_type
signaling_NaN() noexcept {
return value_type(); }
4056template <
int32_t I>
struct hash<
fp128::fixed_point128<I>>
4061 uint64_t low = 0, high = 0;
4062 value.get_components(low, high);
4064 uint64_t state = low + 0x9E3779B97F4A7C15ull;
4065 state = (state ^ (state >> 30)) * 0xBF58476D1CE4E5B9ull;
4066 state = (state ^ (state >> 27)) * 0x94D049BB133111EBull;
4067 state ^= high + 0x9E3779B97F4A7C15ull + (state << 6) + (state >> 2);
4068 state = (state ^ (state >> 30)) * 0xBF58476D1CE4E5B9ull;
4069 return static_cast<size_t>(state ^ (state >> 31));
4080template <
int32_t I>
struct formatter<
fp128::fixed_point128<I>, char>
4082 constexpr auto parse(basic_format_parse_context<char>& context)
4084 auto it = context.begin();
4085 const auto end = context.end();
4086 if (it == end || *it ==
'}')
4089 const auto is_align = [](
char c) {
return c ==
'<' || c ==
'>' || c ==
'^'; };
4090 if (it + 1 != end && is_align(*(it + 1))) {
4094 }
else if (is_align(*it)) {
4098 if (it != end && (*it ==
'+' || *it ==
'-' || *it ==
' '))
4101 if (it != end && *it ==
'0') {
4106 while (it != end && *it >=
'0' && *it <=
'9')
4109 if (it != end && *it !=
'}')
4110 throw format_error(
"invalid format specification for fixed_point128");
4116 string text =
static_cast<string>(value);
4117 if (
sign !=
'-' && !text.empty() && text[0] !=
'-')
4118 text.insert(text.begin(),
sign);
4120 if (
static_cast<int>(text.size()) <
width) {
4121 const size_t padding =
static_cast<size_t>(
width) - text.size();
4123 const size_t offset = (!text.empty() && (text[0] ==
'-' || text[0] ==
'+' || text[0] ==
' ')) ? 1u : 0u;
4124 text.insert(offset, padding,
'0');
4125 }
else if (
align ==
'<') {
4126 text.append(padding,
fill);
4127 }
else if (
align ==
'^') {
4128 text.insert(0, padding / 2,
fill);
4129 text.append(padding - padding / 2,
fill);
4131 text.insert(0, padding,
fill);
4134 return std::copy(text.begin(), text.end(), context.out());
Google test class (friend).
friend fixed_point128 log(fixed_point128 x)
Calculates the natural Log (base e) of x: log(x) log2(x) * ln(2), the constant applied with 128 fract...
friend fixed_point128 operator%(const T &lhs, const fixed_point128 &rhs)
Performs modulo of a scalar by a fixed_point128.
constexpr fixed_point128 operator+() const noexcept
Unary +. Returns a copy of the object.
friend constexpr fixed_point128 operator^(fixed_point128 lhs, const T &rhs)
Performs bitwise XOR (^)
friend constexpr bool operator==(const fixed_point128 &lhs, const fixed_point128 &rhs) noexcept
Compare logical/bitwise equal.
friend constexpr bool operator==(const T &lhs, const fixed_point128 &rhs) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
static constexpr fixed_point128 half() noexcept
friend constexpr bool operator<(const T &lhs, const fixed_point128 &rhs) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
constexpr int32_t get_bit(uint32_t bit) const noexcept
get a specific bit within the 128 fixed point data
constexpr fixed_point128 & operator*=(const fixed_point128 &rhs) noexcept
Multiplies a value to this object.
friend constexpr fixed_point128 operator*(const T &lhs, const fixed_point128 &rhs) noexcept
Multiplies a scalar and a fixed_point128, in that order.
static const fixed_point128 & half_pi() noexcept
Returns an instance of fixed_point128 with the value of pi / 2.
friend fixed_point128 operator/(const T &lhs, const fixed_point128 &rhs)
Divides a scalar by a fixed_point128.
fixed_point128< I > type
Self type alias.
static constexpr int32_t F
constexpr fixed_point128 & operator|=(const fixed_point128 &rhs) noexcept
Bitwise OR=.
friend constexpr bool operator>=(const fixed_point128 &lhs, const T &rhs) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
constexpr fixed_point128(int32_t x) noexcept
Constructor from int32_t type.
constexpr fixed_point128 & operator=(fixed_point128 &&rhs) noexcept
Move assignment operator.
friend fixed_point128 fmod(const fixed_point128 &x, const fixed_point128 &y)
Performs the fmod() function, similar to libc's fmod(): x - y * trunc(x / y). Exact,...
friend constexpr fixed_point128 operator<<(const T &lhs, const fixed_point128 &rhs) noexcept
Shifts a scalar left by a fixed_point128 shift count.
friend fixed_point128 asin(fixed_point128 x) noexcept
Calculate the inverse sine function Newton's method on sin() for |x| up to one half,...
constexpr fixed_point128 & operator--() noexcept
Prefix – operation (–a)
friend void fact_reciprocal(int x, fixed_point128 &res) noexcept
Factorial reciprocal (inverse). Calculates 1 / x! Maximum value of x that may produce non zero values...
friend constexpr bool operator<(const fixed_point128 &lhs, const fixed_point128 &rhs) noexcept
Return true if this object is small than the rhs.
friend fixed_point128 atan2(fixed_point128 y, fixed_point128 x) noexcept
Calculate the inverse tangent function of the ratio y / x Accuracy, measured against mpmath at I = 1,...
friend constexpr fixed_point128 operator-(fixed_point128 lhs, const T &rhs) noexcept
subtracts the right hand side operand to this object to and returns the result.
friend constexpr bool operator>=(const fixed_point128 &lhs, const fixed_point128 &rhs) noexcept
Return true this object is larger or equal than the rhs.
friend fixed_point128 sqrt(const fixed_point128 &x, uint32_t iterations=3) noexcept
Calculates the square root, correctly rounded.
friend constexpr fixed_point128 fmax(const fixed_point128 &x, const fixed_point128 &y) noexcept
Returns the maximum between x and y.
constexpr fixed_point128 & operator^=(const T &rhs)
Bitwise XOR=.
friend constexpr fixed_point128 operator+(fixed_point128 lhs, const T &rhs) noexcept
Adds 2 values and returns the result.
friend constexpr bool operator>(const fixed_point128 &lhs, const fixed_point128 &rhs) noexcept
Return true this object is larger than the rhs.
fixed_point128 & operator%=(T rhs)
Performs modulo with a generic type by converting to fixed_point128.
constexpr fixed_point128(double x) noexcept
Constructor from the double type Underflow goes to zero. Overflow, NaN and +-INF saturate to the extr...
constexpr fixed_point128 & square() noexcept
Squares this object in place.
friend constexpr fixed_point128 log2(fixed_point128 x)
Calculates the Log base 2 of x: y = log2(x) Accuracy, measured against mpmath at I = 1,...
fixed_point128(const std::string &x) noexcept
Constructor from std::string. Accurate to 37 digits after the decimal point. Allows creating very hig...
friend constexpr fixed_point128 ceil(const fixed_point128 &x) noexcept
Performs the ceil() function, similar to libc's ceil(), rounds up towards infinity.
constexpr fixed_point128 operator<<(T shift) const noexcept
Performs left shift operation. Hinted rather than forced, see operator>> above.
friend fixed_point128 tan(fixed_point128 x) noexcept
Calculate the tangent function tan(x) = sin(x)/cos(x)
static const fixed_point128 & pi2() noexcept
Returns an instance of fixed_point128 with the value of pi * 2 Needs I to be 3 or more.
constexpr fixed_point128 operator-() const noexcept
Unary -. Returns the two's complement of the object. The most negative value has no positive counterp...
friend fixed_point128 operator%(fixed_point128 lhs, const T &rhs)
Calculates modulo.
friend fixed_point128 exp(const fixed_point128 &x) noexcept
Calculates the exponent of x: e Using the Maclaurin series expansion, the formula is: 1 2 3 x x x exp...
friend fixed_point128 sin(fixed_point128 x) noexcept
Calculate the Sine function Ultimately uses sin1() or cos1() with a reduced range of [-pi/4,...
constexpr ~fixed_point128() noexcept=default
Destructor.
static const fixed_point128 & golden_ratio() noexcept
Returns an instance of fixed_point128 with the value of the golden ratio.
friend fixed_point128 cos(fixed_point128 x) noexcept
Calculate the cosine function Ultimately uses sin1() or cos1() with a reduced range of [-pi/4,...
friend constexpr fixed_point128 operator|(const T &lhs, const fixed_point128 &rhs)
Performs bitwise OR of a scalar and a fixed_point128.
constexpr fixed_point128 & operator|=(const T &rhs)
Bitwise OR=.
constexpr bool is_int() const noexcept
Returns true if the value is an int (fraction is zero)
constexpr fixed_point128 & operator-=(const T &rhs) noexcept
Subtract a value to this object.
friend constexpr bool operator<(const fixed_point128 &lhs, const T &rhs) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend constexpr fixed_point128 operator+(const T &lhs, const fixed_point128 &rhs) noexcept
Adds a scalar and a fixed_point128, in that order.
constexpr fixed_point128 operator>>(T shift) const noexcept
Performs right shift operation.
constexpr fixed_point128 & operator*=(T x) noexcept
Multiplies a value to this object.
constexpr fixed_point128(fixed_point128 &&rhs) noexcept
Move constructor Doesn't modify the right hand side object. Acts like a copy constructor.
constexpr fixed_point128(const fixed_point128 &rhs) noexcept
Copy constructor.
constexpr fixed_point128 operator~() const noexcept
Bitwise not (~). Flips all 128 bits, the sign included, which makes it -x - epsilon().
friend fixed_point128 expm1(const fixed_point128 &x) noexcept
Calculates the exponent of x and reduces 1 from the result: (e^x) - 1 Evaluated as exp(x) - 1,...
friend constexpr uint64_t lzcnt128(const fixed_point128 &x) noexcept
Calculates the left zero count of value x, ignoring the sign. Counted on the magnitude,...
friend constexpr fixed_point128 floor(const fixed_point128 &x) noexcept
Performs the floor() function, similar to libc's floor(), rounds down towards -infinity.
friend constexpr bool operator!=(const fixed_point128 &lhs, const fixed_point128 &rhs) noexcept
Return true when objects are not equal. Can be used as logical XOR.
friend constexpr fixed_point128 sqr(fixed_point128 x) noexcept
Calculates the square of a value. i.e. x^2.
friend fixed_point128 hypot(const fixed_point128 &x, const fixed_point128 &y) noexcept
Calculates the hypotenuse. i.e. sqrt(x^2 + y^2)
constexpr fixed_point128 & operator+=(const T &rhs) noexcept
Add a value to this object.
friend constexpr fixed_point128 round(const fixed_point128 &x) noexcept
Rounds towards the nearest integer. The halfway value (0.5) is rounded away from zero.
friend fixed_point128 cosh(const fixed_point128 &x) noexcept
Calculate the hyperbolic cosine function e^x + e^(-x) cosh(x) = ---------— 2 Accuracy,...
friend constexpr int32_t ilogb(const fixed_point128 &x) noexcept
Retrieves an integer that represents the base-2 exponent of the specified value. floor(log2(|x|)),...
constexpr fixed_point128 & operator+=(const fixed_point128 &rhs) noexcept
Add a value to this object.
friend fixed_point128 sin1(fixed_point128 x) noexcept
Calculate the sine function over a limited range [-0.5pi, 0.5pi] Using the Maclaurin series expansion...
fixed_point128 & operator/=(const fixed_point128 &rhs)
Divide this object by x. The quotient is rounded to nearest, a tie going away from zero,...
friend std::istream & operator>>(std::istream &is, fixed_point128< J > &value)
constexpr fixed_point128(uint64_t x) noexcept
Constructor from uint64_t type A value of 2^I or above overflows into the sign and wraps silently.
friend class fixed_point128
constexpr fixed_point128 & operator-=(const fixed_point128 &rhs) noexcept
Subtract a value to this object.
friend constexpr bool operator<=(const fixed_point128 &lhs, const T &rhs) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend constexpr bool operator!=(const fixed_point128 &lhs, const T &rhs) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend constexpr fixed_point128 fabs(const fixed_point128 &x) noexcept
Returns the absolute value.
constexpr fixed_point128(int64_t x) noexcept
Constructor from int64_t type The shift is done in the unsigned domain, where it wraps rather than ov...
constexpr fixed_point128< I > & operator=(const fixed_point128< I2 > &rhs) noexcept
cross-template assignment operator, can be used between two different fixed_point128 templates Behave...
fixed_point128 & operator%=(const fixed_point128 &rhs)
%= operator, the remainder of a truncating division: x - y * trunc(x / y).
constexpr fixed_point128 & operator&=(const fixed_point128 &rhs) noexcept
Bitwise AND= The operators below work on all 128 bits, the sign bit included.
static const fixed_point128 & e() noexcept
friend constexpr bool operator>(const fixed_point128 &lhs, const T &rhs) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend fixed_point128 exp2(const fixed_point128 &x) noexcept
Computes 2 to the power of x exp(x * ln(2)), the constant applied with 128 fraction bits....
friend constexpr fixed_point128 fdim(const fixed_point128 &x, const fixed_point128 &y) noexcept
Determines the positive difference between the first and second values.
friend constexpr fixed_point128 operator&(const T &lhs, const fixed_point128 &rhs)
Performs bitwise AND of a scalar and a fixed_point128.
friend constexpr fixed_point128 copysign(const fixed_point128 &x, const fixed_point128 &y) noexcept
returns the value of x with the sign of y.
friend constexpr bool operator!=(const T &lhs, const fixed_point128 &rhs) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend constexpr fixed_point128 logb(fixed_point128 x)
Calculates Log base 2 of x as an integer ignoring the sign of x. floor(log2(fabs(x))),...
static const fixed_point128 & sqrt_2() noexcept
Returns an instance of fixed_point128 with the value of sqrt(2)
constexpr bool is_zero() const noexcept
Returns true if the value is zero.
friend fixed_point128 log1p(fixed_point128 x)
Calculates the natural Log (base e) of 1 + x: log(1 + x) Not noexcept: it forwards to log(),...
friend constexpr fixed_point128 operator|(fixed_point128 lhs, const T &rhs)
Performs bitwise OR (|)
static const fixed_point128 & pi() noexcept
Returns an instance of fixed_point128 with the value of pi Needs I to be 2 or more.
friend fixed_point128 tanh(const fixed_point128 &x) noexcept
Calculates the hyperbolic tangent e^x - e^(-x) 1 - e^(-2|x|) tanh(x) = ---------— = ------------—,...
fixed_point128 & operator/=(T x)
Divide this object by x.
friend constexpr fixed_point128 modf(const fixed_point128 &x, fixed_point128 *iptr) noexcept
Split into integer and fraction parts. Both results carry the sign of the input variable.
friend fixed_point128 operator/(fixed_point128 lhs, const T &rhs)
Divides this object by the right hand side operand and returns the result.
friend constexpr fixed_point128 operator*(fixed_point128 lhs, const T &rhs) noexcept
Multiplies the right hand side operand with this object to and returns the result.
constexpr fixed_point128(uint64_t l, uint64_t h) noexcept
Constructor from the two QWORDs of the raw value, useful for creating very small constants....
constexpr fixed_point128(uint32_t x) noexcept
Constructor from uint32_t type.
friend fixed_point128 asinh(const fixed_point128 &x) noexcept
Calculates the inverse hyperbolic sine For positive x: asinh(x) = log(x + sqrt(x^2 + 1)) For negative...
static constexpr fixed_point128 epsilon() noexcept
Return an instance of fixed_point128 with the smallest positive value possible.
friend fixed_point128 reciprocal(const fixed_point128 &x) noexcept
Calculates the reciprocal of a value. y = 1 / x.
friend constexpr bool operator>=(const T &lhs, const fixed_point128 &rhs) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend fixed_point128 atan(fixed_point128 x) noexcept
Calculate the inverse tangent function Accuracy, measured against mpmath at I = 1,...
constexpr bool is_positive() const noexcept
Returns true if the value is positive (including zero)
fixed_point128(const char *x) noexcept
Constructor from const char* (C string).
friend fixed_point128 atanh(const fixed_point128 &x) noexcept
Calculates the inverse hyperbolic tangent 1 + x atanh(x) = 0.5 * log( --—) = 0.5 * (log(1 + x) - log(...
constexpr fixed_point128 operator--(int32_t) noexcept
Postfix – operation (a–)
constexpr fixed_point128 & operator^=(const fixed_point128 &rhs) noexcept
Bitwise XOR=.
friend fixed_point128 acosh(const fixed_point128 &x) noexcept
Calculates the inverse hyperbolic cosine For x >= 1: acosh(x) = log(x + sqrt(x^2 - 1)) For x < 1,...
fixed_point128< I > & ref_type
friend constexpr fixed_point128 operator^(const T &lhs, const fixed_point128 &rhs)
Performs bitwise XOR of a scalar and a fixed_point128.
friend fixed_point128 pow(const fixed_point128 &x, const fixed_point128 &y) noexcept
Computes x to the power of y exp(y * log(x)). Accuracy, measured against mpmath at I = 1,...
friend constexpr fixed_point128 operator-(const T &lhs, const fixed_point128 &rhs) noexcept
Subtracts a fixed_point128 from a scalar.
friend constexpr bool operator<=(const T &lhs, const fixed_point128 &rhs) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
static constexpr fixed_point128 one() noexcept
Return an instance of fixed_point128 with the value of 1 These three exact constants are returned by ...
constexpr void get_components(uint64_t &l, uint64_t &h) const noexcept
Reads the raw representation: the two QWORDs of the 128 bit two's complement value.
static constexpr uint64_t max_int_value
fixed_point128< I > * ptr_type
Pointer type alias.
constexpr fixed_point128 & operator<<=(int32_t shift) noexcept
Shift left this object. A value shifted past the range of the type wraps silently,...
constexpr int32_t get_exponent() const noexcept
Returns the exponent of the object - like the base 2 exponent of a floating point A value of 2....
constexpr fixed_point128 operator++(int32_t) noexcept
Postfix ++ operation (a++)
friend fixed_point128 log10(fixed_point128 x)
Calculates Log base 10 of x: log10(x) log2(x) * log10(2), the constant applied with 128 fraction bits...
constexpr fixed_point128 & operator>>=(int32_t shift) noexcept
Shift right this object. The shift is arithmetic: the sign bit is replicated, so the result is the va...
friend fixed_point128 acos(fixed_point128 x) noexcept
Calculate the inverse cosine function pi/2 - asin(x) for |x| up to one half. Beyond that acos(x) = 2 ...
friend constexpr fixed_point128 operator>>(const T &lhs, const fixed_point128 &rhs) noexcept
Shifts a scalar right by a fixed_point128 shift count. The left operand is widened to fixed_point128 ...
friend constexpr fixed_point128 fmin(const fixed_point128 &x, const fixed_point128 &y) noexcept
Returns the minimum between x and y.
constexpr fixed_point128 & operator++() noexcept
Prefix ++ operation (++a)
friend constexpr bool operator==(const fixed_point128 &lhs, const T &rhs) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
constexpr fixed_point128 & operator&=(const T &rhs)
Bitwise AND=.
constexpr bool is_negative() const noexcept
Returns true if the value negative (smaller than zero)
constexpr fixed_point128(const fixed_point128< I2 > &rhs) noexcept
cross-template Copy constructor, can be used between two different fixed_point128 templates A value t...
friend constexpr bool operator>(const T &lhs, const fixed_point128 &rhs) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
constexpr bool operator!() const noexcept
Logical not (!). Opposite of operator bool.
friend constexpr fixed_point128 trunc(const fixed_point128 &x) noexcept
Rounds towards zero.
friend constexpr fixed_point128 operator&(fixed_point128 lhs, const T &rhs)
Performs bitwise AND (&)
friend fixed_point128 sinh(const fixed_point128 &x) noexcept
Calculate the hyperbolic sine function Use the exponent function which produces more accurate results...
friend fixed_point128 cos1(const fixed_point128 &x) noexcept
Calculate the cosine function over a limited range [-0.5pi, 0.5pi] Using the Maclaurin series expansi...
constexpr fixed_point128() noexcept
Default constructor, creates an instance with a value of zero.
friend void _sincos_cordic(fixed_point128 x, fixed_point128 &sin_x, fixed_point128 &cos_x, bool apply_scale_factor) noexcept
Calculate Sine and Cosine using CORDIC using a limited range of [-pi/2, pi/2] 64 iterations,...
friend constexpr bool operator<=(const fixed_point128 &lhs, const fixed_point128 &rhs) noexcept
Return true this object is small or equal than the rhs.
static constexpr float_denorm_style has_denorm
static constexpr value_type min() noexcept
Smallest positive value, which is one unit in the last place.
static constexpr bool has_infinity
static constexpr bool is_specialized
static constexpr value_type denorm_min() noexcept
No value is subnormal, so this is the smallest positive one, the same as min().
static constexpr int min_exponent
2^(min_exponent-1) = 2^(I-127) is the smallest positive value, epsilon().
static FP128_SUPPRESS_DEPRECATED_END constexpr float_round_style round_style
Multiplication, division (by a fixed_point128 or an integer), the right shift and the narrowing conve...
static constexpr value_type signaling_NaN() noexcept
static constexpr value_type epsilon() noexcept
Spacing of the grid, the same at every magnitude.
static constexpr int max_exponent
2^(max_exponent-1) = 2^(I-1) is the largest power of two in range; max() is 2^I - epsilon().
static constexpr bool traps
Division by zero throws std::logic_error rather than producing a value.
static constexpr value_type round_error() noexcept
Largest rounding error of an operation in units in the last place, one half.
static constexpr int max_digits10
Significant decimal digits that tell every pair of neighbouring values apart.
static constexpr bool is_bounded
static constexpr bool has_quiet_NaN
static constexpr bool is_signed
static constexpr bool is_exact
Every representable value is exactly the number it stands for.
static constexpr int min_exponent10
static constexpr bool is_iec559
static constexpr bool is_modulo
+, - and * wrap around: they keep the low 128 bits of the two's complement result,...
static constexpr int radix
static constexpr bool is_integer
static constexpr value_type quiet_NaN() noexcept
static constexpr value_type infinity() noexcept
static constexpr int max_exponent10
static constexpr int digits10
Decimal digits that survive a round trip: floor(127 * log10(2)).
static constexpr int digits
Value bits. One of the 128 is the sign, so 127 of them carry magnitude.
static constexpr bool has_signaling_NaN
static constexpr value_type lowest() noexcept
Most negative value, exactly -2^I. Two's complement makes the range asymmetric, so this one has no po...
static FP128_SUPPRESS_DEPRECATED_BEGIN constexpr bool has_denorm_loss
static constexpr bool tinyness_before
static constexpr value_type max() noexcept
Largest value, every bit below the sign set: 2^I - epsilon().
Exact conversion between binary128 and decimal.
Shared definitions, intrinsics, and helper functions for 128-bit fixed-point arithmetic.
#define FP128_SUPPRESS_DEPRECATED_END
Closes the region opened by FP128_SUPPRESS_DEPRECATED_BEGIN.
#define FP128_SUPPRESS_DEPRECATED_BEGIN
Opens a region in which the use of a deprecated declaration is not reported.
#define FP128_ONE_SHIFT(x)
#define FP128_ADD_ROUND_BIT(l, h, round_up)
Adds a rounding bit into a 128 bit value held as two QWORDs, as l and h are named there.
#define FP128_FLOAT_DIVIDE_BY_ZERO_EXCEPTION
#define FP128_GET_BIT(x, n)
#define FP128_GET_BITS(x, b, count)
#define FP128_MAX_VALUE_64(x)
#define FP128_FORCE_INLINE
Marks a function the compiler must inline rather than merely may.
#define FP128_USE_RECIPROCAL_FOR_DIVISION
Selects how fixed_point128 divides by a value that is neither a power of two nor an integer.
basic_big_uint< 560 > big_uint
The big integer every conversion uses, 560 limbs or 17920 bits.
Everything the library provides.
constexpr void shift_right128_inplace_safe(uint64_t &l, uint64_t &h, int shift) noexcept
Right shift of an unsigned 128 bit integer (inplace), rounded to nearest with a tie going up.
void fact_reciprocal(int x, fixed_point128< I > &res) noexcept
fixed_point128< I > sqrt(const fixed_point128< I > &x, uint32_t iterations=3) noexcept
constexpr uint32_t array_length(const T &a)
Calculates the element count of a C style array at build time Example: int a[5]; constexpr int len = ...
fixed_point128< I > atan(fixed_point128< I > x) noexcept
constexpr void mul128_high(uint64_t a_low, uint64_t a_high, uint64_t b_low, uint64_t b_high, uint64_t &res_low, uint64_t &res_high) noexcept
Upper 128 bits of the product of two 128 bit unsigned values.
fixed_point128< I > ceil(const fixed_point128< I > &x) noexcept
constexpr void shift_right128_inplace(uint64_t &l, uint64_t &h, int shift) noexcept
Right shift a 128 bit unsigned integer (inplace). Limited range, inplace and no parameter checks (che...
static bool div_64bit(uint64_t *q, uint64_t *r, const uint64_t *u, uint64_t v, int64_t m) noexcept
64 bit words unsigned divide function. Variation of the code from the book Hacker's Delight.
fixed_point128< I > hypot(const fixed_point128< I > &x, const fixed_point128< I > &y) noexcept
fixed_point128< I > asin(fixed_point128< I > x) noexcept
fixed_point128< I > cos(fixed_point128< I > x) noexcept
fixed_point128< I > exp2(const fixed_point128< I > &x) noexcept
constexpr int32_t log2_reduction_bits
Bits of argument reduction fixed_point128::log2() applies; log2_recip_table has 2^this entries.
fixed_point128< I > log2(fixed_point128< I > x) noexcept
constexpr void twos_complement128(uint64_t &l, uint64_t &h) noexcept
converts a 128 integer to negative via 2's complement.
uint64_t lzcnt128(const fixed_point128< I > &x) noexcept
constexpr uint64_t shift_left128(uint64_t l, uint64_t h) noexcept
Left shift a 128 bit integer. When shift is a compile time constant, this function generates optimal ...
int32_t ilogb(const fixed_point128< I > &x) noexcept
constexpr void shift_left128_inplace(uint64_t &l, uint64_t &h, int shift) noexcept
Left shift a 128 bit integer (inplace). Limited range, inplace and no parameter checks (checked via a...
static bool div_128bit(uint64_t *q, uint64_t *r, const uint64_t *u, const uint64_t *v) noexcept
Divides an unsigned integer of up to 256 bits by a 128 bit one. Knuth algorithm D,...
static constexpr int32_t flt_frac_bits
Mantissa bit count of an IEEE 754 float.
std::istream & operator>>(std::istream &is, fixed_point128< I > &value)
Reads a fixed_point128 from a stream, the way the builtin arithmetic extractors do.
constexpr uint64_t log2_recip_table[][2]
1/(1 + j/64) as a 128 bit fraction, the reciprocals fixed_point128::log2() reduces with.
bool Divide256By128(uint64_t *q, uint64_t *r, const uint64_t *u, const uint64_t *v) noexcept
Divides a 256 bit numerator by a 128 bit divisor: the one call of div_128bit() in this header.
fixed_point128< I > fmax(const fixed_point128< I > &x, const fixed_point128< I > &y) noexcept
fixed_point128< I > exp(const fixed_point128< I > &x) noexcept
fixed_point128< I > asinh(const fixed_point128< I > &x) noexcept
fixed_point128< I > atan2(fixed_point128< I > y, fixed_point128< I > x) noexcept
fixed_point128< I > modf(const fixed_point128< I > &x, fixed_point128< I > *iptr) noexcept
fixed_point128< I > tan(fixed_point128< I > x) noexcept
constexpr uint64_t fp128_trig_series_table[][2]
1 / (n(n+1)) for n = 1..40, with 125 fraction bits rounded to nearest, {high, low}...
fixed_point128< I > logb(fixed_point128< I > x) noexcept
fixed_point128< I > floor(const fixed_point128< I > &x) noexcept
fixed_point128< I > fmod(const fixed_point128< I > &x, const fixed_point128< I > &y)
fixed_point128< I > sinh(const fixed_point128< I > &x) noexcept
fixed_point128< I > fdim(const fixed_point128< I > &x, const fixed_point128< I > &y) noexcept
constexpr void shift_right128_inplace_safe_signed(uint64_t &l, uint64_t &h, int shift) noexcept
Arithmetic right shift of a 128 bit two's complement value (inplace), rounded to nearest with a tie g...
fixed_point128< I > round(const fixed_point128< I > &x) noexcept
fixed_point128< I > log1p(fixed_point128< I > x) noexcept
fixed_point128< I > sin(fixed_point128< I > x) noexcept
fixed_point128< I > copysign(const fixed_point128< I > &x, const fixed_point128< I > &y) noexcept
fixed_point128< I > log10(fixed_point128< I > x) noexcept
static constexpr int32_t dbl_frac_bits
Mantissa bit count of an IEEE 754 double.
fixed_point128< I > cosh(const fixed_point128< I > &x) noexcept
constexpr void shift_left128_inplace_safe(uint64_t &l, uint64_t &h, int shift) noexcept
Left shift a 128 bit integer (inplace). Handles any positive shift value.
std::ostream & operator<<(std::ostream &os, const fixed_point128< I > &value)
Writes a fixed_point128 to a stream, honouring its width, fill and adjustment.
fixed_point128< I > acos(fixed_point128< I > x) noexcept
fixed_point128< I > pow(const fixed_point128< I > &x, const fixed_point128< I > &y) noexcept
float128 remainder(const float128 &x, const float128 &y) noexcept
fixed_point128< I > tanh(const fixed_point128< I > &x) noexcept
fixed_point128< I > fabs(const fixed_point128< I > &x) noexcept
constexpr uint64_t log2_inv_n_table[][2]
1/(n*ln2) for n = 1 upwards, as a raw 128 bit value with 127 fraction bits; entry [i] holds 1/((i+1)*...
constexpr uint64_t shift_right128(uint64_t l, uint64_t h) noexcept
Right shift a 128 bit integer. When shift is a compile time constant, this function generates optimal...
constexpr uint64_t log2_value_table[][2]
-log2 of the matching log2_recip_table entry, as a 128 bit fraction.
fixed_point128< I > acosh(const fixed_point128< I > &x) noexcept
fixed_point128< I > trunc(const fixed_point128< I > &x) noexcept
fixed_point128< I > reciprocal(const fixed_point128< I > &x) noexcept
constexpr uint64_t popcnt128(uint64_t l, uint64_t h) noexcept
Counts the number of 1 bits (population count) in a 128-bit unsigned integer.
fixed_point128< I > fmin(const fixed_point128< I > &x, const fixed_point128< I > &y) noexcept
fixed_point128< I > expm1(const fixed_point128< I > &x) noexcept
fixed_point128< I > atanh(const fixed_point128< I > &x) noexcept
fixed_point128< I > log(fixed_point128< I > x) noexcept
Bit level view of an IEEE 754 double-precision value.
constexpr uint64_t f() const noexcept
Mantissa (fraction) bits.
constexpr uint64_t s() const noexcept
Sign bit (0 = positive, 1 = negative).
static constexpr double make(uint64_t s, uint64_t e, uint64_t f) noexcept
Assembles a double out of its three fields.
constexpr uint64_t e() const noexcept
Biased exponent bits.
static constexpr float make(uint32_t s, uint32_t e, uint32_t f) noexcept
Assembles a float out of its three fields, see Double::make().
size_t operator()(const fp128::fixed_point128< I > &value) const noexcept