@@ -12,6 +12,7 @@ use crate::typmod::Typmod;
12
12
use lazy_static:: lazy_static;
13
13
use std:: borrow:: Cow ;
14
14
use std:: convert:: { TryFrom , TryInto } ;
15
+ use std:: f64:: consts:: { LN_10 , LOG10_2 , LOG10_E } ;
15
16
use std:: fmt;
16
17
17
18
/// Limit on the precision (and hence scale) specifiable in a NUMERIC typmod.
@@ -1859,7 +1860,7 @@ impl<'a> NumericVar<'a> {
1859
1860
1860
1861
// We have self ~= digits * 10^dweight
1861
1862
// 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 ;
1863
1864
ln_dweight = ln_var. abs ( ) . log10 ( ) as i32 ;
1864
1865
} else {
1865
1866
ln_dweight = 0 ;
@@ -1928,7 +1929,7 @@ impl<'a> NumericVar<'a> {
1928
1929
}
1929
1930
1930
1931
// 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 ;
1932
1933
let mut ndiv2: i32 ;
1933
1934
1934
1935
// Reduce x to the range -0.01 <= x <= 0.01 (approximately) by dividing by
@@ -1958,7 +1959,6 @@ impl<'a> NumericVar<'a> {
1958
1959
// raise the Taylor series result to the power 2^ndiv2, which introduces
1959
1960
// an error of up to around log10(2^ndiv2) digits, so work with this many
1960
1961
// extra digits of precision (plus a few more for good measure).
1961
- const LOG10_2 : f64 = 0.301_029_995_663_981_f64 ;
1962
1962
let mut sig_digits = 1 + dweight + rscale + ( ndiv2 as f64 * LOG10_2 ) as i32 ;
1963
1963
sig_digits = sig_digits. max ( 0 ) + 8 ;
1964
1964
@@ -2068,7 +2068,7 @@ impl<'a> NumericVar<'a> {
2068
2068
return None ;
2069
2069
}
2070
2070
2071
- val *= std :: f64 :: consts :: LOG10_E ; // approximate decimal result weight
2071
+ val *= LOG10_E ; // approximate decimal result weight
2072
2072
2073
2073
// choose the result scale
2074
2074
let rscale = ( NUMERIC_MIN_SIG_DIGITS - val as i32 )
@@ -2555,7 +2555,7 @@ impl<'a> NumericVar<'a> {
2555
2555
2556
2556
// log10(result) = num * log10(e), so this is approximately the decimal
2557
2557
// weight of the result:
2558
- val *= std :: f64 :: consts :: LOG10_E ;
2558
+ val *= LOG10_E ;
2559
2559
2560
2560
// limit to something that won't cause integer overflow
2561
2561
val = val
0 commit comments