@@ -83,60 +83,76 @@ fn float_lt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
8383 arg_check ! (
8484 vm,
8585 args,
86- required = [
87- ( zelf, Some ( vm. ctx. float_type( ) ) ) ,
88- ( other, Some ( vm. ctx. float_type( ) ) )
89- ]
86+ required = [ ( i, Some ( vm. ctx. float_type( ) ) ) , ( i2, None ) ]
9087 ) ;
91- let zelf = get_value ( zelf) ;
92- let other = get_value ( other) ;
93- let result = zelf < other;
94- Ok ( vm. ctx . new_bool ( result) )
88+
89+ let v1 = get_value ( i) ;
90+ if objtype:: isinstance ( i2, & vm. ctx . float_type ( ) ) {
91+ Ok ( vm. ctx . new_bool ( v1 < get_value ( i2) ) )
92+ } else if objtype:: isinstance ( i2, & vm. ctx . int_type ( ) ) {
93+ Ok ( vm
94+ . ctx
95+ . new_bool ( v1 < objint:: get_value ( i2) . to_f64 ( ) . unwrap ( ) ) )
96+ } else {
97+ Err ( vm. new_type_error ( format ! ( "Cannot compare {} and {}" , i. borrow( ) , i2. borrow( ) ) ) )
98+ }
9599}
96100
97101fn float_le ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
98102 arg_check ! (
99103 vm,
100104 args,
101- required = [
102- ( zelf, Some ( vm. ctx. float_type( ) ) ) ,
103- ( other, Some ( vm. ctx. float_type( ) ) )
104- ]
105+ required = [ ( i, Some ( vm. ctx. float_type( ) ) ) , ( i2, None ) ]
105106 ) ;
106- let zelf = get_value ( zelf) ;
107- let other = get_value ( other) ;
108- let result = zelf <= other;
109- Ok ( vm. ctx . new_bool ( result) )
107+
108+ let v1 = get_value ( i) ;
109+ if objtype:: isinstance ( i2, & vm. ctx . float_type ( ) ) {
110+ Ok ( vm. ctx . new_bool ( v1 <= get_value ( i2) ) )
111+ } else if objtype:: isinstance ( i2, & vm. ctx . int_type ( ) ) {
112+ Ok ( vm
113+ . ctx
114+ . new_bool ( v1 <= objint:: get_value ( i2) . to_f64 ( ) . unwrap ( ) ) )
115+ } else {
116+ Err ( vm. new_type_error ( format ! ( "Cannot compare {} and {}" , i. borrow( ) , i2. borrow( ) ) ) )
117+ }
110118}
111119
112120fn float_gt ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
113121 arg_check ! (
114122 vm,
115123 args,
116- required = [
117- ( zelf, Some ( vm. ctx. float_type( ) ) ) ,
118- ( other, Some ( vm. ctx. float_type( ) ) )
119- ]
124+ required = [ ( i, Some ( vm. ctx. float_type( ) ) ) , ( i2, None ) ]
120125 ) ;
121- let zelf = get_value ( zelf) ;
122- let other = get_value ( other) ;
123- let result = zelf > other;
124- Ok ( vm. ctx . new_bool ( result) )
126+
127+ let v1 = get_value ( i) ;
128+ if objtype:: isinstance ( i2, & vm. ctx . float_type ( ) ) {
129+ Ok ( vm. ctx . new_bool ( v1 > get_value ( i2) ) )
130+ } else if objtype:: isinstance ( i2, & vm. ctx . int_type ( ) ) {
131+ Ok ( vm
132+ . ctx
133+ . new_bool ( v1 > objint:: get_value ( i2) . to_f64 ( ) . unwrap ( ) ) )
134+ } else {
135+ Err ( vm. new_type_error ( format ! ( "Cannot compare {} and {}" , i. borrow( ) , i2. borrow( ) ) ) )
136+ }
125137}
126138
127139fn float_ge ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
128140 arg_check ! (
129141 vm,
130142 args,
131- required = [
132- ( zelf, Some ( vm. ctx. float_type( ) ) ) ,
133- ( other, Some ( vm. ctx. float_type( ) ) )
134- ]
143+ required = [ ( i, Some ( vm. ctx. float_type( ) ) ) , ( i2, None ) ]
135144 ) ;
136- let zelf = get_value ( zelf) ;
137- let other = get_value ( other) ;
138- let result = zelf >= other;
139- Ok ( vm. ctx . new_bool ( result) )
145+
146+ let v1 = get_value ( i) ;
147+ if objtype:: isinstance ( i2, & vm. ctx . float_type ( ) ) {
148+ Ok ( vm. ctx . new_bool ( v1 >= get_value ( i2) ) )
149+ } else if objtype:: isinstance ( i2, & vm. ctx . int_type ( ) ) {
150+ Ok ( vm
151+ . ctx
152+ . new_bool ( v1 >= objint:: get_value ( i2) . to_f64 ( ) . unwrap ( ) ) )
153+ } else {
154+ Err ( vm. new_type_error ( format ! ( "Cannot compare {} and {}" , i. borrow( ) , i2. borrow( ) ) ) )
155+ }
140156}
141157
142158fn float_abs ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
0 commit comments