@@ -144,7 +144,7 @@ def cbrt(x, prec)
144144 x = -x if neg = x < 0
145145 ex = x . exponent / 3
146146 x = x . _decimal_shift ( -3 * ex )
147- y = BigDecimal ( Math . cbrt ( x . to_f ) , 0 )
147+ y = BigDecimal ( Math . cbrt ( BigDecimal :: Internal . fast_to_f ( x ) ) , 0 )
148148 BigDecimal ::Internal . newton_loop ( prec + BigDecimal ::Internal ::EXTRA_PREC ) do |p |
149149 y = ( 2 * y + x . div ( y , p ) . div ( y , p ) ) . div ( 3 , p )
150150 end
@@ -304,7 +304,7 @@ def atan(x, prec)
304304
305305 # Solve tan(y) - x = 0 with Newton's method
306306 # Repeat: y -= (tan(y) - x) * cos(y)**2
307- y = BigDecimal ( Math . atan ( x . to_f ) , 0 )
307+ y = BigDecimal ( Math . atan ( BigDecimal :: Internal . fast_to_f ( x ) ) , 0 )
308308 BigDecimal ::Internal . newton_loop ( n ) do |p |
309309 s = sin ( y , p )
310310 c = ( 1 - s * s ) . sqrt ( p )
@@ -605,7 +605,7 @@ def erf(x, prec)
605605 return BigDecimal ( 1 ) if x > 5000000000 # erf(5000000000) > 1 - 1e-10000000000000000000
606606
607607 if x > 8
608- xf = x . to_f
608+ xf = BigDecimal :: Internal . fast_to_f ( x )
609609 log10_erfc = -xf ** 2 / Math . log ( 10 ) - Math . log10 ( xf * Math ::PI ** 0.5 )
610610 erfc_prec = [ prec + log10_erfc . ceil , 1 ] . max
611611 erfc = _erfc_asymptotic ( x , erfc_prec )
@@ -647,7 +647,7 @@ def erfc(x, prec)
647647 # erfc(x) = 1 - erf(x) < exp(-x**2)/x/sqrt(pi)
648648 # Precision of erf(x) needs about log10(exp(-x**2)/x/sqrt(pi)) extra digits
649649 log10 = 2.302585092994046
650- xf = x . to_f
650+ xf = BigDecimal :: Internal . fast_to_f ( x )
651651 high_prec = prec + BigDecimal ::Internal ::EXTRA_PREC + ( ( xf **2 + Math . log ( xf ) + Math . log ( Math ::PI ) /2 ) / log10 ) . ceil
652652 BigDecimal ( 1 ) . sub ( erf ( x , high_prec ) , prec )
653653 end
@@ -698,7 +698,7 @@ def erfc(x, prec)
698698 # sqrt(2)/2 + k*log(k) - k - 2*k*log(x) < -prec*log(10)
699699 # and the left side is minimized when k = x**2.
700700 prec += BigDecimal ::Internal ::EXTRA_PREC
701- xf = x . to_f
701+ xf = BigDecimal :: Internal . fast_to_f ( x )
702702 kmax = ( 1 ..( xf ** 2 ) . floor ) . bsearch do |k |
703703 Math . log ( 2 ) / 2 + k * Math . log ( k ) - k - 2 * k * Math . log ( xf ) < -prec * Math . log ( 10 )
704704 end
0 commit comments