org.jruby.Ruby.newZeroDivisionError()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(157)

本文整理了Java中org.jruby.Ruby.newZeroDivisionError方法的一些代码示例,展示了Ruby.newZeroDivisionError的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.newZeroDivisionError方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:newZeroDivisionError

Ruby.newZeroDivisionError介绍

暂无

代码示例

代码示例来源:origin: org.jruby/jruby-complete

private static boolean canonicalizeShouldNegate(ThreadContext context, RubyInteger den) {
  final int signum = den.signum();
  if (signum == 0) throw context.runtime.newZeroDivisionError();
  return signum < 0;
}

代码示例来源:origin: org.jruby/jruby-complete

private void checkZeroDivisionError(ThreadContext context, IRubyObject other) {
  if (other instanceof RubyFloat && ((RubyFloat) other).getDoubleValue() == 0.0d) {
    throw context.runtime.newZeroDivisionError();
  }
}

代码示例来源:origin: org.jruby/jruby-core

private void checkZeroDivisionError(ThreadContext context, IRubyObject other) {
  if (other instanceof RubyFloat && ((RubyFloat) other).getDoubleValue() == 0.0d) {
    throw context.runtime.newZeroDivisionError();
  }
}

代码示例来源:origin: org.jruby/jruby-core

private static boolean canonicalizeShouldNegate(ThreadContext context, RubyInteger den) {
  final int signum = den.signum();
  if (signum == 0) throw context.runtime.newZeroDivisionError();
  return signum < 0;
}

代码示例来源:origin: org.jruby/jruby-complete

private RubyInteger divideImpl(Ruby runtime, BigInteger otherValue) {
  if (otherValue.signum() == 0) throw runtime.newZeroDivisionError();
  final BigInteger result;
  if (value.signum() * otherValue.signum() == -1) {
    BigInteger[] results = value.divideAndRemainder(otherValue);
    result = results[1].signum() != 0 ? results[0].subtract(BigInteger.ONE) : results[0];
  } else {
    result = value.divide(otherValue);
  }
  return bignorm(runtime, result);
}

代码示例来源:origin: org.jruby/jruby-core

private RubyInteger divideImpl(Ruby runtime, BigInteger otherValue) {
  if (otherValue.signum() == 0) throw runtime.newZeroDivisionError();
  final BigInteger result;
  if (value.signum() * otherValue.signum() == -1) {
    BigInteger[] results = value.divideAndRemainder(otherValue);
    result = results[1].signum() != 0 ? results[0].subtract(BigInteger.ONE) : results[0];
  } else {
    result = value.divide(otherValue);
  }
  return bignorm(runtime, result);
}

代码示例来源:origin: org.jruby/jruby-complete

@Override
public IRubyObject op_mod(ThreadContext context, long other) {
  if (other == 0) throw context.runtime.newZeroDivisionError();
  BigInteger result = value.mod(long2big(other < 0 ? -other : other));
  if (other < 0 && result.signum() != 0) result = long2big(other).add(result);
  return bignorm(context.runtime, result);
}

代码示例来源:origin: org.jruby/jruby-complete

@Override
public IRubyObject idiv(ThreadContext context, IRubyObject other) {
  if (num2dbl(context, other) == 0.0) throw context.runtime.newZeroDivisionError();
  return f_floor(context, f_div(context, this, other));
}

代码示例来源:origin: org.jruby/jruby-core

