Skip to content

Commit

Permalink
cmpint should return {-1, 0, 1} for Fixnums.
Browse files Browse the repository at this point in the history
Fixes #2716: rb_cmpint difference from MRI.
  • Loading branch information
nirvdrum committed Mar 17, 2015
1 parent a6262fb commit 893aefe
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion core/src/main/java/org/jruby/RubyComparable.java
Expand Up @@ -69,7 +69,19 @@ public static RubyModule createComparable(Ruby runtime) {
*/
public static int cmpint(ThreadContext context, IRubyObject val, IRubyObject a, IRubyObject b) {
if (val.isNil()) cmperr(a, b);
if (val instanceof RubyFixnum) return RubyNumeric.fix2int((RubyFixnum) val);
if (val instanceof RubyFixnum) {
final int asInt = RubyNumeric.fix2int((RubyFixnum) val);

if (asInt > 0) {
return 1;
}

if (asInt < 0) {
return -1;
}

return 0;
}
if (val instanceof RubyBignum) return ((RubyBignum) val).getValue().signum() == -1 ? -1 : 1;

RubyFixnum zero = RubyFixnum.zero(context.runtime);
Expand Down

0 comments on commit 893aefe

Please sign in to comment.