Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: fb7968794e55
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6962b6e6cd3f
Choose a head ref
  • 3 commits
  • 4 files changed
  • 2 contributors

Commits on Jan 14, 2018

  1. Copy the full SHA
    bd85346 View commit details
  2. Copy the full SHA
    7ced817 View commit details

Commits on Jan 15, 2018

  1. Merge pull request #4974 from ChrisBr/feature/integer

    Make Integer#{round,floor,ceil,truncate} always return integer
    enebo authored Jan 15, 2018
    Copy the full SHA
    6962b6e View commit details
8 changes: 2 additions & 6 deletions core/src/main/java/org/jruby/RubyBignum.java
Original file line number Diff line number Diff line change
@@ -270,9 +270,7 @@ public static BigInteger long2big(long arg) {
public IRubyObject ceil(ThreadContext context, IRubyObject arg){
int ndigits = arg.convertToInteger().getIntValue();
BigInteger self = value;
if (ndigits > 0){
return convertToFloat();
} else if (ndigits == 0){
if (ndigits >= 0){
return this;
} else {
int posdigits = Math.abs(ndigits);
@@ -293,9 +291,7 @@ public IRubyObject ceil(ThreadContext context, IRubyObject arg){
public IRubyObject floor(ThreadContext context, IRubyObject arg){
int ndigits = arg.convertToInteger().getIntValue();
BigInteger self = value;
if (ndigits > 0){
return convertToFloat();
} else if (ndigits == 0){
if (ndigits >= 0){
return this;
} else {
int posdigits = Math.abs(ndigits);
8 changes: 2 additions & 6 deletions core/src/main/java/org/jruby/RubyFixnum.java
Original file line number Diff line number Diff line change
@@ -305,9 +305,7 @@ public IRubyObject times(ThreadContext context, Block block) {
public IRubyObject ceil(ThreadContext context, IRubyObject arg){
long ndigits = arg.convertToInteger().getLongValue();
long self = getLongValue();
if (ndigits > 0) {
return convertToFloat();
} else if (ndigits == 0){
if (ndigits >= 0) {
return this;
} else {
long posdigits = Math.abs(ndigits);
@@ -328,9 +326,7 @@ public IRubyObject ceil(ThreadContext context, IRubyObject arg){
public IRubyObject floor(ThreadContext context, IRubyObject arg){
long ndigits = (arg).convertToInteger().getLongValue();
long self = getLongValue();
if (ndigits > 0) {
return convertToFloat();
} else if (ndigits == 0){
if (ndigits >= 0) {
return this;
} else {
long posdigits = Math.abs(ndigits);
6 changes: 1 addition & 5 deletions core/src/main/java/org/jruby/RubyInteger.java
Original file line number Diff line number Diff line change
@@ -457,11 +457,7 @@ public IRubyObject round(ThreadContext context, IRubyObject digits, IRubyObject
int ndigits = num2int(digits);

RoundingMode roundingMode = getRoundingMode(context, opts);

if (ndigits > 0) {
return RubyKernel.new_float(runtime, this);
}
if (ndigits == 0) {
if (ndigits >= 0) {
return this;
}

21 changes: 13 additions & 8 deletions test/mri/ruby/test_integer.rb
Original file line number Diff line number Diff line change
@@ -181,8 +181,8 @@ def test_round
assert_int_equal(11111, 11111.round)
assert_int_equal(11111, 11111.round(0))

assert_float_equal(11111.0, 11111.round(1))
assert_float_equal(11111.0, 11111.round(2))
assert_int_equal(11111, 11111.round(1))
assert_int_equal(11111, 11111.round(2))

assert_int_equal(11110, 11111.round(-1))
assert_int_equal(11100, 11111.round(-2))
@@ -255,8 +255,8 @@ def test_floor
assert_int_equal(11111, 11111.floor)
assert_int_equal(11111, 11111.floor(0))

assert_float_equal(11111.0, 11111.floor(1))
assert_float_equal(11111.0, 11111.floor(2))
assert_int_equal(11111, 11111.floor(1))
assert_int_equal(11111, 11111.floor(2))

assert_int_equal(11110, 11110.floor(-1))
assert_int_equal(11110, 11119.floor(-1))
@@ -280,8 +280,8 @@ def test_ceil
assert_int_equal(11111, 11111.ceil)
assert_int_equal(11111, 11111.ceil(0))

assert_float_equal(11111.0, 11111.ceil(1))
assert_float_equal(11111.0, 11111.ceil(2))
assert_int_equal(11111, 11111.ceil(1))
assert_int_equal(11111, 11111.ceil(2))

assert_int_equal(11110, 11110.ceil(-1))
assert_int_equal(11120, 11119.ceil(-1))
@@ -299,14 +299,17 @@ def test_ceil

assert_int_equal(1111_1111_1111_1111_1111_1111_1111_1120, 1111_1111_1111_1111_1111_1111_1111_1111.ceil(-1))
assert_int_equal(-1111_1111_1111_1111_1111_1111_1111_1110, (-1111_1111_1111_1111_1111_1111_1111_1111).ceil(-1))

assert_int_equal(1111_1111_1111_1111_1111_1111_1111_1111, 1111_1111_1111_1111_1111_1111_1111_1111.ceil(1))
assert_int_equal(10**400, (10**400).ceil(1))
end

def test_truncate
assert_int_equal(11111, 11111.truncate)
assert_int_equal(11111, 11111.truncate(0))

assert_float_equal(11111.0, 11111.truncate(1))
assert_float_equal(11111.0, 11111.truncate(2))
assert_int_equal(11111, 11111.truncate(1))
assert_int_equal(11111, 11111.truncate(2))

assert_int_equal(11110, 11110.truncate(-1))
assert_int_equal(11110, 11119.truncate(-1))
@@ -324,6 +327,8 @@ def test_truncate

assert_int_equal(1111_1111_1111_1111_1111_1111_1111_1110, 1111_1111_1111_1111_1111_1111_1111_1111.truncate(-1))
assert_int_equal(-1111_1111_1111_1111_1111_1111_1111_1110, (-1111_1111_1111_1111_1111_1111_1111_1111).truncate(-1))
assert_int_equal(1111_1111_1111_1111_1111_1111_1111_1111, 1111_1111_1111_1111_1111_1111_1111_1111.truncate(1))
assert_int_equal(10**400, (10**400).truncate(1))
end

MimicInteger = Struct.new(:to_int)