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

Function log_decimal64

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

Calculate logarithm for Decimal64 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: i64, scale: i8, base: f64)

Source from the content-addressed store, hash-verified

128/// For integer bases >= 2 with zero scale, return an exact integer log when the
129/// value is a perfect power of the base. Otherwise falls back to f64 computation.
130fn log_decimal64(value: i64, scale: i8, base: f64) -> Result<f64, ArrowError> {
131 if scale == 0
132 && is_valid_integer_base(base)
133 && let Ok(unscaled) = u64::try_from(value)
134 && unscaled > 0
135 {
136 let base_u64 = base as u64;
137 let int_log = unscaled.ilog(base_u64);
138 if base_u64.checked_pow(int_log) == Some(unscaled) {
139 return Ok(int_log as f64);
140 }
141 }
142 decimal_to_f64(value, scale).map(|v| v.log(base))
143}
144
145/// Calculate logarithm for Decimal128 values.
146/// For integer bases >= 2 with zero scale, return an exact integer log when the

Callers 1

invoke_with_argsMethod · 0.85

Calls 4

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…