Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/kernel/Float_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def to_f() 1.2 end
-> { @object.send(:Float, "+1.") }.should raise_error(ArgumentError)
-> { @object.send(:Float, "-1.") }.should raise_error(ArgumentError)
-> { @object.send(:Float, "1.e+0") }.should raise_error(ArgumentError)
-> { @object.send(:Float, "1.e-2") }.should raise_error(ArgumentError)
end
end

Expand All @@ -172,6 +173,7 @@ def to_f() 1.2 end
@object.send(:Float, "+1.").should == 1.0
@object.send(:Float, "-1.").should == -1.0
@object.send(:Float, "1.e+0").should == 1.0
@object.send(:Float, "1.e-2").should be_close(0.01, TOLERANCE)
end
end

Expand Down
12 changes: 12 additions & 0 deletions core/string/to_f_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,16 @@
}.should raise_error(Encoding::CompatibilityError, "ASCII incompatible encoding: UTF-16")
end
end

it "allows String representation without a fractional part" do
"1.".to_f.should == 1.0
"+1.".to_f.should == 1.0
"-1.".to_f.should == -1.0
"1.e+0".to_f.should == 1.0
"1.e+0".to_f.should == 1.0

ruby_bug "#20705", ""..."3.4" do
"1.e-2".to_f.should be_close(0.01, TOLERANCE)
end
end
end