Skip to content

Commit

Permalink
Showing 2 changed files with 18 additions and 7 deletions.
19 changes: 15 additions & 4 deletions core/src/main/java/org/jruby/RubyFloat.java
Original file line number Diff line number Diff line change
@@ -1022,11 +1022,22 @@ private static double roundHalfDown(double x, double s) {
return x;
}

private static double roundHalfUp(double xs) {
if (xs < 0.0) {
return Math.round(xs * -1.0) * -1.0;
private static double roundHalfUp(double n) {
double f = n;
if (f >= 0.0) {
f = Math.floor(f);

if (n - f >= 0.5) {
f += 1.0;
}
} else {
f = Math.ceil(f);

if (f - n >= 0.5) {
f -= 1.0;
}
}
return Math.round(xs);
return f;
}

private static double roundHalfEven(double x, double s) {
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/RubyNumeric.java
Original file line number Diff line number Diff line change
@@ -1422,7 +1422,7 @@ public static boolean fixable(Ruby runtime, double f) {
BigInteger bigint = BigDecimal.valueOf(f).toBigInteger();
return posFixable(bigint) && negFixable(bigint);
} else {
return posFixable(l) && negFixable(l);
return posFixable(f) && negFixable(f);
}
}

@@ -1437,12 +1437,12 @@ public static boolean negFixable(BigInteger f) {
}

// MRI: macro POSFIXABLE, RB_POSFIXABLE
public static boolean posFixable(long l) {
public static boolean posFixable(double l) {
return l <= RubyFixnum.MAX;
}

// MRI: macro NEGFIXABLE, RB_NEGFIXABLE
public static boolean negFixable(long l) {
public static boolean negFixable(double l) {
return l >= RubyFixnum.MIN;
}

0 comments on commit 2c3652a

Please sign in to comment.