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

Function decimal_from_float32

cpp/fory/serialization/compatible_scalar.cc:611–628  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

609}
610
611bool decimal_from_float32(float value, Decimal &out) {
612 uint32_t bits = 0;
613 std::memcpy(&bits, &value, sizeof(bits));
614 const bool negative = (bits & 0x80000000u) != 0;
615 const uint32_t exp_bits = (bits >> 23) & 0xffu;
616 uint32_t frac = bits & 0x7fffffu;
617 if (exp_bits == 0 && frac == 0) {
618 out = Decimal();
619 return true;
620 }
621 uint64_t significand = frac;
622 int32_t exponent = -149;
623 if (exp_bits != 0) {
624 significand |= uint64_t{1} << 23;
625 exponent = static_cast<int32_t>(exp_bits) - 127 - 23;
626 }
627 return decimal_from_float_bits(negative, significand, exponent, out);
628}
629
630bool decimal_from_float64(double value, Decimal &out) {
631 uint64_t bits = 0;

Callers 3

scalar_to_decimalFunction · 0.85
decimal_to_float32Function · 0.85
scalar_to_stringFunction · 0.85

Calls 2

decimal_from_float_bitsFunction · 0.85
DecimalClass · 0.70

Tested by

no test coverage detected