private IRubyObject powerOther19(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; long a = value; if (other instanceof RubyBignum) { if (other.callMethod(context, "<", RubyFixnum.zero(runtime)).isTrue()) { return RubyRational.newRationalRaw(runtime, this).callMethod(context, "**", other); } if (a == 0) return RubyFixnum.zero(runtime); if (a == 1) return RubyFixnum.one(runtime); if (a == -1) { return ((RubyBignum)other).even_p(context).isTrue() ? RubyFixnum.one(runtime) : RubyFixnum.minus_one(runtime); } RubyBignum.newBignum(runtime, RubyBignum.fix2big(this)).op_pow(context, other); } else if (other instanceof RubyFloat) { double b = ((RubyFloat)other).getValue(); 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); return RubyFloat.newFloat(runtime, Math.pow(a, b)); } return coerceBin(context, "**", other); }
private IRubyObject powerOther19(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; long a = value; if (other instanceof RubyBignum) { if (other.callMethod(context, "<", RubyFixnum.zero(runtime)).isTrue()) { return RubyRational.newRationalRaw(runtime, this).callMethod(context, "**", other); } if (a == 0) return RubyFixnum.zero(runtime); if (a == 1) return RubyFixnum.one(runtime); if (a == -1) { return ((RubyBignum)other).even_p(context).isTrue() ? RubyFixnum.one(runtime) : RubyFixnum.minus_one(runtime); } RubyBignum.newBignum(runtime, RubyBignum.fix2big(this)).op_pow(context, other); } else if (other instanceof RubyFloat) { double b = ((RubyFloat)other).getValue(); 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); return RubyFloat.newFloat(runtime, Math.pow(a, b)); } return coerceBin(context, "**", other); }
private IRubyObject powerOther(ThreadContext context, IRubyObject other) { final Ruby runtime = context.runtime; final long a = this.value; if (other instanceof RubyBignum) { if (sites(context).op_lt_bignum.call(context, other, other, RubyFixnum.zero(runtime)).isTrue()) { RubyRational rational = RubyRational.newRationalRaw(runtime, this); return numFuncall(context, rational, sites(context).op_exp_rational, other); } if (a == 0) return RubyFixnum.zero(runtime); if (a == 1) return RubyFixnum.one(runtime); if (a == -1) { return ((RubyBignum) other).even_p(context).isTrue() ? RubyFixnum.one(runtime) : RubyFixnum.minus_one(runtime); } return RubyBignum.newBignum(runtime, RubyBignum.long2big(a)).op_pow(context, other); } if (other instanceof RubyFloat) { double b = ((RubyFloat)other).getValue(); 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); return RubyFloat.newFloat(runtime, Math.pow(a, b)); } return coerceBin(context, sites(context).op_exp, other); }
private IRubyObject powerOther(ThreadContext context, IRubyObject other) { final Ruby runtime = context.runtime; final long a = this.value; if (other instanceof RubyBignum) { if (sites(context).op_lt_bignum.call(context, other, other, RubyFixnum.zero(runtime)).isTrue()) { RubyRational rational = RubyRational.newRationalRaw(runtime, this); return numFuncall(context, rational, sites(context).op_exp_rational, other); } if (a == 0) return RubyFixnum.zero(runtime); if (a == 1) return RubyFixnum.one(runtime); if (a == -1) { return ((RubyBignum) other).even_p(context).isTrue() ? RubyFixnum.one(runtime) : RubyFixnum.minus_one(runtime); } return RubyBignum.newBignum(runtime, RubyBignum.long2big(a)).op_pow(context, other); } if (other instanceof RubyFloat) { double b = ((RubyFloat)other).getValue(); 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); return RubyFloat.newFloat(runtime, Math.pow(a, b)); } return coerceBin(context, sites(context).op_exp, other); }