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

Function decimal_from_bfloat16

cpp/fory/serialization/compatible_scalar.cc:667–683  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

665}
666
667bool decimal_from_bfloat16(bfloat16_t value, Decimal &out) {
668 uint16_t bits = value.to_bits();
669 const bool negative = (bits & 0x8000u) != 0;
670 const uint16_t exp_bits = (bits >> 7) & 0xffu;
671 uint16_t frac = bits & 0x007fu;
672 if (exp_bits == 0 && frac == 0) {
673 out = Decimal();
674 return true;
675 }
676 uint64_t significand = frac;
677 int32_t exponent = -133;
678 if (exp_bits != 0) {
679 significand |= uint64_t{1} << 7;
680 exponent = static_cast<int32_t>(exp_bits) - 127 - 7;
681 }
682 return decimal_from_float_bits(negative, significand, exponent, out);
683}
684
685bool decimal_plain_string(const Decimal &decimal, std::string &out) {
686 Decimal canonical;

Callers 3

scalar_to_decimalFunction · 0.85
decimal_to_bfloat16Function · 0.85
scalar_to_stringFunction · 0.85

Calls 3

decimal_from_float_bitsFunction · 0.85
DecimalClass · 0.70
to_bitsMethod · 0.45

Tested by

no test coverage detected