-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port Float#next_float & Float#prev_float
Somehow rubyspec/rubyspec#297 didn't made it into rubinius. Ported over @jemc pr into rubinius.
Showing
4 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require File.expand_path('../../../spec_helper', __FILE__) | ||
|
||
describe "Float" do | ||
it "returns a float the smallest possible step greater than the receiver" do | ||
barely_positive = 0.0.next_float | ||
barely_positive.should eql 0.0.next_float | ||
|
||
barely_positive.should > 0.0 | ||
barely_positive.should < barely_positive.next_float | ||
|
||
midpoint = barely_positive / 2 | ||
[0.0, barely_positive].should include midpoint | ||
end | ||
|
||
it "steps directly between MAX and INFINITY" do | ||
(-Float::INFINITY).next_float.should eql -Float::MAX | ||
Float::MAX.next_float.should eql Float::INFINITY | ||
end | ||
|
||
it "steps directly between 1.0 and EPSILON + 1.0" do | ||
1.0.next_float.should eql Float::EPSILON + 1.0 | ||
end | ||
|
||
it "steps directly between -1.0 and EPSILON/2 - 1.0" do | ||
(-1.0).next_float.should eql Float::EPSILON/2 - 1.0 | ||
end | ||
|
||
it "reverses the effect of prev_float" do | ||
num = rand | ||
num.prev_float.next_float.should eql num | ||
end | ||
|
||
it "returns negative zero when stepping upward from just below zero" do | ||
x = 0.0.prev_float.next_float | ||
(1/x).should eql -Float::INFINITY | ||
x = (-0.0).prev_float.next_float | ||
(1/x).should eql -Float::INFINITY | ||
x.next_float.should > 0 | ||
end | ||
|
||
it "returns NAN if NAN was the receiver" do | ||
Float::NAN.next_float.nan?.should eql true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require File.expand_path('../../../spec_helper', __FILE__) | ||
|
||
describe "Float" do | ||
it "returns a float the smallest possible step greater than the receiver" do | ||
barely_negative = 0.0.prev_float | ||
barely_negative.should eql 0.0.prev_float | ||
|
||
barely_negative.should < 0.0 | ||
barely_negative.should > barely_negative.prev_float | ||
|
||
midpoint = barely_negative / 2 | ||
[0.0, barely_negative].should include midpoint | ||
end | ||
|
||
it "steps directly between MAX and INFINITY" do | ||
Float::INFINITY.prev_float.should eql Float::MAX | ||
(-Float::MAX).prev_float.should eql -Float::INFINITY | ||
end | ||
|
||
it "steps directly between 1.0 and -EPSILON/2 + 1.0" do | ||
1.0.prev_float.should eql -Float::EPSILON/2 + 1.0 | ||
end | ||
|
||
it "steps directly between -1.0 and -EPSILON - 1.0" do | ||
(-1.0).prev_float.should eql -Float::EPSILON - 1.0 | ||
end | ||
|
||
it "reverses the effect of next_float" do | ||
num = rand | ||
num.next_float.prev_float.should eql num | ||
end | ||
|
||
it "returns positive zero when stepping downward from just above zero" do | ||
x = 0.0.next_float.prev_float | ||
(1/x).should eql Float::INFINITY | ||
x = (-0.0).next_float.prev_float | ||
(1/x).should eql Float::INFINITY | ||
x.prev_float.should < 0 | ||
end | ||
|
||
it "returns NAN if NAN was the receiver" do | ||
Float::NAN.prev_float.nan?.should eql true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
fails:returns a float the smallest possible step greater than the receiver | ||
fails:steps directly between MAX and INFINITY | ||
fails:steps directly between 1.0 and EPSILON + 1.0 | ||
fails:steps directly between -1.0 and EPSILON/2 - 1.0 | ||
fails:reverses the effect of prev_float | ||
fails:returns negative zero when stepping upward from just below zero | ||
fails:returns NAN if NAN was the receiver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
fails:returns a float the smallest possible step greater than the receiver | ||
fails:steps directly between MAX and INFINITY | ||
fails:steps directly between 1.0 and -EPSILON/2 + 1.0 | ||
fails:steps directly between -1.0 and -EPSILON - 1.0 | ||
fails:reverses the effect of next_float | ||
fails:returns positive zero when stepping downward from just above zero | ||
fails:returns NAN if NAN was the receiver |