diff --git a/core/kernel/Float_spec.rb b/core/kernel/Float_spec.rb index 1705205996..e00fe81572 100644 --- a/core/kernel/Float_spec.rb +++ b/core/kernel/Float_spec.rb @@ -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 @@ -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 diff --git a/core/string/to_f_spec.rb b/core/string/to_f_spec.rb index a91ccc168e..abfd2517b6 100644 --- a/core/string/to_f_spec.rb +++ b/core/string/to_f_spec.rb @@ -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