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

Function decimal_from_float_bits

cpp/fory/serialization/compatible_scalar.cc:592–609  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

590}
591
592bool decimal_from_float_bits(bool negative, uint64_t significand,
593 int32_t exponent, Decimal &out) {
594 BigUInt magnitude = BigUInt::from_uint64(significand);
595 if (exponent >= 0) {
596 for (int32_t i = 0; i < exponent; ++i) {
597 magnitude.multiply(2);
598 }
599 return canonical_decimal(std::move(magnitude), negative, 0, out);
600 }
601 const int32_t scale = -exponent;
602 if (scale > MAX_COMPATIBLE_DECIMAL_DIGITS) {
603 return false;
604 }
605 for (int32_t i = 0; i < scale; ++i) {
606 magnitude.multiply(5);
607 }
608 return canonical_decimal(std::move(magnitude), negative, scale, out);
609}
610
611bool decimal_from_float32(float value, Decimal &out) {
612 uint32_t bits = 0;

Callers 4

decimal_from_float32Function · 0.85
decimal_from_float64Function · 0.85
decimal_from_float16Function · 0.85
decimal_from_bfloat16Function · 0.85

Calls 2

canonical_decimalFunction · 0.70
multiplyMethod · 0.45

Tested by

no test coverage detected