Skip to content

Commit 2ee51d6

Browse files
committed
Support non-integer bases in decimal log and handle large Decimal256 values
1 parent dbb6603 commit 2ee51d6

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

datafusion/functions/src/math/log.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ where
125125
{
126126
return if unscaled > 0 {
127127
Ok(unscaled.ilog(base as u128) as f64)
128-
} else {
129-
Ok(f64::NAN)
128+
} else {
129+
Ok(f64::NAN)
130130
};
131131
}
132132

@@ -1192,7 +1192,7 @@ mod tests {
11921192
assert!(
11931193
log_result.is_finite() && log_result > 0.0,
11941194
"Expected positive finite log result, got {log_result}"
1195-
);
1195+
);
11961196
}
11971197
ColumnarValue::Scalar(_) => {
11981198
panic!("Expected an array value")

datafusion/sqllogictest/test_files/decimal.slt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,9 +861,11 @@ select log(100000000000000000000000000000000000::decimal(76,0));
861861
----
862862
35
863863

864-
# log(10^50) for decimal256 for a value larger than i128
865-
query error Arrow error: Not yet implemented: Log of Decimal256 larger than Decimal128 is not yet supported
864+
# log(10^50) for decimal256 for a value larger than i128 (uses f64 fallback)
865+
query R
866866
select log(100000000000000000000000000000000000000000000000000::decimal(76,0));
867+
----
868+
50
867869

868870
# log(10^35) for decimal128 with explicit base
869871
query R

0 commit comments

Comments
 (0)