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(); }
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(); }
return getCanonicalObject(r.getQuotient()); else return Rational.simplify(r);
return getCanonicalObject(r.getQuotient()); else return Rational.simplify(r);
else final Number qa = a.getQuotient(); final Number qb = b.getQuotient(); final int qCmp = OWLRealUtils.compare(qa, qb); if (qCmp == 0)
else final Number qa = a.getQuotient(); final Number qb = b.getQuotient(); final int qCmp = OWLRealUtils.compare(qa, qb); if (qCmp == 0)