MCPcopy Create free account
hub / github.com/apache/datafusion / log_decimal128

Function log_decimal128

datafusion/functions/src/math/log.rs:148–161  ·  view source on GitHub ↗

Calculate logarithm for Decimal128 values. For integer bases >= 2 with zero scale, return an exact integer log when the value is a perfect power of the base. Otherwise falls back to f64 computation.

(value: i128, scale: i8, base: f64)

Source from the content-addressed store, hash-verified

146/// For integer bases >= 2 with zero scale, return an exact integer log when the
147/// value is a perfect power of the base. Otherwise falls back to f64 computation.
148fn log_decimal128(value: i128, scale: i8, base: f64) -> Result<f64, ArrowError> {
149 if scale == 0
150 && is_valid_integer_base(base)
151 && let Ok(unscaled) = u128::try_from(value)
152 && unscaled > 0
153 {
154 let base_u128 = base as u128;
155 let int_log = unscaled.ilog(base_u128);
156 if base_u128.checked_pow(int_log) == Some(unscaled) {
157 return Ok(int_log as f64);
158 }
159 }
160 decimal_to_f64(value, scale).map(|v| v.log(base))
161}
162
163/// Convert a scaled decimal value to f64.
164#[inline]

Callers 3

log_decimal256Function · 0.85
invoke_with_argsMethod · 0.85
test_log_decimal_nativeFunction · 0.85

Calls 4

is_valid_integer_baseFunction · 0.85
decimal_to_f64Function · 0.85
logMethod · 0.80
mapMethod · 0.45

Tested by 1

test_log_decimal_nativeFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…