Skip to content

Commit

Permalink
Showing 2 changed files with 7 additions and 7 deletions.
9 changes: 6 additions & 3 deletions core/src/main/java/org/jruby/RubyNumeric.java
Original file line number Diff line number Diff line change
@@ -255,7 +255,7 @@ public static IRubyObject dbl2num(Ruby runtime, double val) {
* MRI: macro DBL2IVAL
*/
public static IRubyObject dbl2ival(Ruby runtime, double val) {
if (fixable(val)) {
if (fixable(runtime, val)) {
return RubyFixnum.newFixnum(runtime, (long) val);
}
return RubyBignum.newBignorm(runtime, val);
@@ -1411,8 +1411,11 @@ public static IRubyObject numFuncall(ThreadContext context, final IRubyObject x,
}

// MRI: macro FIXABLE, RB_FIXABLE
// Note: this should not be NaN or +-Inf
public static boolean fixable(double f) {
// Note: this does additional checks for inf and nan
public static boolean fixable(Ruby runtime, double f) {
if (Double.isNaN(f) || Double.isInfinite(f)) {
throw runtime.newFloatDomainError(Double.toString(f));
}
long l = (long) f;
if (l == RubyFixnum.MIN ||
l == RubyFixnum.MAX){
5 changes: 1 addition & 4 deletions core/src/main/java/org/jruby/util/TypeConverter.java
Original file line number Diff line number Diff line change
@@ -382,10 +382,7 @@ public static IRubyObject convertToInteger(ThreadContext context, IRubyObject va
for (;;) {
if (val instanceof RubyFloat) {
if (base != 0) raiseIntegerBaseError(context);
double value = ((RubyFloat) val).getValue();
if (value <= RubyFixnum.MAX || value >= RubyFixnum.MIN) {
return RubyNumeric.dbl2ival(context.runtime, value);
}
return RubyNumeric.dbl2ival(context.runtime, ((RubyFloat) val).getValue());
} else if (val instanceof RubyInteger) {
if (base != 0) raiseIntegerBaseError(context);
return val;

0 comments on commit 5f4caec

Please sign in to comment.