Skip to content
This repository was archived by the owner on Jan 17, 2024. It is now read-only.

Commit 3990696

Browse files
committed
Use std::f64::consts.
1 parent 6a161d6 commit 3990696

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/var.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::typmod::Typmod;
1212
use lazy_static::lazy_static;
1313
use std::borrow::Cow;
1414
use std::convert::{TryFrom, TryInto};
15+
use std::f64::consts::{LN_10, LOG10_2, LOG10_E};
1516
use std::fmt;
1617

1718
/// Limit on the precision (and hence scale) specifiable in a NUMERIC typmod.
@@ -1859,7 +1860,7 @@ impl<'a> NumericVar<'a> {
18591860

18601861
// We have self ~= digits * 10^dweight
18611862
// so ln(self) ~= ln(digits) + dweight * ln(10)
1862-
let ln_var = (digits as f64).ln() + dweight as f64 * std::f64::consts::LN_10;
1863+
let ln_var = (digits as f64).ln() + dweight as f64 * LN_10;
18631864
ln_dweight = ln_var.abs().log10() as i32;
18641865
} else {
18651866
ln_dweight = 0;
@@ -1928,7 +1929,7 @@ impl<'a> NumericVar<'a> {
19281929
}
19291930

19301931
// decimal weight = log10(e^x) = x * log10(e)
1931-
let dweight = (val * std::f64::consts::LOG10_E) as i32;
1932+
let dweight = (val * LOG10_E) as i32;
19321933
let mut ndiv2: i32;
19331934

19341935
// Reduce x to the range -0.01 <= x <= 0.01 (approximately) by dividing by
@@ -1958,7 +1959,6 @@ impl<'a> NumericVar<'a> {
19581959
// raise the Taylor series result to the power 2^ndiv2, which introduces
19591960
// an error of up to around log10(2^ndiv2) digits, so work with this many
19601961
// extra digits of precision (plus a few more for good measure).
1961-
const LOG10_2: f64 = 0.301_029_995_663_981_f64;
19621962
let mut sig_digits = 1 + dweight + rscale + (ndiv2 as f64 * LOG10_2) as i32;
19631963
sig_digits = sig_digits.max(0) + 8;
19641964

@@ -2068,7 +2068,7 @@ impl<'a> NumericVar<'a> {
20682068
return None;
20692069
}
20702070

2071-
val *= std::f64::consts::LOG10_E; // approximate decimal result weight
2071+
val *= LOG10_E; // approximate decimal result weight
20722072

20732073
// choose the result scale
20742074
let rscale = (NUMERIC_MIN_SIG_DIGITS - val as i32)
@@ -2555,7 +2555,7 @@ impl<'a> NumericVar<'a> {
25552555

25562556
// log10(result) = num * log10(e), so this is approximately the decimal
25572557
// weight of the result:
2558-
val *= std::f64::consts::LOG10_E;
2558+
val *= LOG10_E;
25592559

25602560
// limit to something that won't cause integer overflow
25612561
val = val

0 commit comments

Comments
 (0)