public static Number numberRemainder(Number x, Number y) { if (Zero.numberIsZero(y)) { throw new ArithmeticException("Divide by zero"); } Ops type = OpType.findOpType(x, y); if (type == Ops.DOUBLE) { return Remainder.doubleRemainder(Coercion.toDouble(x), Coercion.toDouble(y)); } else if (type == Ops.BIGDECIMAL) { return Remainder.bigDecimalRemainder(Coercion.toBigDecimal(x), Coercion.toBigDecimal(y)); } else if (type == Ops.RATIO) { return Remainder.ratioRemainder(Coercion.toRatio(x), Coercion.toRatio(y)); } else if (type == Ops.BIGINT) { return Remainder.bigIntRemainder(Coercion.toBigInt(x), Coercion.toBigInt(y)); } else { return Remainder.longRemainder(Coercion.toLong(x), Coercion.toLong(y)); } }
public int score(LuaValue value) { switch (value.type()) { case LuaValue.TTABLE: return value.length() == 0 ? 0 : componentCoercion.score(value.get(1)); case LuaValue.TUSERDATA: return inheritanceLevels(componentType, value.touserdata().getClass().getComponentType()); case LuaValue.TNIL: return SCORE_NULL_VALUE; default: return SCORE_UNCOERCIBLE; } }
public Object coerce(LuaValue value) { switch (value.type()) { case LuaValue.TTABLE: { int n = value.length(); Object a = Array.newInstance(componentType, n); for (int i = 0; i < n; i++) Array.set(a, i, componentCoercion.coerce(value.get(i + 1))); return a; } case LuaValue.TUSERDATA: return value.touserdata(); case LuaValue.TNIL: return null; default: return null; } }