From cb3c263c4a67f4d361dbdb5048a1c073bd1fff96 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 13 Mar 2023 20:10:29 +0100 Subject: [PATCH] More accurate logarithm for base 2 and 10 --- library/src/compute/calc.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/library/src/compute/calc.rs b/library/src/compute/calc.rs index 25df817d1..7fcc61316 100644 --- a/library/src/compute/calc.rs +++ b/library/src/compute/calc.rs @@ -366,7 +366,13 @@ pub fn log( #[default(10.0)] base: f64, ) -> Value { - Value::Float(value.log(base)) + Value::Float(if base == 2.0 { + value.log2() + } else if base == 10.0 { + value.log10() + } else { + value.log(base) + }) } /// Round a number down to the nearest integer.