public static Number integerSum(final Number a, final Number b) { final Type ta = Type.get(a.getClass()); final Type tb = Type.get(b.getClass()); if (ta == null || tb == null) { final String msg = format("Unexpected number type %s,%s passed to integerSum method.", a.getClass().getCanonicalName(), b.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } final BigInteger ia = bigInteger(a); final BigInteger ib = bigInteger(b); return shrinkBigInteger(ia.add(ib)); }
public static Number integerSum(final Number a, final Number b) { final Type ta = Type.get(a.getClass()); final Type tb = Type.get(b.getClass()); if (ta == null || tb == null) { final String msg = format("Unexpected number type %s,%s passed to integerSum method.", a.getClass().getCanonicalName(), b.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } final BigInteger ia = bigInteger(a); final BigInteger ib = bigInteger(b); return shrinkBigInteger(ia.add(ib)); }
public static Number integerDifference(final Number a, final Number b) { final Type ta = Type.get(a.getClass()); final Type tb = Type.get(b.getClass()); if (ta == null || tb == null) { final String msg = format("Unexpected number type %s,%s passed to integerDifference method.", a.getClass().getCanonicalName(), b.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } final BigInteger ia = bigInteger(a); final BigInteger ib = bigInteger(b); return shrinkBigInteger(ia.subtract(ib)); }
public static Number integerDifference(final Number a, final Number b) { final Type ta = Type.get(a.getClass()); final Type tb = Type.get(b.getClass()); if (ta == null || tb == null) { final String msg = format("Unexpected number type %s,%s passed to integerDifference method.", a.getClass().getCanonicalName(), b.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } final BigInteger ia = bigInteger(a); final BigInteger ib = bigInteger(b); return shrinkBigInteger(ia.subtract(ib)); }
return shrinkBigInteger(bigInteger(n).add(BigInteger.ONE)); else
return shrinkBigInteger(bigInteger(n).subtract(BigInteger.ONE)); else
return shrinkBigInteger(bigInteger(n).add(BigInteger.ONE)); else
return shrinkBigInteger(bigInteger(n).subtract(BigInteger.ONE)); else
public static Number roundCeiling(final Number n) { final Type t = Type.get(n.getClass()); if (t == null) { final String msg = format("Unexpected number type %s passed to roundDown method.", n.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } if (t.isIntegerOnly()) return n; if (Type.BIG_DECIMAL.equals(t)) { final BigDecimal d = (BigDecimal) n; final BigDecimal[] dandr = d.divideAndRemainder(BigDecimal.ONE); if (dandr[1].equals(BigDecimal.ZERO) || d.signum() == -1) return shrinkBigInteger(dandr[0].toBigIntegerExact()); else return shrinkBigInteger(dandr[0].toBigIntegerExact().add(BigInteger.ONE)); } else if (Type.RATIONAL.equals(t)) { final Rational r = (Rational) n; return roundCeiling(r.getQuotient()); } else throw new IllegalStateException(); }
public static Number roundFloor(final Number n) { final Type t = Type.get(n.getClass()); if (t == null) { final String msg = format("Unexpected number type %s passed to roundDown method.", n.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } if (t.isIntegerOnly()) return n; if (Type.BIG_DECIMAL.equals(t)) { final BigDecimal d = (BigDecimal) n; final BigDecimal[] dandr = d.divideAndRemainder(BigDecimal.ONE); if (dandr[1].equals(BigDecimal.ZERO) || d.signum() == 1) return shrinkBigInteger(dandr[0].toBigIntegerExact()); else return shrinkBigInteger(dandr[0].toBigIntegerExact().subtract(BigInteger.ONE)); } else if (Type.RATIONAL.equals(t)) { final Rational r = (Rational) n; return roundFloor(r.getQuotient()); } else throw new IllegalStateException(); }
public static Number roundCeiling(final Number n) { final Type t = Type.get(n.getClass()); if (t == null) { final String msg = format("Unexpected number type %s passed to roundDown method.", n.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } if (t.isIntegerOnly()) return n; if (Type.BIG_DECIMAL.equals(t)) { final BigDecimal d = (BigDecimal) n; final BigDecimal[] dandr = d.divideAndRemainder(BigDecimal.ONE); if (dandr[1].equals(BigDecimal.ZERO) || d.signum() == -1) return shrinkBigInteger(dandr[0].toBigIntegerExact()); else return shrinkBigInteger(dandr[0].toBigIntegerExact().add(BigInteger.ONE)); } else if (Type.RATIONAL.equals(t)) { final Rational r = (Rational) n; return roundCeiling(r.getQuotient()); } else throw new IllegalStateException(); }
public static Number roundFloor(final Number n) { final Type t = Type.get(n.getClass()); if (t == null) { final String msg = format("Unexpected number type %s passed to roundDown method.", n.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } if (t.isIntegerOnly()) return n; if (Type.BIG_DECIMAL.equals(t)) { final BigDecimal d = (BigDecimal) n; final BigDecimal[] dandr = d.divideAndRemainder(BigDecimal.ONE); if (dandr[1].equals(BigDecimal.ZERO) || d.signum() == 1) return shrinkBigInteger(dandr[0].toBigIntegerExact()); else return shrinkBigInteger(dandr[0].toBigIntegerExact().subtract(BigInteger.ONE)); } else if (Type.RATIONAL.equals(t)) { final Rational r = (Rational) n; return roundFloor(r.getQuotient()); } else throw new IllegalStateException(); }
public static Number roundDown(final Number n) { final Type t = Type.get(n.getClass()); if (t == null) { final String msg = format("Unexpected number type %s passed to roundDown method.", n.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } if (t.isIntegerOnly()) return n; if (Type.BIG_DECIMAL.equals(t)) { final BigDecimal d = (BigDecimal) n; return shrinkBigInteger(d.divideToIntegralValue(BigDecimal.ONE).toBigIntegerExact()); } else if (Type.RATIONAL.equals(t)) { final Rational r = (Rational) n; return roundDown(r.getQuotient()); } else throw new IllegalStateException(); }
public static Number roundDown(final Number n) { final Type t = Type.get(n.getClass()); if (t == null) { final String msg = format("Unexpected number type %s passed to roundDown method.", n.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } if (t.isIntegerOnly()) return n; if (Type.BIG_DECIMAL.equals(t)) { final BigDecimal d = (BigDecimal) n; return shrinkBigInteger(d.divideToIntegralValue(BigDecimal.ONE).toBigIntegerExact()); } else if (Type.RATIONAL.equals(t)) { final Rational r = (Rational) n; return roundDown(r.getQuotient()); } else throw new IllegalStateException(); }
return shrinkBigInteger(bigInteger(n)); else if (Type.RATIONAL.equals(t))
return shrinkBigInteger(bigInteger(n)); else if (Type.RATIONAL.equals(t))