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

Method IncreaseScaleWithOverflowCheck

cpp/src/gandiva/decimal_ir.cc:142–162  ·  view source on GitHub ↗

CPP: return (increase_scale_by <= 0) ? {in_value,false} : {in_value * GetScaleMultiplier(increase_scale_by),true} The return value also indicates if there was an overflow while increasing the scale.

Source from the content-addressed store, hash-verified

140//
141// The return value also indicates if there was an overflow while increasing the scale.
142DecimalIR::ValueWithOverflow DecimalIR::IncreaseScaleWithOverflowCheck(
143 llvm::Value* in_value, llvm::Value* increase_scale_by) {
144 llvm::Value* le_zero =
145 ir_builder()->CreateICmpSLE(increase_scale_by, types()->i32_constant(0));
146
147 // then block
148 auto then_lambda = [&] {
149 ValueWithOverflow ret{in_value, types()->false_constant()};
150 return ret.AsStruct(this);
151 };
152
153 // else block
154 auto else_lambda = [&] {
155 llvm::Value* multiplier = GetScaleMultiplier(increase_scale_by);
156 return ir_builder()->CreateCall(smul_with_overflow_fn_, {in_value, multiplier});
157 };
158
159 auto ir_struct =
160 BuildIfElse(le_zero, i128_with_overflow_struct_type_, then_lambda, else_lambda);
161 return ValueWithOverflow::MakeFromStruct(this, ir_struct);
162}
163
164// CPP: return (reduce_scale_by <= 0) ?
165// in_value : in_value / GetScaleMultiplier(reduce_scale_by)

Callers

nothing calls this directly

Calls 4

GetScaleMultiplierFunction · 0.85
AsStructMethod · 0.80
ir_builderFunction · 0.70
typesFunction · 0.70

Tested by

no test coverage detected