@@ -21,7 +21,7 @@ mod math {
2121 // Helper macro:
2222 macro_rules! call_math_func {
2323 ( $fun: ident, $name: ident, $vm: ident ) => { {
24- let value = $name. to_f64 ( ) ;
24+ let value = * $name;
2525 let result = value. $fun( ) ;
2626 result_or_overflow( value, result, $vm)
2727 } } ;
@@ -46,17 +46,17 @@ mod math {
4646
4747 #[ pyfunction]
4848 fn isfinite ( x : ArgIntoFloat ) -> bool {
49- x. to_f64 ( ) . is_finite ( )
49+ x. is_finite ( )
5050 }
5151
5252 #[ pyfunction]
5353 fn isinf ( x : ArgIntoFloat ) -> bool {
54- x. to_f64 ( ) . is_infinite ( )
54+ x. is_infinite ( )
5555 }
5656
5757 #[ pyfunction]
5858 fn isnan ( x : ArgIntoFloat ) -> bool {
59- x. to_f64 ( ) . is_nan ( )
59+ x. is_nan ( )
6060 }
6161
6262 #[ derive( FromArgs ) ]
@@ -73,10 +73,10 @@ mod math {
7373
7474 #[ pyfunction]
7575 fn isclose ( args : IsCloseArgs , vm : & VirtualMachine ) -> PyResult < bool > {
76- let a = args. a . to_f64 ( ) ;
77- let b = args. b . to_f64 ( ) ;
78- let rel_tol = args. rel_tol . map_or ( 1e-09 , |value| value. to_f64 ( ) ) ;
79- let abs_tol = args. abs_tol . map_or ( 0.0 , |value| value. to_f64 ( ) ) ;
76+ let a = * args. a ;
77+ let b = * args. b ;
78+ let rel_tol = args. rel_tol . map_or ( 1e-09 , |value| value. into ( ) ) ;
79+ let abs_tol = args. abs_tol . map_or ( 0.0 , |value| value. into ( ) ) ;
8080
8181 if rel_tol < 0.0 || abs_tol < 0.0 {
8282 return Err ( vm. new_value_error ( "tolerances must be non-negative" . to_owned ( ) ) ) ;
@@ -107,12 +107,10 @@ mod math {
107107
108108 #[ pyfunction]
109109 fn copysign ( x : ArgIntoFloat , y : ArgIntoFloat ) -> f64 {
110- let a = x. to_f64 ( ) ;
111- let b = y. to_f64 ( ) ;
112- if a. is_nan ( ) || b. is_nan ( ) {
113- a
110+ if x. is_nan ( ) || y. is_nan ( ) {
111+ x. into ( )
114112 } else {
115- a . copysign ( b )
113+ x . copysign ( * y )
116114 }
117115 }
118116
@@ -129,7 +127,7 @@ mod math {
129127
130128 #[ pyfunction]
131129 fn log ( x : ArgIntoFloat , base : OptionalArg < ArgIntoFloat > , vm : & VirtualMachine ) -> PyResult < f64 > {
132- let x = x . to_f64 ( ) ;
130+ let x = * x ;
133131 base. map_or_else (
134132 || {
135133 if x. is_nan ( ) || x > 0.0_f64 {
@@ -138,13 +136,13 @@ mod math {
138136 Err ( vm. new_value_error ( "math domain error" . to_owned ( ) ) )
139137 }
140138 } ,
141- |base| Ok ( x. log ( base. to_f64 ( ) ) ) ,
139+ |base| Ok ( x. log ( * base) ) ,
142140 )
143141 }
144142
145143 #[ pyfunction]
146144 fn log1p ( x : ArgIntoFloat , vm : & VirtualMachine ) -> PyResult < f64 > {
147- let x = x . to_f64 ( ) ;
145+ let x = * x ;
148146 if x. is_nan ( ) || x > -1.0_f64 {
149147 Ok ( ( x + 1.0_f64 ) . ln ( ) )
150148 } else {
@@ -154,7 +152,7 @@ mod math {
154152
155153 #[ pyfunction]
156154 fn log2 ( x : ArgIntoFloat , vm : & VirtualMachine ) -> PyResult < f64 > {
157- let x = x . to_f64 ( ) ;
155+ let x = * x ;
158156 if x. is_nan ( ) || x > 0.0_f64 {
159157 Ok ( x. log2 ( ) )
160158 } else {
@@ -164,7 +162,7 @@ mod math {
164162
165163 #[ pyfunction]
166164 fn log10 ( x : ArgIntoFloat , vm : & VirtualMachine ) -> PyResult < f64 > {
167- let x = x . to_f64 ( ) ;
165+ let x = * x ;
168166 if x. is_nan ( ) || x > 0.0_f64 {
169167 Ok ( x. log10 ( ) )
170168 } else {
@@ -174,8 +172,8 @@ mod math {
174172
175173 #[ pyfunction]
176174 fn pow ( x : ArgIntoFloat , y : ArgIntoFloat , vm : & VirtualMachine ) -> PyResult < f64 > {
177- let x = x . to_f64 ( ) ;
178- let y = y . to_f64 ( ) ;
175+ let x = * x ;
176+ let y = * y ;
179177
180178 if x < 0.0 && x. is_finite ( ) && y. fract ( ) != 0.0 && y. is_finite ( ) {
181179 return Err ( vm. new_value_error ( "math domain error" . to_owned ( ) ) ) ;
@@ -192,7 +190,7 @@ mod math {
192190
193191 #[ pyfunction]
194192 fn sqrt ( value : ArgIntoFloat , vm : & VirtualMachine ) -> PyResult < f64 > {
195- let value = value. to_f64 ( ) ;
193+ let value = * value;
196194 if value. is_sign_negative ( ) {
197195 return Err ( vm. new_value_error ( "math domain error" . to_owned ( ) ) ) ;
198196 }
@@ -213,7 +211,7 @@ mod math {
213211 // Trigonometric functions:
214212 #[ pyfunction]
215213 fn acos ( x : ArgIntoFloat , vm : & VirtualMachine ) -> PyResult < f64 > {
216- let x = x . to_f64 ( ) ;
214+ let x = * x ;
217215 if x. is_nan ( ) || ( -1.0_f64 ..=1.0_f64 ) . contains ( & x) {
218216 Ok ( x. acos ( ) )
219217 } else {
@@ -223,7 +221,7 @@ mod math {
223221
224222 #[ pyfunction]
225223 fn asin ( x : ArgIntoFloat , vm : & VirtualMachine ) -> PyResult < f64 > {
226- let x = x . to_f64 ( ) ;
224+ let x = * x ;
227225 if x. is_nan ( ) || ( -1.0_f64 ..=1.0_f64 ) . contains ( & x) {
228226 Ok ( x. asin ( ) )
229227 } else {
@@ -238,7 +236,7 @@ mod math {
238236
239237 #[ pyfunction]
240238 fn atan2 ( y : ArgIntoFloat , x : ArgIntoFloat ) -> f64 {
241- y. to_f64 ( ) . atan2 ( x . to_f64 ( ) )
239+ y. atan2 ( * x )
242240 }
243241
244242 #[ pyfunction]
@@ -337,19 +335,19 @@ mod math {
337335
338336 #[ pyfunction]
339337 fn degrees ( x : ArgIntoFloat ) -> f64 {
340- x . to_f64 ( ) * ( 180.0 / std:: f64:: consts:: PI )
338+ * x * ( 180.0 / std:: f64:: consts:: PI )
341339 }
342340
343341 #[ pyfunction]
344342 fn radians ( x : ArgIntoFloat ) -> f64 {
345- x . to_f64 ( ) * ( std:: f64:: consts:: PI / 180.0 )
343+ * x * ( std:: f64:: consts:: PI / 180.0 )
346344 }
347345
348346 // Hyperbolic functions:
349347
350348 #[ pyfunction]
351349 fn acosh ( x : ArgIntoFloat , vm : & VirtualMachine ) -> PyResult < f64 > {
352- let x = x . to_f64 ( ) ;
350+ let x = * x ;
353351 if x. is_sign_negative ( ) || x. is_zero ( ) {
354352 Err ( vm. new_value_error ( "math domain error" . to_owned ( ) ) )
355353 } else {
@@ -364,7 +362,7 @@ mod math {
364362
365363 #[ pyfunction]
366364 fn atanh ( x : ArgIntoFloat , vm : & VirtualMachine ) -> PyResult < f64 > {
367- let x = x . to_f64 ( ) ;
365+ let x = * x ;
368366 if x >= 1.0_f64 || x <= -1.0_f64 {
369367 Err ( vm. new_value_error ( "math domain error" . to_owned ( ) ) )
370368 } else {
@@ -390,7 +388,7 @@ mod math {
390388 // Special functions:
391389 #[ pyfunction]
392390 fn erf ( x : ArgIntoFloat ) -> f64 {
393- let x = x . to_f64 ( ) ;
391+ let x = * x ;
394392 if x. is_nan ( ) {
395393 x
396394 } else {
@@ -400,7 +398,7 @@ mod math {
400398
401399 #[ pyfunction]
402400 fn erfc ( x : ArgIntoFloat ) -> f64 {
403- let x = x . to_f64 ( ) ;
401+ let x = * x ;
404402 if x. is_nan ( ) {
405403 x
406404 } else {
@@ -410,7 +408,7 @@ mod math {
410408
411409 #[ pyfunction]
412410 fn gamma ( x : ArgIntoFloat ) -> f64 {
413- let x = x . to_f64 ( ) ;
411+ let x = * x ;
414412 if x. is_finite ( ) {
415413 puruspe:: gamma ( x)
416414 } else if x. is_nan ( ) || x. is_sign_positive ( ) {
@@ -422,7 +420,7 @@ mod math {
422420
423421 #[ pyfunction]
424422 fn lgamma ( x : ArgIntoFloat ) -> f64 {
425- let x = x . to_f64 ( ) ;
423+ let x = * x ;
426424 if x. is_finite ( ) {
427425 puruspe:: ln_gamma ( x)
428426 } else if x. is_nan ( ) {
@@ -474,7 +472,7 @@ mod math {
474472
475473 #[ pyfunction]
476474 fn frexp ( x : ArgIntoFloat ) -> ( f64 , i32 ) {
477- let value = x . to_f64 ( ) ;
475+ let value = * x ;
478476 if value. is_finite ( ) {
479477 let ( m, exp) = float_ops:: ufrexp ( value) ;
480478 ( m * value. signum ( ) , exp)
@@ -541,7 +539,7 @@ mod math {
541539 let mut inf_sum = 0.0 ;
542540
543541 for obj in seq. iter ( vm) ? {
544- let mut x = obj?. to_f64 ( ) ;
542+ let mut x = * obj?;
545543
546544 let xsave = x;
547545 let mut j = 0 ;
@@ -726,7 +724,7 @@ mod math {
726724
727725 #[ pyfunction]
728726 fn modf ( x : ArgIntoFloat ) -> ( f64 , f64 ) {
729- let x = x . to_f64 ( ) ;
727+ let x = * x ;
730728 if !x. is_finite ( ) {
731729 if x. is_infinite ( ) {
732730 return ( 0.0_f64 . copysign ( x) , x) ;
@@ -740,12 +738,12 @@ mod math {
740738
741739 #[ pyfunction]
742740 fn nextafter ( x : ArgIntoFloat , y : ArgIntoFloat ) -> f64 {
743- float_ops:: nextafter ( x . to_f64 ( ) , y . to_f64 ( ) )
741+ float_ops:: nextafter ( * x , * y )
744742 }
745743
746744 #[ pyfunction]
747745 fn ulp ( x : ArgIntoFloat ) -> f64 {
748- float_ops:: ulp ( x . to_f64 ( ) )
746+ float_ops:: ulp ( * x )
749747 }
750748
751749 fn fmod ( x : f64 , y : f64 ) -> f64 {
@@ -758,8 +756,8 @@ mod math {
758756
759757 #[ pyfunction( name = "fmod" ) ]
760758 fn py_fmod ( x : ArgIntoFloat , y : ArgIntoFloat , vm : & VirtualMachine ) -> PyResult < f64 > {
761- let x = x . to_f64 ( ) ;
762- let y = y . to_f64 ( ) ;
759+ let x = * x ;
760+ let y = * y ;
763761
764762 let r = fmod ( x, y) ;
765763
@@ -772,8 +770,8 @@ mod math {
772770
773771 #[ pyfunction]
774772 fn remainder ( x : ArgIntoFloat , y : ArgIntoFloat , vm : & VirtualMachine ) -> PyResult < f64 > {
775- let x = x . to_f64 ( ) ;
776- let y = y . to_f64 ( ) ;
773+ let x = * x ;
774+ let y = * y ;
777775
778776 if x. is_finite ( ) && y. is_finite ( ) {
779777 if y == 0.0 {
0 commit comments