public static boolean isInteger(final Number n) { final Type t = Type.get(n.getClass()); if (t == null) { final String msg = format("Unexpected number type %s passed to isInteger method.", n.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } if (t.isIntegerOnly()) return true; if (t.equals(Type.BIG_DECIMAL)) { final BigDecimal decVal = (BigDecimal) n; return BigInteger.ZERO.equals(decVal.unscaledValue()) || decVal.stripTrailingZeros().scale() <= 0; } else if (t.equals(Type.RATIONAL)) { final Rational ratVal = (Rational) n; if (compare(1, ratVal.getDenominator()) == 0) return true; else return compare(1, Rational.simplify(ratVal).getDenominator()) == 0; } return false; }
public static boolean isInteger(final Number n) { final Type t = Type.get(n.getClass()); if (t == null) { final String msg = format("Unexpected number type %s passed to isInteger method.", n.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } if (t.isIntegerOnly()) return true; if (t.equals(Type.BIG_DECIMAL)) { final BigDecimal decVal = (BigDecimal) n; return BigInteger.ZERO.equals(decVal.unscaledValue()) || decVal.stripTrailingZeros().scale() <= 0; } else if (t.equals(Type.RATIONAL)) { final Rational ratVal = (Rational) n; if (compare(1, ratVal.getDenominator()) == 0) return true; else return compare(1, Rational.simplify(ratVal).getDenominator()) == 0; } return false; }
return getCanonicalObject(r.getQuotient()); else return Rational.simplify(r);
return getCanonicalObject(r.getQuotient()); else return Rational.simplify(r);
if (compare(1, r.getDenominator()) != 0) r = Rational.simplify(r); if (compare(1, r.getDenominator()) != 0) throw new IllegalArgumentException();
if (compare(1, r.getDenominator()) != 0) r = Rational.simplify(r); if (compare(1, r.getDenominator()) != 0) throw new IllegalArgumentException();
@Override public ATermAppl getCanonicalRepresentation(final ATermAppl input) throws InvalidLiteralException { final Number n = getValue(input); if (n instanceof Rational) { final String canonicalForm = Rational.simplify((Rational) n).toString(); if (canonicalForm.equals(ATermUtils.getLiteralValue(input))) return input; else return ATermUtils.makeTypedLiteral(canonicalForm, getName()); } else return OWLReal.getInstance().getLiteral(OWLRealUtils.getCanonicalObject(n)); }
@Override public ATermAppl getCanonicalRepresentation(final ATermAppl input) throws InvalidLiteralException { final Number n = getValue(input); if (n instanceof Rational) { final String canonicalForm = Rational.simplify((Rational) n).toString(); if (canonicalForm.equals(ATermUtils.getLiteralValue(input))) return input; else return ATermUtils.makeTypedLiteral(canonicalForm, getName()); } else return OWLReal.getInstance().getLiteral(OWLRealUtils.getCanonicalObject(n)); }