@@ -132,9 +132,9 @@ impl CalculationJob {
132132 let prec = consts. float_precision ;
133133 let calc_num = match num {
134134 CalculationResult :: Approximate ( base, exponent) => {
135- let res = base . as_float ( ) * Float :: with_val ( prec , 10 ) . pow ( & exponent ) ;
136- if Float :: is_finite ( & ( res . clone ( ) * math :: APPROX_FACT_SAFE_UPPER_BOUND_FACTOR ) ) {
137- res . to_integer ( ) . unwrap ( )
135+ if exponent <= consts . integer_construction_limit {
136+ let x : Float = base . as_float ( ) * Float :: with_val ( prec , 10 ) . pow ( & exponent ) ;
137+ x . to_integer ( ) . unwrap ( )
138138 } else {
139139 return Some ( if base. as_float ( ) < & 0.0 {
140140 CalculationResult :: ComplexInfinity
@@ -143,7 +143,11 @@ impl CalculationJob {
143143 ( Float :: from ( base) , exponent) ,
144144 -level as u32 ,
145145 ) ;
146- CalculationResult :: Approximate ( termial. 0 . into ( ) , termial. 1 )
146+ if termial. 0 == 1 {
147+ CalculationResult :: ApproximateDigits ( false , termial. 1 )
148+ } else {
149+ CalculationResult :: Approximate ( termial. 0 . into ( ) , termial. 1 )
150+ }
147151 } else {
148152 let mut exponent = exponent;
149153 exponent. add_from ( math:: length ( & exponent, prec) ) ;
@@ -152,17 +156,32 @@ impl CalculationJob {
152156 }
153157 }
154158 CalculationResult :: ApproximateDigits ( was_neg, digits) => {
155- return Some ( if digits. is_negative ( ) {
156- CalculationResult :: Float ( Float :: new ( prec) . into ( ) )
157- } else if was_neg {
158- CalculationResult :: ComplexInfinity
159- } else if level < 0 {
160- CalculationResult :: ApproximateDigits ( false , ( digits - 1 ) * 2 + 1 )
159+ if digits <= consts. integer_construction_limit {
160+ let x: Float = Float :: with_val ( prec, 10 ) . pow ( digits. clone ( ) - 1 ) ;
161+ x. to_integer ( ) . unwrap ( )
161162 } else {
162- let mut digits = digits;
163- digits. add_from ( math:: length ( & digits, prec) ) ;
164- CalculationResult :: ApproximateDigitsTower ( false , false , 1 . into ( ) , digits)
165- } ) ;
163+ return Some ( if digits. is_negative ( ) {
164+ CalculationResult :: Float ( Float :: new ( prec) . into ( ) )
165+ } else if was_neg {
166+ CalculationResult :: ComplexInfinity
167+ } else if level < 0 {
168+ let mut one = Float :: with_val ( consts. float_precision , 1 ) ;
169+ if was_neg {
170+ one *= -1 ;
171+ }
172+ let termial =
173+ math:: approximate_approx_termial ( ( one, digits) , -level as u32 ) ;
174+ if termial. 0 == 1 {
175+ CalculationResult :: ApproximateDigits ( false , termial. 1 )
176+ } else {
177+ CalculationResult :: Approximate ( termial. 0 . into ( ) , termial. 1 )
178+ }
179+ } else {
180+ let mut digits = digits;
181+ digits. add_from ( math:: length ( & digits, prec) ) ;
182+ CalculationResult :: ApproximateDigitsTower ( false , false , 1 . into ( ) , digits)
183+ } ) ;
184+ }
166185 }
167186 CalculationResult :: ApproximateDigitsTower ( was_neg, neg, depth, exponent) => {
168187 return Some ( if neg {
0 commit comments