import static org.jruby.CompatVersion.*;
Implementation of the Fixnum class.
@JRubyClass(name="Fixnum", parent="Integer", include="Precision")
for (int i = 0; i < runtime.fixnumCache.length; i++) {
private final long value;
public static final long MAX = (1L<<(BIT_SIZE - 1)) - 1;
public static final long MIN = -1 * MAX - 1;
short circuit for Fixnum key comparison
if (num.value == value) {
Ruby runtime = context.runtime;
long lvalue = this.value;
for (long i = 0; i < lvalue; i++) {
block.yield(context, nil);
for (long i = 0; i < lvalue; i++) {
return RubyEnumerator.enumeratorize(context.runtime, this, "times");
case 1: return to_s(args[0]);
if (base < 2 || base > 36) {
long result = value + otherValue;
long otherValue = other.value;
long result = value + otherValue;
return (~(original ^ other) & (original ^ result) & SIGN_BIT) != 0;
return (~(original ^ ~other) & (original ^ result) & SIGN_BIT) != 0;
long result = value - otherValue;
long otherValue = other.value;
long result = value - otherValue;
Ruby runtime = context.runtime;
Ruby runtime = context.runtime;
return RubyFixnum.zero(runtime);
long result = value * otherValue;
if (result / value == otherValue) {
fix_div
here is terrible MRI gotcha:
1.div 3.0 -> 0
1 / 3.0 -> 0.3333333333333333
MRI is also able to do it in one place by looking at current frame in rb_num_coerce_bin:
rb_funcall(x, ruby_frame->orig_func, 1, y);
also note that RubyFloat doesn't override Numeric.div
return idiv(context, other, "div");
return idiv(context, other, "/");
return idiv(context, other, "/");
Ruby runtime = context.runtime;
result = (x + 1) / y - 1;
result = (x - 1) / y - 1;
if (mod < 0 && y > 0 || mod > 0 && y < 0) {
final Ruby runtime = context.runtime;
integerDiv = RubyFixnum.newFixnum(runtime, -x);
if (mod < 0 && y > 0 || mod > 0 && y < 0) {
integerDiv = RubyFixnum.newFixnum(runtime, div);
return RubyArray.newArray(runtime, integerDiv, fixMod);
if (context.is19) return op_pow_19(context, other);
if (context.is19) throw context.runtime.newRuntimeError("bug: using direct op_pow(long) in 1.8 mode");
Ruby runtime = context.runtime;
return RubyFixnum.one(runtime);
Ruby runtime = context.runtime;
if (value < 0 && (d_other != Math.round(d_other))) {
Ruby runtime = context.runtime;
if (a == 0) return RubyFixnum.zero(runtime);
if (a == 1) return RubyFixnum.one(runtime);
if (b == 0.0 || a == 1) return runtime.newFloat(1.0);
if (a == 0) return runtime.newFloat(b < 0 ? 1.0 / 0.0 : 0.0);
Ruby runtime = context.runtime;
return RubyFixnum.one(runtime);
return b > 0 ? RubyFixnum.zero(runtime) : RubyNumeric.dbl2num(runtime, 1.0 / 0.0);
return RubyFixnum.one(runtime);
return b % 2 == 0 ? RubyFixnum.one(runtime) : RubyFixnum.minus_one(runtime);
return Numeric.int_pow(context, a, b);
return value == other.value;
return value == otherValue ? 0 : value > otherValue ? 1 : -1;
Ruby runtime = context.runtime;