MCPcopy Create free account
hub / github.com/apache/arrow / ToRealPositive

Method ToRealPositive

cpp/src/arrow/util/decimal.cc:1407–1423  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1405 /// Here "exact value" means the closest representable value by Real.
1406 template <typename Real>
1407 static Real ToRealPositive(const Decimal256& decimal, int32_t scale) {
1408 const auto parts_le = decimal.little_endian_array();
1409 if (scale <= 0 || (parts_le[3] == 0 && parts_le[2] == 0 && parts_le[1] == 0 &&
1410 parts_le[0] < RealTraits<Real>::kMaxPreciseInteger)) {
1411 // No need to split the decimal if it is already an integer (scale <= 0) or if it
1412 // can be precisely represented by Real
1413 return ToRealPositiveNoSplit<Real>(decimal, scale);
1414 }
1415
1416 // Split the decimal into whole and fractional parts to avoid precision loss
1417 BasicDecimal256 whole_decimal, fraction_decimal;
1418 decimal.GetWholeAndFraction(scale, &whole_decimal, &fraction_decimal);
1419
1420 Real whole = ToRealPositiveNoSplit<Real>(whole_decimal, 0);
1421 Real fraction = ToRealPositiveNoSplit<Real>(fraction_decimal, scale);
1422 return whole + fraction;
1423 }
1424};
1425
1426} // namespace

Callers

nothing calls this directly

Calls 2

little_endian_arrayMethod · 0.80
GetWholeAndFractionMethod · 0.80

Tested by

no test coverage detected