@Deprecated public IRubyObject op_pow19(ThreadContext context, IRubyObject other) { return op_pow(context, other); }
@Deprecated public IRubyObject op_pow19(ThreadContext context, IRubyObject other) { return op_pow(context, other); }
private IRubyObject powerFixnum(ThreadContext context, long other) { Ruby runtime = context.runtime; if (other == 0) { return RubyFixnum.one(runtime); } if (other == 1) { return this; } if (other > 0) { return RubyBignum.newBignum(runtime, value).op_pow(context, other); } return RubyFloat.newFloat(runtime, Math.pow(value, other)); }
private IRubyObject powerFixnum(ThreadContext context, long other) { Ruby runtime = context.runtime; if (other == 0) { return RubyFixnum.one(runtime); } if (other == 1) { return this; } if (other > 0) { return RubyBignum.newBignum(runtime, value).op_pow(context, other); } return RubyFloat.newFloat(runtime, Math.pow(value, other)); }
while (y % 2 == 0) { if (!fitSqrtLong(x)) { IRubyObject v = RubyBignum.newBignum(runtime, x).op_pow(context, y); if (z != 1) v = RubyBignum.newBignum(runtime, neg ? -z : z).op_mul(context, v); return (RubyNumeric) v; IRubyObject v = RubyBignum.newBignum(runtime, x).op_pow(context, y); if (z != 1) v = RubyBignum.newBignum(runtime, neg ? -z : z).op_mul(context, v); return (RubyNumeric) v;
while (y % 2 == 0) { if (!fitSqrtLong(x)) { IRubyObject v = RubyBignum.newBignum(runtime, x).op_pow(context, y); if (z != 1) v = RubyBignum.newBignum(runtime, neg ? -z : z).op_mul(context, v); return (RubyNumeric) v; IRubyObject v = RubyBignum.newBignum(runtime, x).op_pow(context, y); if (z != 1) v = RubyBignum.newBignum(runtime, neg ? -z : z).op_mul(context, v); return (RubyNumeric) v;
while (y % 2 == 0) { if (!fitSqrtLong(x)) { IRubyObject v = RubyBignum.newBignum(runtime, RubyBignum.fix2big(RubyFixnum.newFixnum(runtime, x))).op_pow(context, RubyFixnum.newFixnum(runtime, y)); if (z != 1) v = RubyBignum.newBignum(runtime, RubyBignum.fix2big(RubyFixnum.newFixnum(runtime, neg ? -z : z))).op_mul19(context, v); return v; BigInteger bigXZ = bigX.multiply(bigX); if (bigXZ.divide(bigX).longValue() != z) { IRubyObject v = RubyBignum.newBignum(runtime, RubyBignum.fix2big(RubyFixnum.newFixnum(runtime, x))).op_pow(context, RubyFixnum.newFixnum(runtime, y)); if (z != 1) v = RubyBignum.newBignum(runtime, RubyBignum.fix2big(RubyFixnum.newFixnum(runtime, neg ? -z : z))).op_mul19(context, v); return v;
while (y % 2 == 0) { if (!fitSqrtLong(x)) { IRubyObject v = RubyBignum.newBignum(runtime, RubyBignum.fix2big(RubyFixnum.newFixnum(runtime, x))).op_pow(context, RubyFixnum.newFixnum(runtime, y)); if (z != 1) v = RubyBignum.newBignum(runtime, RubyBignum.fix2big(RubyFixnum.newFixnum(runtime, neg ? -z : z))).op_mul19(context, v); return v; BigInteger bigXZ = bigX.multiply(bigX); if (bigXZ.divide(bigX).longValue() != z) { IRubyObject v = RubyBignum.newBignum(runtime, RubyBignum.fix2big(RubyFixnum.newFixnum(runtime, x))).op_pow(context, RubyFixnum.newFixnum(runtime, y)); if (z != 1) v = RubyBignum.newBignum(runtime, RubyBignum.fix2big(RubyFixnum.newFixnum(runtime, neg ? -z : z))).op_mul19(context, v); return v;
/** rb_big_pow * */ @JRubyMethod(name = {"**", "power"}, required = 1) public IRubyObject op_pow(ThreadContext context, IRubyObject other) { double d; if (other instanceof RubyFixnum) { RubyFixnum fix = (RubyFixnum) other; long fixValue = fix.getLongValue(); return op_pow(context, fixValue); } else if (other instanceof RubyBignum) { d = ((RubyBignum) other).getDoubleValue(); getRuntime().getWarnings().warn(ID.MAY_BE_TOO_BIG, "in a**b, b may be too big"); } else if (other instanceof RubyFloat) { d = ((RubyFloat) other).getDoubleValue(); } else { return coerceBin(context, "**", other); } return RubyFloat.newFloat(getRuntime(), Math.pow(big2dbl(this), d)); }
/** rb_big_pow * */ @JRubyMethod(name = {"**", "power"}, required = 1) public IRubyObject op_pow(ThreadContext context, IRubyObject other) { double d; if (other instanceof RubyFixnum) { RubyFixnum fix = (RubyFixnum) other; long fixValue = fix.getLongValue(); return op_pow(context, fixValue); } else if (other instanceof RubyBignum) { d = ((RubyBignum) other).getDoubleValue(); getRuntime().getWarnings().warn(ID.MAY_BE_TOO_BIG, "in a**b, b may be too big"); } else if (other instanceof RubyFloat) { d = ((RubyFloat) other).getDoubleValue(); } else { return coerceBin(context, "**", other); } return RubyFloat.newFloat(getRuntime(), Math.pow(big2dbl(this), d)); }
/** rb_big_pow * */ @Override @JRubyMethod(name = {"**", "power"}, required = 1) public IRubyObject op_pow(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; if (other == RubyFixnum.zero(runtime)) return RubyFixnum.one(runtime); final double d; if (other instanceof RubyFloat) { d = ((RubyFloat) other).getDoubleValue(); if (compareTo(RubyFixnum.zero(runtime)) == -1 && d != Math.round(d)) { RubyComplex complex = RubyComplex.newComplexRaw(context.runtime, this); return sites(context).op_exp.call(context, complex, complex, other); } } else if (other instanceof RubyBignum) { d = ((RubyBignum) other).getDoubleValue(); context.runtime.getWarnings().warn(ID.MAY_BE_TOO_BIG, "in a**b, b may be too big"); } else if (other instanceof RubyFixnum) { return op_pow(context, other.convertToInteger().getLongValue()); } else { return coerceBin(context, sites(context).op_exp, other); } return pow(runtime, d); }
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); }
/** rb_big_pow * */ @Override @JRubyMethod(name = {"**", "power"}, required = 1) public IRubyObject op_pow(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; if (other == RubyFixnum.zero(runtime)) return RubyFixnum.one(runtime); final double d; if (other instanceof RubyFloat) { d = ((RubyFloat) other).getDoubleValue(); if (compareTo(RubyFixnum.zero(runtime)) == -1 && d != Math.round(d)) { RubyComplex complex = RubyComplex.newComplexRaw(context.runtime, this); return sites(context).op_exp.call(context, complex, complex, other); } } else if (other instanceof RubyBignum) { d = ((RubyBignum) other).getDoubleValue(); context.runtime.getWarnings().warn(ID.MAY_BE_TOO_BIG, "in a**b, b may be too big"); } else if (other instanceof RubyFixnum) { return op_pow(context, other.convertToInteger().getLongValue()); } else { return coerceBin(context, sites(context).op_exp, other); } return pow(runtime, d); }
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); }