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

Function adjusted_mantissa negative_digit_comp

Source/external/fast_float.h:3025–3070  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3023// are of the same magnitude.
3024template <typename T>
3025inline FASTFLOAT_CONSTEXPR20
3026adjusted_mantissa negative_digit_comp(bigint& bigmant, adjusted_mantissa am, int32_t exponent) noexcept {
3027 bigint& real_digits = bigmant;
3028 int32_t real_exp = exponent;
3029
3030 // get the value of `b`, rounded down, and get a bigint representation of b+h
3031 adjusted_mantissa am_b = am;
3032 // gcc7 buf: use a lambda to remove the noexcept qualifier bug with -Wnoexcept-type.
3033 round<T>(am_b, [](adjusted_mantissa&a, int32_t shift) { round_down(a, shift); });
3034 T b;
3035 to_float(false, am_b, b);
3036 adjusted_mantissa theor = to_extended_halfway(b);
3037 bigint theor_digits(theor.mantissa);
3038 int32_t theor_exp = theor.power2;
3039
3040 // scale real digits and theor digits to be same power.
3041 int32_t pow2_exp = theor_exp - real_exp;
3042 uint32_t pow5_exp = uint32_t(-real_exp);
3043 if (pow5_exp != 0) {
3044 FASTFLOAT_ASSERT(theor_digits.pow5(pow5_exp));
3045 }
3046 if (pow2_exp > 0) {
3047 FASTFLOAT_ASSERT(theor_digits.pow2(uint32_t(pow2_exp)));
3048 } else if (pow2_exp < 0) {
3049 FASTFLOAT_ASSERT(real_digits.pow2(uint32_t(-pow2_exp)));
3050 }
3051
3052 // compare digits, and use it to director rounding
3053 int ord = real_digits.compare(theor_digits);
3054 adjusted_mantissa answer = am;
3055 round<T>(answer, [ord](adjusted_mantissa& a, int32_t shift) {
3056 round_nearest_tie_even(a, shift, [ord](bool is_odd, bool _, bool __) -> bool {
3057 (void)_; // not needed, since we've done our comparison
3058 (void)__; // not needed, since we've done our comparison
3059 if (ord > 0) {
3060 return true;
3061 } else if (ord < 0) {
3062 return false;
3063 } else {
3064 return is_odd;
3065 }
3066 });
3067 });
3068
3069 return answer;
3070}
3071
3072// parse the significant digits as a big integer to unambiguously round the
3073// the significant digits. here, we are trying to determine how to round

Callers

nothing calls this directly

Calls 7

round_downFunction · 0.85
to_floatFunction · 0.85
to_extended_halfwayFunction · 0.85
round_nearest_tie_evenFunction · 0.85
pow5Method · 0.80
pow2Method · 0.80
compareMethod · 0.80

Tested by

no test coverage detected