public boolean equals(Decimal other) { return comparesTo(other) == 0; }
public boolean isOne() { Decimal one = one(); return comparesTo(one) == 0; }
public boolean equals(Decimal value, Decimal maxDifference) { Decimal diff = this.subtract(value).absolute(); return diff.comparesTo(maxDifference) <= 0; }
private void testCompares(String v1, String v2, int outcome) throws UcumException { Decimal d1 = new Decimal(v1); Decimal d2 = new Decimal(v2); int result = d1.comparesTo(d2); check(result == outcome, "Compare fail: "+v1+".compares("+v2+") should be "+Integer.toString(outcome)+" but was "+Integer.toString(result)); }
private void runConversionCase(XmlPullParser xpp) throws XmlPullParserException, IOException, UcumException { String id = xpp.getAttributeValue(null, "id"); String value = xpp.getAttributeValue(null, "value"); String srcUnit = xpp.getAttributeValue(null, "srcUnit"); String dstUnit = xpp.getAttributeValue(null, "dstUnit"); String outcome = xpp.getAttributeValue(null, "outcome"); System.out.println("case "+id+": "+value+" "+srcUnit+" -> "+outcome+" "+dstUnit); Decimal res = ucumSvc.convert(new Decimal(value), srcUnit, dstUnit); debug("Convert Test "+id+": the value '"+value+" "+srcUnit+"' ==> "+res.toString()+" "+dstUnit); // if (!res.toPlainString().equals(outcome)) { - that assumes that we can get the precision right, which we can't if (res.comparesTo(new Decimal(outcome)) != 0) { errCount++; System.err.println("Test "+id+": The value '"+outcome+"' was expected the result was "+res.toString()); } while (xpp.getEventType() != XmlPullParser.END_TAG) xpp.next(); xpp.next(); }
public int asInteger() throws UcumException { if (!isWholeNumber()) throw new UcumException("Unable to represent "+toString()+" as an integer"); if (comparesTo(new Decimal(Integer.MIN_VALUE)) < 0) throw new UcumException("Unable to represent "+toString()+" as a signed 8 byte integer"); if (comparesTo(new Decimal(Integer.MAX_VALUE)) > 0) throw new UcumException("Unable to represent "+toString()+" as a signed 8 byte integer"); return Integer.parseInt(asDecimal()); }
private void runMultiplicationCase(XmlPullParser xpp) throws XmlPullParserException, IOException, UcumException { String id = xpp.getAttributeValue(null, "id"); String v1 = xpp.getAttributeValue(null, "v1"); String u1 = xpp.getAttributeValue(null, "u1"); String v2 = xpp.getAttributeValue(null, "v2"); String u2 = xpp.getAttributeValue(null, "u2"); String vRes = xpp.getAttributeValue(null, "vRes"); String uRes = xpp.getAttributeValue(null, "uRes"); Pair o1 = new Pair(new Decimal(v1), u1); Pair o2 = new Pair(new Decimal(v2), u2); Pair o3 = ucumSvc.multiply(o1, o2); debug("Multiplication Test "+id+": the value '"+v1+" "+u1+"' * '"+v2+" "+u2+"' ==> "+o3.getValue().toString()+" "+o3.getCode()); // if (!res.toPlainString().equals(outcome)) { - that assumes that we can get the precision right, which we can't if (o3.getValue().comparesTo(new Decimal(vRes)) != 0 || !o3.getCode().equals(uRes)) { errCount++; System.err.println("Test "+id+": The value '"+vRes+" "+uRes+"' was expected, but the result was "+o3.getValue().toString()+" "+o3.getCode()); } while (xpp.getEventType() != XmlPullParser.END_TAG) xpp.next(); xpp.next(); }
public boolean equals(Decimal other) { return comparesTo(other) == 0; }
public boolean isOne() { Decimal one = one(); return comparesTo(one) == 0; }
public boolean equals(Decimal value, Decimal maxDifference) { Decimal diff = this.subtract(value).absolute(); return diff.comparesTo(maxDifference) <= 0; }
private void testCompares(String v1, String v2, int outcome) throws UcumException { Decimal d1 = new Decimal(v1); Decimal d2 = new Decimal(v2); int result = d1.comparesTo(d2); check(result == outcome, "Compare fail: "+v1+".compares("+v2+") should be "+Integer.toString(outcome)+" but was "+Integer.toString(result)); }
private void runConversionCase(XmlPullParser xpp) throws XmlPullParserException, IOException, UcumException { String id = xpp.getAttributeValue(null, "id"); String value = xpp.getAttributeValue(null, "value"); String srcUnit = xpp.getAttributeValue(null, "srcUnit"); String dstUnit = xpp.getAttributeValue(null, "dstUnit"); String outcome = xpp.getAttributeValue(null, "outcome"); System.out.println("case "+id+": "+value+" "+srcUnit+" -> "+outcome+" "+dstUnit); Decimal res = ucumSvc.convert(new Decimal(value), srcUnit, dstUnit); debug("Convert Test "+id+": the value '"+value+" "+srcUnit+"' ==> "+res.toString()+" "+dstUnit); // if (!res.toPlainString().equals(outcome)) { - that assumes that we can get the precision right, which we can't if (res.comparesTo(new Decimal(outcome)) != 0) { errCount++; System.err.println("Test "+id+": The value '"+outcome+"' was expected the result was "+res.toString()); } while (xpp.getEventType() != XmlPullParser.END_TAG) xpp.next(); xpp.next(); }
public int asInteger() throws UcumException { if (!isWholeNumber()) throw new UcumException("Unable to represent "+toString()+" as an integer"); if (comparesTo(new Decimal(Integer.MIN_VALUE)) < 0) throw new UcumException("Unable to represent "+toString()+" as a signed 8 byte integer"); if (comparesTo(new Decimal(Integer.MAX_VALUE)) > 0) throw new UcumException("Unable to represent "+toString()+" as a signed 8 byte integer"); return Integer.parseInt(asDecimal()); }
private void runMultiplicationCase(XmlPullParser xpp) throws XmlPullParserException, IOException, UcumException { String id = xpp.getAttributeValue(null, "id"); String v1 = xpp.getAttributeValue(null, "v1"); String u1 = xpp.getAttributeValue(null, "u1"); String v2 = xpp.getAttributeValue(null, "v2"); String u2 = xpp.getAttributeValue(null, "u2"); String vRes = xpp.getAttributeValue(null, "vRes"); String uRes = xpp.getAttributeValue(null, "uRes"); Pair o1 = new Pair(new Decimal(v1), u1); Pair o2 = new Pair(new Decimal(v2), u2); Pair o3 = ucumSvc.multiply(o1, o2); debug("Multiplication Test "+id+": the value '"+v1+" "+u1+"' * '"+v2+" "+u2+"' ==> "+o3.getValue().toString()+" "+o3.getCode()); // if (!res.toPlainString().equals(outcome)) { - that assumes that we can get the precision right, which we can't if (o3.getValue().comparesTo(new Decimal(vRes)) != 0 || !o3.getCode().equals(uRes)) { errCount++; System.err.println("Test "+id+": The value '"+vRes+" "+uRes+"' was expected, but the result was "+o3.getValue().toString()+" "+o3.getCode()); } while (xpp.getEventType() != XmlPullParser.END_TAG) xpp.next(); xpp.next(); }