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

Method ToRealPositive

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

little_endian_arrayMethod · 0.80
GetWholeAndFractionMethod · 0.80

Tested by

no test coverage detected