@@ -546,41 +546,34 @@ impl Hashable for PyFloat {
546
546
impl AsNumber for PyFloat {
547
547
fn as_number ( ) -> & ' static PyNumberMethods {
548
548
static AS_NUMBER : Lazy < PyNumberMethods > = Lazy :: new ( || PyNumberMethods {
549
- add : atomic_func ! ( |num, other, vm| PyFloat :: number_float_op (
549
+ add : atomic_func ! ( |num, other, vm| PyFloat :: number_op (
550
550
num,
551
551
other,
552
- |a, b| a + b,
552
+ |a, b, _vm | a + b,
553
553
vm
554
554
) ) ,
555
- subtract : atomic_func ! ( |num, other, vm| PyFloat :: number_float_op (
555
+ subtract : atomic_func ! ( |num, other, vm| PyFloat :: number_op (
556
556
num,
557
557
other,
558
- |a, b| a - b,
558
+ |a, b, _vm | a - b,
559
559
vm
560
560
) ) ,
561
- multiply : atomic_func ! ( |num, other, vm| PyFloat :: number_float_op (
561
+ multiply : atomic_func ! ( |num, other, vm| PyFloat :: number_op (
562
562
num,
563
563
other,
564
- |a, b| a * b,
564
+ |a, b, _vm | a * b,
565
565
vm
566
566
) ) ,
567
- remainder : atomic_func ! ( |num, other, vm| PyFloat :: number_general_op(
568
- num, other, inner_mod, vm
569
- ) ) ,
570
- divmod : atomic_func ! ( |num, other, vm| PyFloat :: number_general_op(
571
- num,
572
- other,
573
- inner_divmod,
574
- vm
575
- ) ) ,
576
- power : atomic_func ! ( |num, other, vm| PyFloat :: number_general_op(
577
- num, other, float_pow, vm
578
- ) ) ,
567
+ remainder : atomic_func ! ( |num, other, vm| PyFloat :: number_op( num, other, inner_mod, vm) ) ,
568
+ divmod : atomic_func ! ( |num, other, vm| PyFloat :: number_op( num, other, inner_divmod, vm) ) ,
569
+ power : atomic_func ! ( |num, other, vm| PyFloat :: number_op( num, other, float_pow, vm) ) ,
579
570
negative : atomic_func ! ( |num, vm| {
580
571
let value = PyFloat :: number_downcast( num) . value;
581
572
( -value) . to_pyresult( vm)
582
573
} ) ,
583
- positive : atomic_func ! ( |num, vm| PyFloat :: number_float( num, vm) . to_pyresult( vm) ) ,
574
+ positive : atomic_func ! (
575
+ |num, vm| PyFloat :: number_downcast_exact( num, vm) . to_pyresult( vm)
576
+ ) ,
584
577
absolute : atomic_func ! ( |num, vm| {
585
578
let value = PyFloat :: number_downcast( num) . value;
586
579
value. abs( ) . to_pyresult( vm)
@@ -590,26 +583,26 @@ impl AsNumber for PyFloat {
590
583
let value = PyFloat :: number_downcast( num) . value;
591
584
try_to_bigint( value, vm) . map( |x| vm. ctx. new_int( x) )
592
585
} ) ,
593
- float : atomic_func ! ( |num, vm| Ok ( PyFloat :: number_float ( num, vm) ) ) ,
586
+ float : atomic_func ! ( |num, vm| Ok ( PyFloat :: number_downcast_exact ( num, vm) ) ) ,
594
587
floor_divide : atomic_func ! ( |num, other, vm| {
595
- PyFloat :: number_general_op ( num, other, inner_floordiv, vm)
588
+ PyFloat :: number_op ( num, other, inner_floordiv, vm)
596
589
} ) ,
597
590
true_divide : atomic_func ! ( |num, other, vm| {
598
- PyFloat :: number_general_op ( num, other, inner_div, vm)
591
+ PyFloat :: number_op ( num, other, inner_div, vm)
599
592
} ) ,
600
593
..PyNumberMethods :: NOT_IMPLEMENTED
601
594
} ) ;
602
595
& AS_NUMBER
603
596
}
597
+
598
+ #[ inline]
599
+ fn clone_exact ( zelf : & Py < Self > , vm : & VirtualMachine ) -> PyRef < Self > {
600
+ vm. ctx . new_float ( zelf. value )
601
+ }
604
602
}
605
603
606
604
impl PyFloat {
607
- fn number_general_op < F , R > (
608
- number : PyNumber ,
609
- other : & PyObject ,
610
- op : F ,
611
- vm : & VirtualMachine ,
612
- ) -> PyResult
605
+ fn number_op < F , R > ( number : PyNumber , other : & PyObject , op : F , vm : & VirtualMachine ) -> PyResult
613
606
where
614
607
F : FnOnce ( f64 , f64 , & VirtualMachine ) -> R ,
615
608
R : ToPyResult ,
@@ -620,26 +613,6 @@ impl PyFloat {
620
613
Ok ( vm. ctx . not_implemented ( ) )
621
614
}
622
615
}
623
-
624
- fn number_float_op < F > (
625
- number : PyNumber ,
626
- other : & PyObject ,
627
- op : F ,
628
- vm : & VirtualMachine ,
629
- ) -> PyResult
630
- where
631
- F : FnOnce ( f64 , f64 ) -> f64 ,
632
- {
633
- Self :: number_general_op ( number, other, |a, b, _vm| op ( a, b) , vm)
634
- }
635
-
636
- fn number_float ( number : PyNumber , vm : & VirtualMachine ) -> PyRef < PyFloat > {
637
- if let Some ( zelf) = number. obj . downcast_ref_if_exact :: < Self > ( vm) {
638
- zelf. to_owned ( )
639
- } else {
640
- vm. ctx . new_float ( Self :: number_downcast ( number) . value )
641
- }
642
- }
643
616
}
644
617
645
618
// Retrieve inner float value:
0 commit comments