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

Method ToRealPositive

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

Source from the content-addressed store, hash-verified

474 /// Here "exact value" means the closest representable value by Real.
475 template <typename Real>
476 static Real ToRealPositive(const Decimal128& decimal, int32_t scale) {
477 if (scale <= 0 || (decimal.high_bits() == 0 &&
478 decimal.low_bits() <= RealTraits<Real>::kMaxPreciseInteger)) {
479 // No need to split the decimal if it is already an integer (scale <= 0) or if it
480 // can be precisely represented by Real
481 return ToRealPositiveNoSplit<Real>(decimal, scale);
482 }
483
484 // Split decimal into whole and fractional parts to avoid precision loss
485 BasicDecimal128 whole_decimal, fraction_decimal;
486 decimal.GetWholeAndFraction(scale, &whole_decimal, &fraction_decimal);
487
488 Real whole = ToRealPositiveNoSplit<Real>(whole_decimal, 0);
489 Real fraction = ToRealPositiveNoSplit<Real>(fraction_decimal, scale);
490
491 return whole + fraction;
492 }
493};
494
495} // namespace

Callers

nothing calls this directly

Calls 1

GetWholeAndFractionMethod · 0.80

Tested by

no test coverage detected