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

Function scientific_exponent

Source/external/fast_float.h:2713–2730  ·  view source on GitHub ↗

calculate the exponent, in scientific notation, of the number. this algorithm is not even close to optimized, but it has no practical effect on performance: in order to have a faster algorithm, we'd need to slow down performance for faster algorithms, and this is still fast.

Source from the content-addressed store, hash-verified

2711// effect on performance: in order to have a faster algorithm, we'd need
2712// to slow down performance for faster algorithms, and this is still fast.
2713fastfloat_really_inline FASTFLOAT_CONSTEXPR14
2714int32_t scientific_exponent(parsed_number_string& num) noexcept {
2715 uint64_t mantissa = num.mantissa;
2716 int32_t exponent = int32_t(num.exponent);
2717 while (mantissa >= 10000) {
2718 mantissa /= 10000;
2719 exponent += 4;
2720 }
2721 while (mantissa >= 100) {
2722 mantissa /= 100;
2723 exponent += 2;
2724 }
2725 while (mantissa >= 10) {
2726 mantissa /= 10;
2727 exponent += 1;
2728 }
2729 return exponent;
2730}
2731
2732// this converts a native floating-point number to an extended-precision float.
2733template <typename T>

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected