@JRubyMethod public IRubyObject ceil(ThreadContext context) { checkFloatDomain(); BigInteger ceil = value.setScale(0, RoundingMode.CEILING).toBigInteger(); if (ceil.compareTo(BigInteger.valueOf((long) ceil.intValue())) == 0) { // It fits in Fixnum return RubyInteger.int2fix(context.runtime, ceil.intValue()); } return RubyBignum.newBignum(context.runtime, ceil); }
@JRubyMethod public IRubyObject ceil(ThreadContext context) { checkFloatDomain(); BigInteger ceil = value.setScale(0, RoundingMode.CEILING).toBigInteger(); if (ceil.compareTo(BigInteger.valueOf((long) ceil.intValue())) == 0) { // It fits in Fixnum return RubyInteger.int2fix(context.runtime, ceil.intValue()); } return RubyBignum.newBignum(context.runtime, ceil); }
@JRubyMethod(name = "ceil", optional = 1, compat = CompatVersion.RUBY1_9) public IRubyObject ceil19(IRubyObject[] args) { checkFloatDomain(); if (args.length == 0) { BigInteger ceil = value.setScale(0, RoundingMode.CEILING).toBigInteger(); if (ceil.compareTo(BigInteger.valueOf((long)ceil.intValue())) == 0) { // it fits in Fixnum return RubyInteger.int2fix(getRuntime(), ceil.intValue()); } return RubyBignum.newBignum(getRuntime(), ceil); } return ceil(args); }
@JRubyMethod(name = "ceil", optional = 1, compat = CompatVersion.RUBY1_9) public IRubyObject ceil19(IRubyObject[] args) { checkFloatDomain(); if (args.length == 0) { BigInteger ceil = value.setScale(0, RoundingMode.CEILING).toBigInteger(); if (ceil.compareTo(BigInteger.valueOf((long)ceil.intValue())) == 0) { // it fits in Fixnum return RubyInteger.int2fix(getRuntime(), ceil.intValue()); } return RubyBignum.newBignum(getRuntime(), ceil); } return ceil(args); }
/** * Based on Gergő Nemes's Gamma Function approximation formula, we compute * Log Gamma function for real number x. * @param recv Math module * @param x a real number * @return 2-element array [ln(Γ(x)), sgn] for real number x, * where sgn is the sign of Γ(x) when exponentiated * @see #gamma(ThreadContext, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.builtin.IRubyObject) */ @JRubyMethod(name = "lgamma", required = 1, module = true, visibility = Visibility.PRIVATE) public static RubyArray lgamma(ThreadContext context, IRubyObject recv, IRubyObject x) { double value = RubyKernel.new_float(context.runtime, x).getDoubleValue(); // JRUBY-4653: Could this error checking done more elegantly? if (value < 0 && Double.isInfinite(value)) throw context.runtime.newMathDomainError("lgamma"); NemesLogGamma l = new NemesLogGamma(value); return RubyArray.newArray(context.runtime, RubyFloat.newFloat(context.runtime, l.value), RubyInteger.int2fix(context.runtime, (int) l.sign)); }
/** * Based on Gergő Nemes's Gamma Function approximation formula, we compute * Log Gamma function for real number x. * @param recv Math module * @param x a real number * @return 2-element array [ln(Γ(x)), sgn] for real number x, * where sgn is the sign of Γ(x) when exponentiated * @see #gamma(ThreadContext, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.builtin.IRubyObject) */ @JRubyMethod(name = "lgamma", required = 1, module = true, visibility = Visibility.PRIVATE) public static RubyArray lgamma(ThreadContext context, IRubyObject recv, IRubyObject x) { double value = RubyKernel.new_float(context.runtime, x).getDoubleValue(); // JRUBY-4653: Could this error checking done more elegantly? if (value < 0 && Double.isInfinite(value)) throw context.runtime.newMathDomainError("lgamma"); NemesLogGamma l = new NemesLogGamma(value); return RubyArray.newArray(context.runtime, RubyFloat.newFloat(context.runtime, l.value), RubyInteger.int2fix(context.runtime, (int) l.sign)); }
/** * Based on Gergő Nemes's Gamma Function approximation formula, we compute * Log Gamma function for real number x. * @param recv Math module * @param x a real number * @return 2-element array [ln(Γ(x)), sgn] for real number x, * where sgn is the sign of Γ(x) when exponentiated * @see #gamma(org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.builtin.IRubyObject) */ @JRubyMethod(name = "lgamma", required = 1, module = true, visibility = Visibility.PRIVATE, compat = CompatVersion.RUBY1_9) public static RubyArray lgamma(IRubyObject recv, IRubyObject x) { Ruby runtime = recv.getRuntime(); double value = RubyKernel.new_float(recv, x).getDoubleValue(); // JRUBY-4653: Could this error checking done more elegantly? if (value < 0 && Double.isInfinite(value)) { throw recv.getRuntime().newMathDomainError("lgamma"); } NemesLogGamma l = new NemesLogGamma(value); IRubyObject[] ary = new IRubyObject[2]; ary[0] = RubyFloat.newFloat(runtime, l.value); ary[1] = RubyInteger.int2fix(runtime, (int) l.sign); return RubyArray.newArray(recv.getRuntime(), ary); }
/** * Based on Gergő Nemes's Gamma Function approximation formula, we compute * Log Gamma function for real number x. * @param recv Math module * @param x a real number * @return 2-element array [ln(Γ(x)), sgn] for real number x, * where sgn is the sign of Γ(x) when exponentiated * @see #gamma(org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.builtin.IRubyObject) */ @JRubyMethod(name = "lgamma", required = 1, module = true, visibility = Visibility.PRIVATE, compat = CompatVersion.RUBY1_9) public static RubyArray lgamma(IRubyObject recv, IRubyObject x) { Ruby runtime = recv.getRuntime(); double value = RubyKernel.new_float(recv, x).getDoubleValue(); // JRUBY-4653: Could this error checking done more elegantly? if (value < 0 && Double.isInfinite(value)) { throw recv.getRuntime().newMathDomainError("lgamma"); } NemesLogGamma l = new NemesLogGamma(value); IRubyObject[] ary = new IRubyObject[2]; ary[0] = RubyFloat.newFloat(runtime, l.value); ary[1] = RubyInteger.int2fix(runtime, (int) l.sign); return RubyArray.newArray(recv.getRuntime(), ary); }