[ruby 2.4] Implemented Integer#ceil, #floor, #truncate#4616
Merged
headius merged 3 commits intojruby:ruby-2.4from Jun 13, 2017
Merged
[ruby 2.4] Implemented Integer#ceil, #floor, #truncate#4616headius merged 3 commits intojruby:ruby-2.4from
headius merged 3 commits intojruby:ruby-2.4from
Conversation
Integer#floor, and Integer#truncate
…/jruby into 2.4-integer-ceil-floor-truncate
kares
reviewed
May 21, 2017
| * | ||
| */ | ||
| @Override | ||
| public IRubyObject ceil(ThreadContext context, IRubyObject args){ |
Member
There was a problem hiding this comment.
args should be named arg or something (everywhere) - otherwise its a bit confusing.
kares
reviewed
May 21, 2017
| BigInteger self = value; | ||
| if (self.compareTo(BigInteger.ZERO) == 1){ | ||
| return floor(context, args); | ||
| } else if (self.compareTo(BigInteger.ZERO) == -1){ |
Member
There was a problem hiding this comment.
maybe compareTo could be performance only once and saved in a local instead of twice
kares
reviewed
May 21, 2017
| BigInteger self = value; | ||
| if (ndigits.compareTo(BigInteger.ZERO) == 1){ | ||
| return convertToFloat(); | ||
| } else if (ndigits.compareTo(BigInteger.ZERO) == 0){ |
Member
There was a problem hiding this comment.
maybe compareTo could be performance only once and saved in a local instead of twice
kares
reviewed
May 21, 2017
| */ | ||
| @Override | ||
| public IRubyObject floor(ThreadContext context, IRubyObject args){ | ||
| BigInteger ndigits = args.convertToInteger().getBigIntegerValue(); |
Member
There was a problem hiding this comment.
is the arg really going to be a Bignul value isn't it an over-kill ?
kares
reviewed
May 21, 2017
| */ | ||
| @Override | ||
| public IRubyObject ceil(ThreadContext context, IRubyObject args){ | ||
| BigInteger ndigits = args.convertToInteger().getBigIntegerValue(); |
Member
There was a problem hiding this comment.
is the arg really going to be a Bignul value isn't it an over-kill ?
* changed "args" to "arg" in ceil, floor, and truncate * changed type of "ndigits" in RubyBignum from BigInteger to int
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Feature #12245 ( ref #4293 )
Fixed the issue with my previous PR (#4571)
There was already an implementation of Integer#round. I noticed it had an implementation in Integer that covered both Fixnum and Bignum. Would this be a preferable way of doing things, or is my current method of splitting the implementation between Fixnum and Bignum acceptable?