@@ -179,20 +179,39 @@ impl PyFloat {
179
179
PyFloat :: from ( float_val?) . into_ref_with_type ( vm, cls)
180
180
}
181
181
182
+ fn float_eq ( & self , other : PyObjectRef ) -> bool {
183
+ let other = get_value ( & other) ;
184
+ self . value == other
185
+ }
186
+
187
+ fn int_eq ( & self , other : PyObjectRef ) -> bool {
188
+ let other_int = objint:: get_value ( & other) ;
189
+ let value = self . value ;
190
+ if let ( Some ( self_int) , Some ( other_float) ) = ( value. to_bigint ( ) , other_int. to_f64 ( ) ) {
191
+ value == other_float && self_int == * other_int
192
+ } else {
193
+ false
194
+ }
195
+ }
196
+
182
197
#[ pymethod( name = "__eq__" ) ]
183
198
fn eq ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyObjectRef {
184
- let value = self . value ;
185
199
let result = if objtype:: isinstance ( & other, & vm. ctx . float_type ( ) ) {
186
- let other = get_value ( & other) ;
187
- value == other
200
+ self . float_eq ( other)
188
201
} else if objtype:: isinstance ( & other, & vm. ctx . int_type ( ) ) {
189
- let other_int = objint:: get_value ( & other) ;
202
+ self . int_eq ( other)
203
+ } else {
204
+ return vm. ctx . not_implemented ( ) ;
205
+ } ;
206
+ vm. ctx . new_bool ( result)
207
+ }
190
208
191
- if let ( Some ( self_int) , Some ( other_float) ) = ( value. to_bigint ( ) , other_int. to_f64 ( ) ) {
192
- value == other_float && self_int == * other_int
193
- } else {
194
- false
195
- }
209
+ #[ pymethod( name = "__ne__" ) ]
210
+ fn ne ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyObjectRef {
211
+ let result = if objtype:: isinstance ( & other, & vm. ctx . float_type ( ) ) {
212
+ !self . float_eq ( other)
213
+ } else if objtype:: isinstance ( & other, & vm. ctx . int_type ( ) ) {
214
+ !self . int_eq ( other)
196
215
} else {
197
216
return vm. ctx . not_implemented ( ) ;
198
217
} ;
0 commit comments