File tree Expand file tree Collapse file tree 3 files changed +35
-0
lines changed
src/main/ruby/truffleruby/core Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ Compatibility:
35
35
* Implement ` IO#set_encoding_by_bom ` (#2372 , pawandubey).
36
36
* Implemented ` Enumerator::Lazy#with_index ` (#2356 ).
37
37
* Implement ` rb_backref_set ` .
38
+ * Fix ` Float#<=> ` when comparing ` Infinity ` to other ` #infinite? ` values.
38
39
39
40
Performance:
40
41
Original file line number Diff line number Diff line change @@ -63,4 +63,28 @@ def coerce(other)
63
63
it "returns 1 when self is negative and other is -Infinity" do
64
64
( -Float ::MAX . to_i *2 <=> -infinity_value ) . should == 1
65
65
end
66
+
67
+ it "returns 0 when self is Infinity and other other is infinite?=1" do
68
+ obj = Object . new
69
+ def obj . infinite?
70
+ 1
71
+ end
72
+ ( infinity_value <=> obj ) . should == 0
73
+ end
74
+
75
+ it "returns 1 when self is Infinity and other is infinite?=-1" do
76
+ obj = Object . new
77
+ def obj . infinite?
78
+ -1
79
+ end
80
+ ( infinity_value <=> obj ) . should == 1
81
+ end
82
+
83
+ it "returns 1 when self is Infinity and other is infinite?=nil (which means finite)" do
84
+ obj = Object . new
85
+ def obj . infinite?
86
+ nil
87
+ end
88
+ ( infinity_value <=> obj ) . should == 1
89
+ end
66
90
end
Original file line number Diff line number Diff line change @@ -236,7 +236,17 @@ def redo_compare(meth, right)
236
236
a <=> b
237
237
end
238
238
239
+ # only used by Float#<=>
239
240
private def redo_compare_bad_coerce_return_error ( right )
241
+ if self . infinite? and !Primitive . undefined? ( val = Truffle ::Type . check_funcall ( right , :infinite? ) )
242
+ if val
243
+ cmp = val <=> 0
244
+ return self > 0.0 ? ( cmp > 0 ? 0 : 1 ) : ( cmp < 0 ? 0 : -1 )
245
+ else
246
+ # right.infinite? returned false or nil, which means right is finite
247
+ return self > 0.0 ? 1 : -1
248
+ end
249
+ end
240
250
b , a = math_coerce ( right , :bad_coerce_return_error )
241
251
return nil unless b
242
252
a <=> b
You can’t perform that action at this time.
0 commit comments