Skip to content

Commit

Permalink
Fixed C++ exception being raised in rb_dbl2big.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Jan 16, 2016
1 parent 2c09d37 commit e265a22
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions vm/capi/bignum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ extern "C" {
VALUE rb_dbl2big(double num) {
NativeMethodEnvironment* env = NativeMethodEnvironment::get();

// We have to handle exceptional cases here so that a C++ exception is not
// thrown when we call into C++ code.
if(isinf(num)) {
rb_raise(rb_eFloatDomainError, num < 0 ? "-Infinity" : "Infinity");
} else if(isnan(num)) {
rb_raise(rb_eFloatDomainError, "NaN");
}

Integer* bignum = Bignum::from_double(env->state(), num);

return env->get_handle(bignum);
Expand Down

0 comments on commit e265a22

Please sign in to comment.