MCPcopy Create free account
hub / github.com/apache/fory / decimal_from_float64

Function decimal_from_float64

cpp/fory/serialization/compatible_scalar.cc:630–647  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

628}
629
630bool 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
649bool decimal_from_float16(float16_t value, Decimal &out) {
650 uint16_t bits = value.to_bits();

Callers 3

scalar_to_decimalFunction · 0.85
decimal_to_float64Function · 0.85
scalar_to_stringFunction · 0.85

Calls 2

decimal_from_float_bitsFunction · 0.85
DecimalClass · 0.70

Tested by

no test coverage detected