@Override
public IRubyObject idiv(ThreadContext context, IRubyObject other) {
  if (num2dbl(context, other) == 0.0) throw context.runtime.newZeroDivisionError();
  return f_floor(context, f_div(context, this, other));
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

/** flo_mod
 * 
 */
@JRubyMethod(name = {"%", "modulo"}, required = 1, compat = CompatVersion.RUBY1_9)
public IRubyObject op_mod19(ThreadContext context, IRubyObject other) {
  if (!other.isNil() && other instanceof RubyNumeric
    && ((RubyNumeric)other).getDoubleValue() == 0) {
    throw context.runtime.newZeroDivisionError();
  }
  return op_mod(context, other);
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

@JRubyMethod(name = "divmod", required = 1, compat = RUBY1_9)
public IRubyObject divmod19(ThreadContext context, IRubyObject other) {
  if (!other.isNil() && other instanceof RubyFloat
      && ((RubyFloat)other).getDoubleValue() == 0) {
    throw context.runtime.newZeroDivisionError();
  }
  return divmod(context, other);
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

/** rb_big_modulo
 *
 */
@JRubyMethod(name = {"%", "modulo"}, required = 1, compat = RUBY1_9)
public IRubyObject op_mod19(ThreadContext context, IRubyObject other) {
  if (!other.isNil() && other instanceof RubyFloat
      && ((RubyFloat)other).getDoubleValue() == 0) {
    throw context.runtime.newZeroDivisionError();
  }
  return op_mod(context, other);
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

/** flo_divmod
 * 
 */
@JRubyMethod(name = "divmod", required = 1, compat = CompatVersion.RUBY1_9)
public IRubyObject divmod19(ThreadContext context, IRubyObject other) {
  if (!other.isNil() && other instanceof RubyNumeric
    && ((RubyNumeric)other).getDoubleValue() == 0) {
    throw context.runtime.newZeroDivisionError();
  }
  return divmod(context, other);
}

代码示例来源:origin: org.jruby/jruby-complete

public final RubyNumeric op_div(ThreadContext context, RubyInteger other) {
  if (other.isZero()) {
    throw context.runtime.newZeroDivisionError();
  }
  return f_muldiv(context, getMetaClass(), num, den, other, RubyFixnum.one(context.runtime), false);
}

代码示例来源:origin: org.jruby/jruby-complete

/** nurat_divmod
 * 
 */
@JRubyMethod(name = "divmod")
public IRubyObject op_divmod(ThreadContext context, IRubyObject other) {
  if (num2dbl(context, other) == 0.0) throw context.runtime.newZeroDivisionError();
  IRubyObject val = f_floor(context, f_div(context, this, other));
  return context.runtime.newArray(val, f_sub(context, this, f_mul(context, other, val)));
}

代码示例来源:origin: org.jruby/jruby-core

/** nurat_divmod
 * 
 */
@JRubyMethod(name = "divmod")
public IRubyObject op_divmod(ThreadContext context, IRubyObject other) {
  if (num2dbl(context, other) == 0.0) throw context.runtime.newZeroDivisionError();
  IRubyObject val = f_floor(context, f_div(context, this, other));
  return context.runtime.newArray(val, f_sub(context, this, f_mul(context, other, val)));
}

代码示例来源:origin: org.jruby/jruby-complete

private RubyInteger idiv(ThreadContext context, RubyRational val) {
  if (isNaN()) throw newNaNFloatDomainError(context.runtime);
  if (isInfinity()) { // NOTE: MRI is inconsistent with div(other, d) impl
    throw newInfinityFloatDomainError(context.runtime, infinitySign);
  }
  if (val.isZero()) throw context.runtime.newZeroDivisionError();
  BigDecimal result = this.value.multiply(toBigDecimal(val.getDenominator()))
                 .divideToIntegralValue(toBigDecimal(val.getNumerator()));
  return toInteger(context.runtime, result);
}

代码示例来源:origin: org.jruby/jruby-core

private RubyInteger idiv(ThreadContext context, RubyRational val) {
  if (isNaN()) throw newNaNFloatDomainError(context.runtime);
  if (isInfinity()) { // NOTE: MRI is inconsistent with div(other, d) impl
    throw newInfinityFloatDomainError(context.runtime, infinitySign);
  }
  if (val.isZero()) throw context.runtime.newZeroDivisionError();
  BigDecimal result = this.value.multiply(toBigDecimal(val.getDenominator()))
                 .divideToIntegralValue(toBigDecimal(val.getNumerator()));
  return toInteger(context.runtime, result);
}

代码示例来源:origin: org.jruby/jruby-complete

private static RubyNumeric canonicalizeInternal(ThreadContext context, RubyClass clazz, long num, long den) {
  if (den == 0)
    throw context.runtime.newZeroDivisionError();
  if (num == Long.MIN_VALUE && den == Long.MIN_VALUE)
    canonicalizeInternal(context, clazz, context.runtime.newFixnum(num), context.runtime.newFixnum(den));
  long gcd = i_gcd(num, den);
  RubyInteger _num = (RubyInteger) context.runtime.newFixnum(num).idiv(context, gcd);
  RubyInteger _den = (RubyInteger) context.runtime.newFixnum(den).idiv(context, gcd);
  if (Numeric.CANON && canonicalization && _den.getLongValue() == 1) return _num;
  return newRational(context.runtime, clazz, _num, _den);
}

代码示例来源:origin: org.jruby/jruby-core

private static RubyNumeric canonicalizeInternal(ThreadContext context, RubyClass clazz, long num, long den) {
  if (den == 0)
    throw context.runtime.newZeroDivisionError();
  if (num == Long.MIN_VALUE && den == Long.MIN_VALUE)
    canonicalizeInternal(context, clazz, context.runtime.newFixnum(num), context.runtime.newFixnum(den));
  long gcd = i_gcd(num, den);
  RubyInteger _num = (RubyInteger) context.runtime.newFixnum(num).idiv(context, gcd);
  RubyInteger _den = (RubyInteger) context.runtime.newFixnum(den).idiv(context, gcd);
  if (Numeric.CANON && canonicalization && _den.getLongValue() == 1) return _num;
  return newRational(context.runtime, clazz, _num, _den);
}

相关文章

Ruby类方法