| 628 | } |
| 629 | |
| 630 | bool decimal_from_float64(double value, Decimal &out) { |
| 631 | uint64_t bits = 0; |
| 632 | std::memcpy(&bits, &value, sizeof(bits)); |
| 633 | const bool negative = (bits & 0x8000000000000000ULL) != 0; |
| 634 | const uint64_t exp_bits = (bits >> 52) & 0x7ffULL; |
| 635 | uint64_t frac = bits & 0xfffffffffffffULL; |
| 636 | if (exp_bits == 0 && frac == 0) { |
| 637 | out = Decimal(); |
| 638 | return true; |
| 639 | } |
| 640 | uint64_t significand = frac; |
| 641 | int32_t exponent = -1074; |
| 642 | if (exp_bits != 0) { |
| 643 | significand |= uint64_t{1} << 52; |
| 644 | exponent = static_cast<int32_t>(exp_bits) - 1023 - 52; |
| 645 | } |
| 646 | return decimal_from_float_bits(negative, significand, exponent, out); |
| 647 | } |
| 648 | |
| 649 | bool decimal_from_float16(float16_t value, Decimal &out) { |
| 650 | uint16_t bits = value.to_bits(); |
no test coverage detected