Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Float to_i should raise a FloatDomainError when NaN #646

Merged
merged 1 commit into from
Oct 13, 2022
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
1 change: 1 addition & 0 deletions spec/core/float/shared/to_i.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
describe :float_to_i, shared: true do
it "returns self truncated to an Integer" do
-> { (0.0 / 0.0).send(@method) }.should raise_error(FloatDomainError)
899.2.send(@method).should eql(899)
-1.122256e-45.send(@method).should eql(0)
5_213_451.9201.send(@method).should eql(5213451)
Expand Down
1 change: 1 addition & 0 deletions src/float_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ Value FloatObject::coerce(Env *env, Value arg) {
}

Value FloatObject::to_i(Env *env) const {
if (is_nan()) env->raise("FloatDomainError", "NaN");
if (is_infinity()) {
env->raise("FloatDomainError", to_s()->as_string()->string());
}
Expand Down