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.
| 2484 | // effect on performance: in order to have a faster algorithm, we'd need |
| 2485 | // to slow down performance for faster algorithms, and this is still fast. |
| 2486 | fastfloat_really_inline int32_t scientific_exponent(parsed_number_string& num) noexcept { |
| 2487 | uint64_t mantissa = num.mantissa; |
| 2488 | int32_t exponent = int32_t(num.exponent); |
| 2489 | while (mantissa >= 10000) { |
| 2490 | mantissa /= 10000; |
| 2491 | exponent += 4; |
| 2492 | } |
| 2493 | while (mantissa >= 100) { |
| 2494 | mantissa /= 100; |
| 2495 | exponent += 2; |
| 2496 | } |
| 2497 | while (mantissa >= 10) { |
| 2498 | mantissa /= 10; |
| 2499 | exponent += 1; |
| 2500 | } |
| 2501 | return exponent; |
| 2502 | } |
| 2503 | |
| 2504 | // this converts a native floating-point number to an extended-precision float. |
| 2505 | template <typename T> |