New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ruby 2.4] Implemented Integer#ceil, #floor, #truncate #4616

Merged
merged 3 commits into from Jun 13, 2017

Conversation

Projects
None yet
3 participants
@whwilder
Contributor

whwilder commented May 19, 2017

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?

*
*/
@Override
public IRubyObject ceil(ThreadContext context, IRubyObject args){

This comment has been minimized.

@kares

kares May 21, 2017

Member

args should be named arg or something (everywhere) - otherwise its a bit confusing.

BigInteger self = value;
if (self.compareTo(BigInteger.ZERO) == 1){
return floor(context, args);
} else if (self.compareTo(BigInteger.ZERO) == -1){

This comment has been minimized.

@kares

kares May 21, 2017

Member

maybe compareTo could be performance only once and saved in a local instead of twice

BigInteger self = value;
if (ndigits.compareTo(BigInteger.ZERO) == 1){
return convertToFloat();
} else if (ndigits.compareTo(BigInteger.ZERO) == 0){

This comment has been minimized.

@kares

kares May 21, 2017

Member

maybe compareTo could be performance only once and saved in a local instead of twice

*/
@Override
public IRubyObject floor(ThreadContext context, IRubyObject args){
BigInteger ndigits = args.convertToInteger().getBigIntegerValue();

This comment has been minimized.

@kares

kares May 21, 2017

Member

is the arg really going to be a Bignul value isn't it an over-kill ?

*/
@Override
public IRubyObject ceil(ThreadContext context, IRubyObject args){
BigInteger ndigits = args.convertToInteger().getBigIntegerValue();

This comment has been minimized.

@kares

kares May 21, 2017

Member

is the arg really going to be a Bignul value isn't it an over-kill ?

Fixed some style issues:
* changed "args" to "arg" in ceil, floor, and truncate
* changed type of "ndigits" in RubyBignum from BigInteger to int

@headius headius added this to the JRuby 9.2.0.0 milestone Jun 13, 2017

@headius headius merged commit fd45d77 into jruby:ruby-2.4 Jun 13, 2017

1 check failed

continuous-integration/travis-ci/pr The Travis CI build failed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment