-
-
Notifications
You must be signed in to change notification settings - Fork 925
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
[ruby 2.4] Implemented Integer#ceil, #floor, #truncate #4616
Conversation
Integer#floor, and Integer#truncate
…/jruby into 2.4-integer-ceil-floor-truncate
* | ||
*/ | ||
@Override | ||
public IRubyObject ceil(ThreadContext context, IRubyObject args){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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?