Skip to content
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

whwilder
Copy link
Contributor

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){
Copy link
Member

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){
Copy link
Member

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){
Copy link
Member

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();
Copy link
Member

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();
Copy link
Member

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
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants