MCPcopy Create free account
hub / github.com/Open-GD/OpenGD / round_nearest_tie_even

Function round_nearest_tie_even

Source/external/fast_float.h:2808–2832  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2806
2807template <typename callback>
2808fastfloat_really_inline FASTFLOAT_CONSTEXPR14
2809void round_nearest_tie_even(adjusted_mantissa& am, int32_t shift, callback cb) noexcept {
2810 const uint64_t mask
2811 = (shift == 64)
2812 ? UINT64_MAX
2813 : (uint64_t(1) << shift) - 1;
2814 const uint64_t halfway
2815 = (shift == 0)
2816 ? 0
2817 : uint64_t(1) << (shift - 1);
2818 uint64_t truncated_bits = am.mantissa & mask;
2819 bool is_above = truncated_bits > halfway;
2820 bool is_halfway = truncated_bits == halfway;
2821
2822 // shift digits into position
2823 if (shift == 64) {
2824 am.mantissa = 0;
2825 } else {
2826 am.mantissa >>= shift;
2827 }
2828 am.power2 += shift;
2829
2830 bool is_odd = (am.mantissa & 1) == 1;
2831 am.mantissa += uint64_t(cb(is_odd, is_halfway, is_above));
2832}
2833
2834fastfloat_really_inline FASTFLOAT_CONSTEXPR14
2835void round_down(adjusted_mantissa& am, int32_t shift) noexcept {

Calls

no outgoing calls

Tested by

no test coverage detected