@@ -7,14 +7,13 @@ use statrs::function::erf::{erf, erfc};
77use statrs:: function:: gamma:: { gamma, ln_gamma} ;
88
99use num_bigint:: BigInt ;
10- use num_traits:: cast:: ToPrimitive ;
1110use num_traits:: { One , Zero } ;
1211
1312use crate :: function:: OptionalArg ;
1413use crate :: obj:: objfloat:: { self , IntoPyFloat , PyFloatRef } ;
15- use crate :: obj:: objint:: PyIntRef ;
14+ use crate :: obj:: objint:: { self , PyIntRef } ;
1615use crate :: obj:: objtype;
17- use crate :: pyobject:: { PyObjectRef , PyResult , TypeProtocol } ;
16+ use crate :: pyobject:: { Either , PyObjectRef , PyResult , TypeProtocol } ;
1817use crate :: vm:: VirtualMachine ;
1918
2019#[ cfg( not( target_arch = "wasm32" ) ) ]
@@ -261,8 +260,16 @@ fn math_frexp(value: IntoPyFloat) -> (f64, i32) {
261260 }
262261}
263262
264- fn math_ldexp ( value : PyFloatRef , i : PyIntRef ) -> f64 {
265- value. to_f64 ( ) * ( 2_f64 ) . powf ( i. as_bigint ( ) . to_f64 ( ) . unwrap ( ) )
263+ fn math_ldexp (
264+ value : Either < PyFloatRef , PyIntRef > ,
265+ i : PyIntRef ,
266+ vm : & VirtualMachine ,
267+ ) -> PyResult < f64 > {
268+ let value = match value {
269+ Either :: A ( f) => f. to_f64 ( ) ,
270+ Either :: B ( z) => objint:: try_float ( z. as_bigint ( ) , vm) ?,
271+ } ;
272+ Ok ( value * ( 2_f64 ) . powf ( objint:: try_float ( i. as_bigint ( ) , vm) ?) )
266273}
267274
268275fn math_gcd ( a : PyIntRef , b : PyIntRef ) -> BigInt {
0 commit comments