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

Method FromReal

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

Source from the content-addressed store, hash-verified

240
241 template <typename Real>
242 static Result<DecimalType> FromReal(Real x, int32_t precision, int32_t scale) {
243 DCHECK_GT(precision, 0);
244 DCHECK_LE(precision, kMaxPrecision);
245 DCHECK_GE(scale, -kMaxScale);
246 DCHECK_LE(scale, kMaxScale);
247
248 if (!std::isfinite(x)) {
249 return Status::Invalid("Cannot convert ", x, " to Decimal128");
250 }
251 if (x == 0) {
252 return DecimalType{};
253 }
254 if (x < 0) {
255 ARROW_ASSIGN_OR_RAISE(auto dec, FromPositiveReal(-x, precision, scale));
256 return dec.Negate();
257 } else {
258 return FromPositiveReal(x, precision, scale);
259 }
260 }
261
262 template <typename Real>
263 static Real ToReal(const DecimalType& decimal, int32_t scale) {

Callers

nothing calls this directly

Calls 2

NegateMethod · 0.80
InvalidFunction · 0.50

Tested by

no test coverage detected