Skip to content

Commit 68ee316

Browse files
committed
Reimplement Float#round in a way it is done in MRI
1 parent 421ffd1 commit 68ee316

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

core/float/round_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
12.345678.round(3.999).should == 12.346
3131
end
3232

33+
it "correctly rounds exact floats with a numerous digits in a fraction part" do
34+
0.8241000000000004.round(10).should == 0.8241
35+
0.8241000000000002.round(10).should == 0.8241
36+
end
37+
3338
it "returns zero when passed a negative argument with magnitude greater than magnitude of the whole number portion of the Float" do
3439
0.8346268.round(-1).should eql(0)
3540
end
@@ -68,6 +73,10 @@
6873
0.42.round(2.0**30).should == 0.42
6974
end
7075

76+
it "returns rounded values for not so big argument" do
77+
0.42.round(2.0**23).should == 0.42
78+
end
79+
7180
it "returns big values rounded to nearest" do
7281
+2.5e20.round(-20).should eql( +3 * 10 ** 20 )
7382
-2.5e20.round(-20).should eql( -3 * 10 ** 20 )

0 commit comments

Comments
 (0)