use of android.icu.math.BigDecimal in project j2objc by google.
the class RuleBasedNumberFormat method format.
// -----------------------------------------------------------------------
// formatting implementation
// -----------------------------------------------------------------------
/**
* Bottleneck through which all the public format() methods
* that take a double pass. By the time we get here, we know
* which rule set we're using to do the formatting.
* @param number The number to format
* @param ruleSet The rule set to use to format the number
* @return The text that resulted from formatting the number
*/
private String format(double number, NFRuleSet ruleSet) {
// all API format() routines that take a double vector through
// here. Create an empty string buffer where the result will
// be built, and pass it to the rule set (along with an insertion
// position of 0 and the number being formatted) to the rule set
// for formatting
StringBuilder result = new StringBuilder();
if (getRoundingMode() != BigDecimal.ROUND_UNNECESSARY) {
// We convert to a string because BigDecimal insists on excessive precision.
number = new BigDecimal(Double.toString(number)).setScale(getMaximumFractionDigits(), roundingMode).doubleValue();
}
ruleSet.format(number, result, 0, 0);
postProcess(result, ruleSet);
return result.toString();
}
use of android.icu.math.BigDecimal in project j2objc by google.
the class IntlTestDecimalFormatAPI method testJB1871.
/**
* Problem 1: simply running
* decF4.setRoundingMode(java.math.BigDecimal.ROUND_HALF_UP) does not work
* as decF4.setRoundingIncrement(.0001) must also be run.
* Problem 2: decF4.format(8.88885) does not return 8.8889 as expected.
* You must run decF4.format(new BigDecimal(Double.valueOf(8.88885))) in
* order for this to work as expected.
* Problem 3: There seems to be no way to set half up to be the default
* rounding mode.
* We solved the problem with the code at the bottom of this page however
* this is not quite general purpose enough to include in icu4j. A static
* setDefaultRoundingMode function would solve the problem nicely. Also
* decimal places past 20 are not handled properly. A small ammount of work
* would make bring this up to snuff.
*/
@Test
public void testJB1871() {
// problem 2
double number = 8.88885;
String expected = "8.8889";
String pat = ",##0.0000";
DecimalFormat dec = new DecimalFormat(pat);
dec.setRoundingMode(BigDecimal.ROUND_HALF_UP);
double roundinginc = 0.0001;
dec.setRoundingIncrement(roundinginc);
String str = dec.format(number);
if (!str.equals(expected)) {
errln("Fail: " + number + " x \"" + pat + "\" = \"" + str + "\", expected \"" + expected + "\"");
}
pat = ",##0.0001";
dec = new DecimalFormat(pat);
dec.setRoundingMode(BigDecimal.ROUND_HALF_UP);
str = dec.format(number);
if (!str.equals(expected)) {
errln("Fail: " + number + " x \"" + pat + "\" = \"" + str + "\", expected \"" + expected + "\"");
}
// testing 20 decimal places
pat = ",##0.00000000000000000001";
dec = new DecimalFormat(pat);
BigDecimal bignumber = new BigDecimal("8.888888888888888888885");
expected = "8.88888888888888888889";
dec.setRoundingMode(BigDecimal.ROUND_HALF_UP);
str = dec.format(bignumber);
if (!str.equals(expected)) {
errln("Fail: " + bignumber + " x \"" + pat + "\" = \"" + str + "\", expected \"" + expected + "\"");
}
}
use of android.icu.math.BigDecimal in project j2objc by google.
the class DiagBigDecimalTest method diagdivide.
/* ----------------------------------------------------------------- */
/**
* Test the {@link android.icu.math.BigDecimal#divide} method.
*/
@Test
public void diagdivide() {
boolean flag = false;
android.icu.math.MathContext rmcd;
int rhu;
int rd;
int ru;
java.lang.RuntimeException e = null;
java.lang.ArithmeticException ae = null;
TestFmwk.assertTrue("div301", ((new android.icu.math.BigDecimal("1")).divide(new android.icu.math.BigDecimal("3"), mcdef).toString()).equals("0.333333333"));
TestFmwk.assertTrue("div302", ((new android.icu.math.BigDecimal("2")).divide(new android.icu.math.BigDecimal("3"), mcdef).toString()).equals("0.666666667"));
TestFmwk.assertTrue("div303", ((new android.icu.math.BigDecimal("2.4")).divide(new android.icu.math.BigDecimal("1"), mcdef).toString()).equals("2.4"));
TestFmwk.assertTrue("div304", ((new android.icu.math.BigDecimal("2.4")).divide(new android.icu.math.BigDecimal("-1"), mcdef).toString()).equals("-2.4"));
TestFmwk.assertTrue("div305", ((new android.icu.math.BigDecimal("-2.4")).divide(new android.icu.math.BigDecimal("1"), mcdef).toString()).equals("-2.4"));
TestFmwk.assertTrue("div306", ((new android.icu.math.BigDecimal("-2.4")).divide(new android.icu.math.BigDecimal("-1"), mcdef).toString()).equals("2.4"));
TestFmwk.assertTrue("div307", ((new android.icu.math.BigDecimal("2.40")).divide(new android.icu.math.BigDecimal("1"), mcdef).toString()).equals("2.4"));
TestFmwk.assertTrue("div308", ((new android.icu.math.BigDecimal("2.400")).divide(new android.icu.math.BigDecimal("1"), mcdef).toString()).equals("2.4"));
TestFmwk.assertTrue("div309", ((new android.icu.math.BigDecimal("2.4")).divide(new android.icu.math.BigDecimal("2"), mcdef).toString()).equals("1.2"));
TestFmwk.assertTrue("div310", ((new android.icu.math.BigDecimal("2.400")).divide(new android.icu.math.BigDecimal("2"), mcdef).toString()).equals("1.2"));
TestFmwk.assertTrue("div311", ((new android.icu.math.BigDecimal("2.")).divide(new android.icu.math.BigDecimal("2"), mcdef).toString()).equals("1"));
TestFmwk.assertTrue("div312", ((new android.icu.math.BigDecimal("20")).divide(new android.icu.math.BigDecimal("20"), mcdef).toString()).equals("1"));
TestFmwk.assertTrue("div313", ((new android.icu.math.BigDecimal("187")).divide(new android.icu.math.BigDecimal("187"), mcdef).toString()).equals("1"));
TestFmwk.assertTrue("div314", ((new android.icu.math.BigDecimal("5")).divide(new android.icu.math.BigDecimal("2"), mcdef).toString()).equals("2.5"));
TestFmwk.assertTrue("div315", ((new android.icu.math.BigDecimal("5")).divide(new android.icu.math.BigDecimal("2.0"), mcdef).toString()).equals("2.5"));
TestFmwk.assertTrue("div316", ((new android.icu.math.BigDecimal("5")).divide(new android.icu.math.BigDecimal("2.000"), mcdef).toString()).equals("2.5"));
TestFmwk.assertTrue("div317", ((new android.icu.math.BigDecimal("5")).divide(new android.icu.math.BigDecimal("0.200"), mcdef).toString()).equals("25"));
TestFmwk.assertTrue("div318", ((new android.icu.math.BigDecimal("999999999")).divide(new android.icu.math.BigDecimal("1"), mcdef).toString()).equals("999999999"));
TestFmwk.assertTrue("div319", ((new android.icu.math.BigDecimal("999999999.4")).divide(new android.icu.math.BigDecimal("1"), mcdef).toString()).equals("999999999"));
TestFmwk.assertTrue("div320", ((new android.icu.math.BigDecimal("999999999.5")).divide(new android.icu.math.BigDecimal("1"), mcdef).toString()).equals("1E+9"));
TestFmwk.assertTrue("div321", ((new android.icu.math.BigDecimal("999999999.9")).divide(new android.icu.math.BigDecimal("1"), mcdef).toString()).equals("1E+9"));
TestFmwk.assertTrue("div322", ((new android.icu.math.BigDecimal("999999999.999")).divide(new android.icu.math.BigDecimal("1"), mcdef).toString()).equals("1E+9"));
TestFmwk.assertTrue("div323", ((new android.icu.math.BigDecimal("0.0000E-50")).divide(new android.icu.math.BigDecimal("1"), mcdef).toString()).equals("0"));
// MC
TestFmwk.assertTrue("div325", ((new android.icu.math.BigDecimal("999999999")).divide(new android.icu.math.BigDecimal("1"), mcdef).toString()).equals("999999999"));
TestFmwk.assertTrue("div326", ((new android.icu.math.BigDecimal("999999999")).divide(new android.icu.math.BigDecimal("1"), mc6).toString()).equals("1E+9"));
TestFmwk.assertTrue("div327", ((new android.icu.math.BigDecimal("9999999")).divide(new android.icu.math.BigDecimal("1"), mc6).toString()).equals("1E+7"));
TestFmwk.assertTrue("div328", ((new android.icu.math.BigDecimal("999999")).divide(new android.icu.math.BigDecimal("1"), mc6).toString()).equals("999999"));
// check rounding explicitly [note: digits+1 truncation]
rmcd = new android.icu.math.MathContext(2, android.icu.math.MathContext.SCIENTIFIC, false, android.icu.math.MathContext.ROUND_CEILING);
TestFmwk.assertTrue("div330", ((new android.icu.math.BigDecimal("1.50")).divide(one, rmcd).toString()).equals("1.5"));
TestFmwk.assertTrue("div331", ((new android.icu.math.BigDecimal("1.51")).divide(one, rmcd).toString()).equals("1.6"));
TestFmwk.assertTrue("div332", ((new android.icu.math.BigDecimal("1.55")).divide(one, rmcd).toString()).equals("1.6"));
rmcd = new android.icu.math.MathContext(2, android.icu.math.MathContext.SCIENTIFIC, false, android.icu.math.MathContext.ROUND_DOWN);
TestFmwk.assertTrue("div333", ((new android.icu.math.BigDecimal("1.55")).divide(one, rmcd).toString()).equals("1.5"));
TestFmwk.assertTrue("div334", ((new android.icu.math.BigDecimal("1.59")).divide(one, rmcd).toString()).equals("1.5"));
rmcd = new android.icu.math.MathContext(2, android.icu.math.MathContext.SCIENTIFIC, false, android.icu.math.MathContext.ROUND_FLOOR);
TestFmwk.assertTrue("div335", ((new android.icu.math.BigDecimal("1.55")).divide(one, rmcd).toString()).equals("1.5"));
TestFmwk.assertTrue("div336", ((new android.icu.math.BigDecimal("1.59")).divide(one, rmcd).toString()).equals("1.5"));
rmcd = new android.icu.math.MathContext(2, android.icu.math.MathContext.SCIENTIFIC, false, android.icu.math.MathContext.ROUND_HALF_DOWN);
TestFmwk.assertTrue("div337", ((new android.icu.math.BigDecimal("1.45")).divide(one, rmcd).toString()).equals("1.4"));
TestFmwk.assertTrue("div338", ((new android.icu.math.BigDecimal("1.50")).divide(one, rmcd).toString()).equals("1.5"));
TestFmwk.assertTrue("div339", ((new android.icu.math.BigDecimal("1.55")).divide(one, rmcd).toString()).equals("1.5"));
rmcd = new android.icu.math.MathContext(2, android.icu.math.MathContext.SCIENTIFIC, false, android.icu.math.MathContext.ROUND_HALF_EVEN);
TestFmwk.assertTrue("div340", ((new android.icu.math.BigDecimal("1.45")).divide(one, rmcd).toString()).equals("1.4"));
TestFmwk.assertTrue("div341", ((new android.icu.math.BigDecimal("1.50")).divide(one, rmcd).toString()).equals("1.5"));
TestFmwk.assertTrue("div342", ((new android.icu.math.BigDecimal("1.55")).divide(one, rmcd).toString()).equals("1.6"));
rmcd = new android.icu.math.MathContext(2, android.icu.math.MathContext.SCIENTIFIC, false, android.icu.math.MathContext.ROUND_HALF_UP);
TestFmwk.assertTrue("div343", ((new android.icu.math.BigDecimal("1.45")).divide(one, rmcd).toString()).equals("1.5"));
TestFmwk.assertTrue("div344", ((new android.icu.math.BigDecimal("1.50")).divide(one, rmcd).toString()).equals("1.5"));
TestFmwk.assertTrue("div345", ((new android.icu.math.BigDecimal("1.55")).divide(one, rmcd).toString()).equals("1.6"));
rmcd = new android.icu.math.MathContext(2, android.icu.math.MathContext.SCIENTIFIC, false, android.icu.math.MathContext.ROUND_UP);
TestFmwk.assertTrue("div346", ((new android.icu.math.BigDecimal("1.50")).divide(one, rmcd).toString()).equals("1.5"));
TestFmwk.assertTrue("div347", ((new android.icu.math.BigDecimal("1.51")).divide(one, rmcd).toString()).equals("1.6"));
TestFmwk.assertTrue("div348", ((new android.icu.math.BigDecimal("1.55")).divide(one, rmcd).toString()).equals("1.6"));
// fixed point...
TestFmwk.assertTrue("div350", ((new android.icu.math.BigDecimal("1")).divide(new android.icu.math.BigDecimal("3")).toString()).equals("0"));
TestFmwk.assertTrue("div351", ((new android.icu.math.BigDecimal("2")).divide(new android.icu.math.BigDecimal("3")).toString()).equals("1"));
TestFmwk.assertTrue("div352", ((new android.icu.math.BigDecimal("2.4")).divide(new android.icu.math.BigDecimal("1")).toString()).equals("2.4"));
TestFmwk.assertTrue("div353", ((new android.icu.math.BigDecimal("2.4")).divide(new android.icu.math.BigDecimal("-1")).toString()).equals("-2.4"));
TestFmwk.assertTrue("div354", ((new android.icu.math.BigDecimal("-2.4")).divide(new android.icu.math.BigDecimal("1")).toString()).equals("-2.4"));
TestFmwk.assertTrue("div355", ((new android.icu.math.BigDecimal("-2.4")).divide(new android.icu.math.BigDecimal("-1")).toString()).equals("2.4"));
TestFmwk.assertTrue("div356", ((new android.icu.math.BigDecimal("2.40")).divide(new android.icu.math.BigDecimal("1")).toString()).equals("2.40"));
TestFmwk.assertTrue("div357", ((new android.icu.math.BigDecimal("2.400")).divide(new android.icu.math.BigDecimal("1")).toString()).equals("2.400"));
TestFmwk.assertTrue("div358", ((new android.icu.math.BigDecimal("2.4")).divide(new android.icu.math.BigDecimal("2")).toString()).equals("1.2"));
TestFmwk.assertTrue("div359", ((new android.icu.math.BigDecimal("2.400")).divide(new android.icu.math.BigDecimal("2")).toString()).equals("1.200"));
TestFmwk.assertTrue("div360", ((new android.icu.math.BigDecimal("2.")).divide(new android.icu.math.BigDecimal("2")).toString()).equals("1"));
TestFmwk.assertTrue("div361", ((new android.icu.math.BigDecimal("20")).divide(new android.icu.math.BigDecimal("20")).toString()).equals("1"));
TestFmwk.assertTrue("div362", ((new android.icu.math.BigDecimal("187")).divide(new android.icu.math.BigDecimal("187")).toString()).equals("1"));
TestFmwk.assertTrue("div363", ((new android.icu.math.BigDecimal("5")).divide(new android.icu.math.BigDecimal("2")).toString()).equals("3"));
TestFmwk.assertTrue("div364", ((new android.icu.math.BigDecimal("5")).divide(new android.icu.math.BigDecimal("2.0")).toString()).equals("3"));
TestFmwk.assertTrue("div365", ((new android.icu.math.BigDecimal("5")).divide(new android.icu.math.BigDecimal("2.000")).toString()).equals("3"));
TestFmwk.assertTrue("div366", ((new android.icu.math.BigDecimal("5")).divide(new android.icu.math.BigDecimal("0.200")).toString()).equals("25"));
TestFmwk.assertTrue("div367", ((new android.icu.math.BigDecimal("5.0")).divide(new android.icu.math.BigDecimal("2")).toString()).equals("2.5"));
TestFmwk.assertTrue("div368", ((new android.icu.math.BigDecimal("5.0")).divide(new android.icu.math.BigDecimal("2.0")).toString()).equals("2.5"));
TestFmwk.assertTrue("div369", ((new android.icu.math.BigDecimal("5.0")).divide(new android.icu.math.BigDecimal("2.000")).toString()).equals("2.5"));
TestFmwk.assertTrue("div370", ((new android.icu.math.BigDecimal("5.0")).divide(new android.icu.math.BigDecimal("0.200")).toString()).equals("25.0"));
TestFmwk.assertTrue("div371", ((new android.icu.math.BigDecimal("999999999")).divide(new android.icu.math.BigDecimal("1")).toString()).equals("999999999"));
TestFmwk.assertTrue("div372", ((new android.icu.math.BigDecimal("999999999.4")).divide(new android.icu.math.BigDecimal("1")).toString()).equals("999999999.4"));
TestFmwk.assertTrue("div373", ((new android.icu.math.BigDecimal("999999999.5")).divide(new android.icu.math.BigDecimal("1")).toString()).equals("999999999.5"));
TestFmwk.assertTrue("div374", ((new android.icu.math.BigDecimal("999999999.9")).divide(new android.icu.math.BigDecimal("1")).toString()).equals("999999999.9"));
TestFmwk.assertTrue("div375", ((new android.icu.math.BigDecimal("999999999.999")).divide(new android.icu.math.BigDecimal("1")).toString()).equals("999999999.999"));
TestFmwk.assertTrue("div376", ((new android.icu.math.BigDecimal("0.0000E-5")).divide(new android.icu.math.BigDecimal("1")).toString()).equals("0"));
TestFmwk.assertTrue("div377", ((new android.icu.math.BigDecimal("0.000000000")).divide(new android.icu.math.BigDecimal("1")).toString()).equals("0.000000000"));
// - Fixed point; explicit scales & rounds [old BigDecimal divides]
rhu = android.icu.math.MathContext.ROUND_HALF_UP;
rd = android.icu.math.MathContext.ROUND_DOWN;
TestFmwk.assertTrue("div001", ((new android.icu.math.BigDecimal("0")).divide(new android.icu.math.BigDecimal("3")).toString()).equals("0"));
TestFmwk.assertTrue("div002", ((new android.icu.math.BigDecimal("0")).divide(new android.icu.math.BigDecimal("3"), rhu).toString()).equals("0"));
TestFmwk.assertTrue("div003", ((new android.icu.math.BigDecimal("0")).divide(new android.icu.math.BigDecimal("3"), 0, rhu).toString()).equals("0"));
TestFmwk.assertTrue("div004", ((new android.icu.math.BigDecimal("0")).divide(new android.icu.math.BigDecimal("3"), 1, rhu).toString()).equals("0.0"));
TestFmwk.assertTrue("div005", ((new android.icu.math.BigDecimal("0")).divide(new android.icu.math.BigDecimal("3"), 2, rhu).toString()).equals("0.00"));
TestFmwk.assertTrue("div006", ((new android.icu.math.BigDecimal("0")).divide(new android.icu.math.BigDecimal("3"), 3, rhu).toString()).equals("0.000"));
TestFmwk.assertTrue("div007", ((new android.icu.math.BigDecimal("0")).divide(new android.icu.math.BigDecimal("3"), 4, rhu).toString()).equals("0.0000"));
TestFmwk.assertTrue("div008", ((new android.icu.math.BigDecimal("1")).divide(new android.icu.math.BigDecimal("3")).toString()).equals("0"));
TestFmwk.assertTrue("div009", ((new android.icu.math.BigDecimal("1")).divide(new android.icu.math.BigDecimal("3"), rhu).toString()).equals("0"));
TestFmwk.assertTrue("div010", ((new android.icu.math.BigDecimal("1")).divide(new android.icu.math.BigDecimal("3"), 0, rhu).toString()).equals("0"));
TestFmwk.assertTrue("div011", ((new android.icu.math.BigDecimal("1")).divide(new android.icu.math.BigDecimal("3"), 1, rhu).toString()).equals("0.3"));
TestFmwk.assertTrue("div012", ((new android.icu.math.BigDecimal("1")).divide(new android.icu.math.BigDecimal("3"), 2, rhu).toString()).equals("0.33"));
TestFmwk.assertTrue("div013", ((new android.icu.math.BigDecimal("1")).divide(new android.icu.math.BigDecimal("3"), 3, rhu).toString()).equals("0.333"));
TestFmwk.assertTrue("div014", ((new android.icu.math.BigDecimal("1")).divide(new android.icu.math.BigDecimal("3"), 4, rhu).toString()).equals("0.3333"));
TestFmwk.assertTrue("div015", ((new android.icu.math.BigDecimal("2")).divide(new android.icu.math.BigDecimal("3")).toString()).equals("1"));
TestFmwk.assertTrue("div016", ((new android.icu.math.BigDecimal("2")).divide(new android.icu.math.BigDecimal("3"), rhu).toString()).equals("1"));
TestFmwk.assertTrue("div017", ((new android.icu.math.BigDecimal("2")).divide(new android.icu.math.BigDecimal("3"), 0, rhu).toString()).equals("1"));
TestFmwk.assertTrue("div018", ((new android.icu.math.BigDecimal("2")).divide(new android.icu.math.BigDecimal("3"), 1, rhu).toString()).equals("0.7"));
TestFmwk.assertTrue("div019", ((new android.icu.math.BigDecimal("2")).divide(new android.icu.math.BigDecimal("3"), 2, rhu).toString()).equals("0.67"));
TestFmwk.assertTrue("div020", ((new android.icu.math.BigDecimal("2")).divide(new android.icu.math.BigDecimal("3"), 3, rhu).toString()).equals("0.667"));
TestFmwk.assertTrue("div021", ((new android.icu.math.BigDecimal("2")).divide(new android.icu.math.BigDecimal("3"), 4, rhu).toString()).equals("0.6667"));
TestFmwk.assertTrue("div030", ((new android.icu.math.BigDecimal("1000")).divide(new android.icu.math.BigDecimal("2000"), 4, rhu).toString()).equals("0.5000"));
TestFmwk.assertTrue("div031", ((new android.icu.math.BigDecimal("1000")).divide(new android.icu.math.BigDecimal("2000"), 3, rhu).toString()).equals("0.500"));
TestFmwk.assertTrue("div032", ((new android.icu.math.BigDecimal("1000")).divide(new android.icu.math.BigDecimal("2000"), 2, rhu).toString()).equals("0.50"));
TestFmwk.assertTrue("div033", ((new android.icu.math.BigDecimal("1000")).divide(new android.icu.math.BigDecimal("2000"), 1, rhu).toString()).equals("0.5"));
TestFmwk.assertTrue("div034", ((new android.icu.math.BigDecimal("1000")).divide(new android.icu.math.BigDecimal("2000"), 0, rhu).toString()).equals("1"));
TestFmwk.assertTrue("div035", ((new android.icu.math.BigDecimal("100")).divide(new android.icu.math.BigDecimal("5000"), 4, rhu).toString()).equals("0.0200"));
TestFmwk.assertTrue("div036", ((new android.icu.math.BigDecimal("100")).divide(new android.icu.math.BigDecimal("5000"), 3, rhu).toString()).equals("0.020"));
TestFmwk.assertTrue("div037", ((new android.icu.math.BigDecimal("100")).divide(new android.icu.math.BigDecimal("5000"), 2, rhu).toString()).equals("0.02"));
TestFmwk.assertTrue("div038", ((new android.icu.math.BigDecimal("100")).divide(new android.icu.math.BigDecimal("5000"), 1, rhu).toString()).equals("0.0"));
TestFmwk.assertTrue("div039", ((new android.icu.math.BigDecimal("100")).divide(new android.icu.math.BigDecimal("5000"), 0, rhu).toString()).equals("0"));
TestFmwk.assertTrue("div040", ((new android.icu.math.BigDecimal("9.99999999")).divide(new android.icu.math.BigDecimal("9.77777777"), 4, rhu).toString()).equals("1.0227"));
TestFmwk.assertTrue("div041", ((new android.icu.math.BigDecimal("9.9999999")).divide(new android.icu.math.BigDecimal("9.7777777"), 4, rhu).toString()).equals("1.0227"));
TestFmwk.assertTrue("div042", ((new android.icu.math.BigDecimal("9.999999")).divide(new android.icu.math.BigDecimal("9.777777"), 4, rhu).toString()).equals("1.0227"));
TestFmwk.assertTrue("div043", ((new android.icu.math.BigDecimal("9.77777777")).divide(new android.icu.math.BigDecimal("9.99999999"), 4, rhu).toString()).equals("0.9778"));
TestFmwk.assertTrue("div044", ((new android.icu.math.BigDecimal("9.7777777")).divide(new android.icu.math.BigDecimal("9.9999999"), 4, rhu).toString()).equals("0.9778"));
TestFmwk.assertTrue("div045", ((new android.icu.math.BigDecimal("9.777777")).divide(new android.icu.math.BigDecimal("9.999999"), 4, rhu).toString()).equals("0.9778"));
TestFmwk.assertTrue("div046", ((new android.icu.math.BigDecimal("9.77777")).divide(new android.icu.math.BigDecimal("9.99999"), 4, rhu).toString()).equals("0.9778"));
TestFmwk.assertTrue("div047", ((new android.icu.math.BigDecimal("9.7777")).divide(new android.icu.math.BigDecimal("9.9999"), 4, rhu).toString()).equals("0.9778"));
TestFmwk.assertTrue("div048", ((new android.icu.math.BigDecimal("9.777")).divide(new android.icu.math.BigDecimal("9.999"), 4, rhu).toString()).equals("0.9778"));
TestFmwk.assertTrue("div049", ((new android.icu.math.BigDecimal("9.77")).divide(new android.icu.math.BigDecimal("9.99"), 4, rhu).toString()).equals("0.9780"));
TestFmwk.assertTrue("div050", ((new android.icu.math.BigDecimal("9.7")).divide(new android.icu.math.BigDecimal("9.9"), 4, rhu).toString()).equals("0.9798"));
TestFmwk.assertTrue("div051", ((new android.icu.math.BigDecimal("9.")).divide(new android.icu.math.BigDecimal("9."), 4, rhu).toString()).equals("1.0000"));
TestFmwk.assertTrue("div060", ((new android.icu.math.BigDecimal("9.99999999")).divide(new android.icu.math.BigDecimal("9.77777777"), rhu).toString()).equals("1.02272727"));
TestFmwk.assertTrue("div061", ((new android.icu.math.BigDecimal("9.9999999")).divide(new android.icu.math.BigDecimal("9.7777777"), rhu).toString()).equals("1.0227273"));
TestFmwk.assertTrue("div062", ((new android.icu.math.BigDecimal("9.999999")).divide(new android.icu.math.BigDecimal("9.777777"), rhu).toString()).equals("1.022727"));
TestFmwk.assertTrue("div063", ((new android.icu.math.BigDecimal("9.77777777")).divide(new android.icu.math.BigDecimal("9.99999999"), rhu).toString()).equals("0.97777778"));
TestFmwk.assertTrue("div064", ((new android.icu.math.BigDecimal("9.7777777")).divide(new android.icu.math.BigDecimal("9.9999999"), rhu).toString()).equals("0.9777778"));
TestFmwk.assertTrue("div065", ((new android.icu.math.BigDecimal("9.777777")).divide(new android.icu.math.BigDecimal("9.999999"), rhu).toString()).equals("0.977778"));
TestFmwk.assertTrue("div066", ((new android.icu.math.BigDecimal("9.77777")).divide(new android.icu.math.BigDecimal("9.99999"), rhu).toString()).equals("0.97778"));
TestFmwk.assertTrue("div067", ((new android.icu.math.BigDecimal("9.7777")).divide(new android.icu.math.BigDecimal("9.9999"), rhu).toString()).equals("0.9778"));
TestFmwk.assertTrue("div068", ((new android.icu.math.BigDecimal("9.777")).divide(new android.icu.math.BigDecimal("9.999"), rhu).toString()).equals("0.978"));
TestFmwk.assertTrue("div069", ((new android.icu.math.BigDecimal("9.77")).divide(new android.icu.math.BigDecimal("9.99"), rhu).toString()).equals("0.98"));
TestFmwk.assertTrue("div070", ((new android.icu.math.BigDecimal("9.7")).divide(new android.icu.math.BigDecimal("9.9"), rhu).toString()).equals("1.0"));
TestFmwk.assertTrue("div071", ((new android.icu.math.BigDecimal("9.")).divide(new android.icu.math.BigDecimal("9."), rhu).toString()).equals("1"));
// test this is actually being used
rd = android.icu.math.MathContext.ROUND_DOWN;
TestFmwk.assertTrue("div080", ((new android.icu.math.BigDecimal("2")).divide(new android.icu.math.BigDecimal("3"), 0, rd).toString()).equals("0"));
TestFmwk.assertTrue("div081", ((new android.icu.math.BigDecimal("2")).divide(new android.icu.math.BigDecimal("3"), 1, rd).toString()).equals("0.6"));
TestFmwk.assertTrue("div082", ((new android.icu.math.BigDecimal("2")).divide(new android.icu.math.BigDecimal("3"), 2, rd).toString()).equals("0.66"));
TestFmwk.assertTrue("div083", ((new android.icu.math.BigDecimal("2")).divide(new android.icu.math.BigDecimal("3"), 3, rd).toString()).equals("0.666"));
TestFmwk.assertTrue("div084", ((new android.icu.math.BigDecimal("2")).divide(new android.icu.math.BigDecimal("3"), 4, rd).toString()).equals("0.6666"));
// check for some 0 residues
ru = android.icu.math.MathContext.ROUND_UNNECESSARY;
TestFmwk.assertTrue("div090", ((new android.icu.math.BigDecimal("1000")).divide(new android.icu.math.BigDecimal("5"), 4, ru).toString()).equals("200.0000"));
TestFmwk.assertTrue("div091", ((new android.icu.math.BigDecimal("1000")).divide(new android.icu.math.BigDecimal("50"), 4, ru).toString()).equals("20.0000"));
TestFmwk.assertTrue("div092", ((new android.icu.math.BigDecimal("1000")).divide(new android.icu.math.BigDecimal("500"), 4, ru).toString()).equals("2.0000"));
TestFmwk.assertTrue("div093", ((new android.icu.math.BigDecimal("1000")).divide(new android.icu.math.BigDecimal("5000"), 4, ru).toString()).equals("0.2000"));
TestFmwk.assertTrue("div094", ((new android.icu.math.BigDecimal("1000")).divide(new android.icu.math.BigDecimal("5000"), 3, ru).toString()).equals("0.200"));
TestFmwk.assertTrue("div095", ((new android.icu.math.BigDecimal("1000")).divide(new android.icu.math.BigDecimal("5000"), 2, ru).toString()).equals("0.20"));
TestFmwk.assertTrue("div096", ((new android.icu.math.BigDecimal("1000")).divide(new android.icu.math.BigDecimal("5000"), 1, ru).toString()).equals("0.2"));
// check rounding explicitly
TestFmwk.assertTrue("div101", ((new android.icu.math.BigDecimal("0.055")).divide(one, 2, android.icu.math.MathContext.ROUND_CEILING).toString()).equals("0.06"));
TestFmwk.assertTrue("div102", ((new android.icu.math.BigDecimal("0.055")).divide(one, 1, android.icu.math.MathContext.ROUND_CEILING).toString()).equals("0.1"));
TestFmwk.assertTrue("div103", ((new android.icu.math.BigDecimal("0.055")).divide(one, 0, android.icu.math.MathContext.ROUND_CEILING).toString()).equals("1"));
TestFmwk.assertTrue("div104", ((new android.icu.math.BigDecimal("0.055")).divide(one, 2, android.icu.math.MathContext.ROUND_DOWN).toString()).equals("0.05"));
TestFmwk.assertTrue("div105", ((new android.icu.math.BigDecimal("0.055")).divide(one, 1, android.icu.math.MathContext.ROUND_DOWN).toString()).equals("0.0"));
TestFmwk.assertTrue("div106", ((new android.icu.math.BigDecimal("0.055")).divide(one, 0, android.icu.math.MathContext.ROUND_DOWN).toString()).equals("0"));
TestFmwk.assertTrue("div107", ((new android.icu.math.BigDecimal("0.055")).divide(one, 2, android.icu.math.MathContext.ROUND_FLOOR).toString()).equals("0.05"));
TestFmwk.assertTrue("div108", ((new android.icu.math.BigDecimal("0.055")).divide(one, 1, android.icu.math.MathContext.ROUND_FLOOR).toString()).equals("0.0"));
TestFmwk.assertTrue("div109", ((new android.icu.math.BigDecimal("0.055")).divide(one, 0, android.icu.math.MathContext.ROUND_FLOOR).toString()).equals("0"));
TestFmwk.assertTrue("div110", ((new android.icu.math.BigDecimal("0.045")).divide(one, 2, android.icu.math.MathContext.ROUND_HALF_DOWN).toString()).equals("0.04"));
TestFmwk.assertTrue("div111", ((new android.icu.math.BigDecimal("0.045")).divide(one, 1, android.icu.math.MathContext.ROUND_HALF_DOWN).toString()).equals("0.0"));
TestFmwk.assertTrue("div112", ((new android.icu.math.BigDecimal("0.045")).divide(one, 0, android.icu.math.MathContext.ROUND_HALF_DOWN).toString()).equals("0"));
TestFmwk.assertTrue("div113", ((new android.icu.math.BigDecimal("0.050")).divide(one, 2, android.icu.math.MathContext.ROUND_HALF_DOWN).toString()).equals("0.05"));
TestFmwk.assertTrue("div114", ((new android.icu.math.BigDecimal("0.050")).divide(one, 1, android.icu.math.MathContext.ROUND_HALF_DOWN).toString()).equals("0.0"));
TestFmwk.assertTrue("div115", ((new android.icu.math.BigDecimal("0.050")).divide(one, 0, android.icu.math.MathContext.ROUND_HALF_DOWN).toString()).equals("0"));
TestFmwk.assertTrue("div116", ((new android.icu.math.BigDecimal("0.055")).divide(one, 2, android.icu.math.MathContext.ROUND_HALF_DOWN).toString()).equals("0.05"));
TestFmwk.assertTrue("div117", ((new android.icu.math.BigDecimal("0.055")).divide(one, 1, android.icu.math.MathContext.ROUND_HALF_DOWN).toString()).equals("0.1"));
TestFmwk.assertTrue("div118", ((new android.icu.math.BigDecimal("0.055")).divide(one, 0, android.icu.math.MathContext.ROUND_HALF_DOWN).toString()).equals("0"));
TestFmwk.assertTrue("div120", ((new android.icu.math.BigDecimal("0.045")).divide(one, 2, android.icu.math.MathContext.ROUND_HALF_EVEN).toString()).equals("0.04"));
TestFmwk.assertTrue("div121", ((new android.icu.math.BigDecimal("0.045")).divide(one, 1, android.icu.math.MathContext.ROUND_HALF_EVEN).toString()).equals("0.0"));
TestFmwk.assertTrue("div122", ((new android.icu.math.BigDecimal("0.045")).divide(one, 0, android.icu.math.MathContext.ROUND_HALF_EVEN).toString()).equals("0"));
TestFmwk.assertTrue("div123", ((new android.icu.math.BigDecimal("0.050")).divide(one, 2, android.icu.math.MathContext.ROUND_HALF_EVEN).toString()).equals("0.05"));
TestFmwk.assertTrue("div124", ((new android.icu.math.BigDecimal("0.050")).divide(one, 1, android.icu.math.MathContext.ROUND_HALF_EVEN).toString()).equals("0.0"));
TestFmwk.assertTrue("div125", ((new android.icu.math.BigDecimal("0.050")).divide(one, 0, android.icu.math.MathContext.ROUND_HALF_EVEN).toString()).equals("0"));
TestFmwk.assertTrue("div126", ((new android.icu.math.BigDecimal("0.150")).divide(one, 2, android.icu.math.MathContext.ROUND_HALF_EVEN).toString()).equals("0.15"));
TestFmwk.assertTrue("div127", ((new android.icu.math.BigDecimal("0.150")).divide(one, 1, android.icu.math.MathContext.ROUND_HALF_EVEN).toString()).equals("0.2"));
TestFmwk.assertTrue("div128", ((new android.icu.math.BigDecimal("0.150")).divide(one, 0, android.icu.math.MathContext.ROUND_HALF_EVEN).toString()).equals("0"));
TestFmwk.assertTrue("div129", ((new android.icu.math.BigDecimal("0.055")).divide(one, 2, android.icu.math.MathContext.ROUND_HALF_EVEN).toString()).equals("0.06"));
TestFmwk.assertTrue("div130", ((new android.icu.math.BigDecimal("0.055")).divide(one, 1, android.icu.math.MathContext.ROUND_HALF_EVEN).toString()).equals("0.1"));
TestFmwk.assertTrue("div131", ((new android.icu.math.BigDecimal("0.055")).divide(one, 0, android.icu.math.MathContext.ROUND_HALF_EVEN).toString()).equals("0"));
TestFmwk.assertTrue("div140", ((new android.icu.math.BigDecimal("0.045")).divide(one, 2, android.icu.math.MathContext.ROUND_HALF_UP).toString()).equals("0.05"));
TestFmwk.assertTrue("div141", ((new android.icu.math.BigDecimal("0.045")).divide(one, 1, android.icu.math.MathContext.ROUND_HALF_UP).toString()).equals("0.0"));
TestFmwk.assertTrue("div142", ((new android.icu.math.BigDecimal("0.045")).divide(one, 0, android.icu.math.MathContext.ROUND_HALF_UP).toString()).equals("0"));
TestFmwk.assertTrue("div143", ((new android.icu.math.BigDecimal("0.050")).divide(one, 2, android.icu.math.MathContext.ROUND_HALF_UP).toString()).equals("0.05"));
TestFmwk.assertTrue("div144", ((new android.icu.math.BigDecimal("0.050")).divide(one, 1, android.icu.math.MathContext.ROUND_HALF_UP).toString()).equals("0.1"));
TestFmwk.assertTrue("div145", ((new android.icu.math.BigDecimal("0.050")).divide(one, 0, android.icu.math.MathContext.ROUND_HALF_UP).toString()).equals("0"));
TestFmwk.assertTrue("div146", ((new android.icu.math.BigDecimal("0.055")).divide(one, 2, android.icu.math.MathContext.ROUND_HALF_UP).toString()).equals("0.06"));
TestFmwk.assertTrue("div147", ((new android.icu.math.BigDecimal("0.055")).divide(one, 1, android.icu.math.MathContext.ROUND_HALF_UP).toString()).equals("0.1"));
TestFmwk.assertTrue("div148", ((new android.icu.math.BigDecimal("0.055")).divide(one, 0, android.icu.math.MathContext.ROUND_HALF_UP).toString()).equals("0"));
TestFmwk.assertTrue("div150", ((new android.icu.math.BigDecimal("0.055")).divide(one, 2, android.icu.math.MathContext.ROUND_UP).toString()).equals("0.06"));
TestFmwk.assertTrue("div151", ((new android.icu.math.BigDecimal("0.055")).divide(one, 1, android.icu.math.MathContext.ROUND_UP).toString()).equals("0.1"));
TestFmwk.assertTrue("div52.", ((new android.icu.math.BigDecimal("0.055")).divide(one, 0, android.icu.math.MathContext.ROUND_UP).toString()).equals("1"));
// - error conditions ---
try {
ten.divide((android.icu.math.BigDecimal) null);
flag = false;
} catch (java.lang.NullPointerException $32) {
flag = true;
}
/* checknull */
TestFmwk.assertTrue("div201", flag);
try {
ten.divide(ten, (android.icu.math.MathContext) null);
flag = false;
} catch (java.lang.NullPointerException $33) {
flag = true;
}
/* checknull2 */
TestFmwk.assertTrue("div202", flag);
try {
(new android.icu.math.BigDecimal("1")).divide(new android.icu.math.BigDecimal("3"), -8, 0);
flag = false;
} catch (java.lang.RuntimeException $34) {
e = $34;
flag = flag & (e.getMessage()).equals("Negative scale: -8");
}
/* checkscale */
TestFmwk.assertTrue("div203", flag);
try {
(new android.icu.math.BigDecimal("1000")).divide(new android.icu.math.BigDecimal("5000"), 0, android.icu.math.MathContext.ROUND_UNNECESSARY);
flag = false;
} catch (java.lang.ArithmeticException $35) {
ae = $35;
flag = (ae.getMessage()).equals("Rounding necessary");
}
/* rounn */
TestFmwk.assertTrue("div204", flag);
try {
(new android.icu.math.BigDecimal("1001")).divide(new android.icu.math.BigDecimal("10"), 0, android.icu.math.MathContext.ROUND_UNNECESSARY);
flag = false;
} catch (java.lang.ArithmeticException $36) {
ae = $36;
flag = (ae.getMessage()).equals("Rounding necessary");
}
/* rounn */
TestFmwk.assertTrue("div205", flag);
try {
(new android.icu.math.BigDecimal("1001")).divide(new android.icu.math.BigDecimal("100"), 1, android.icu.math.MathContext.ROUND_UNNECESSARY);
flag = false;
} catch (java.lang.ArithmeticException $37) {
ae = $37;
flag = (ae.getMessage()).equals("Rounding necessary");
}
/* rounn */
TestFmwk.assertTrue("div206", flag);
try {
(new android.icu.math.BigDecimal("10001")).divide(new android.icu.math.BigDecimal("10000"), 1, android.icu.math.MathContext.ROUND_UNNECESSARY);
flag = false;
} catch (java.lang.ArithmeticException $38) {
ae = $38;
flag = (ae.getMessage()).equals("Rounding necessary");
}
/* rounn */
TestFmwk.assertTrue("div207", flag);
try {
(new android.icu.math.BigDecimal("1.0001")).divide(new android.icu.math.BigDecimal("1"), 1, android.icu.math.MathContext.ROUND_UNNECESSARY);
flag = false;
} catch (java.lang.ArithmeticException $39) {
ae = $39;
flag = (ae.getMessage()).equals("Rounding necessary");
}
/* rounn */
TestFmwk.assertTrue("div208", flag);
try {
(new android.icu.math.BigDecimal("5")).divide(new android.icu.math.BigDecimal("0.00"));
flag = false;
} catch (java.lang.ArithmeticException $40) {
ae = $40;
flag = (ae.getMessage()).equals("Divide by 0");
}
/* div0 */
TestFmwk.assertTrue("div209", flag);
try {
tenlong.divide(android.icu.math.BigDecimal.ONE, mcld);
flag = false;
} catch (java.lang.ArithmeticException $41) {
ae = $41;
flag = (ae.getMessage()).equals("Too many digits:" + " " + tenlong.toString());
}
/* checkdigits */
TestFmwk.assertTrue("div210", flag);
try {
android.icu.math.BigDecimal.ONE.divide(tenlong, mcld);
flag = false;
} catch (java.lang.ArithmeticException $42) {
ae = $42;
flag = (ae.getMessage()).equals("Too many digits:" + " " + tenlong.toString());
}
/* checkdigits */
TestFmwk.assertTrue("div211", flag);
}
use of android.icu.math.BigDecimal in project j2objc by google.
the class DiagBigDecimalTest method diagconstructors.
/*--------------------------------------------------------------------*/
/* Diagnostic group methods */
/*--------------------------------------------------------------------*/
/**
* Test constructors (and {@link #toString()} for equalities).
*/
@Test
public void diagconstructors() {
boolean flag = false;
java.lang.String num;
java.math.BigInteger bip;
java.math.BigInteger biz;
java.math.BigInteger bin;
android.icu.math.BigDecimal bda;
android.icu.math.BigDecimal bdb;
android.icu.math.BigDecimal bmc;
android.icu.math.BigDecimal bmd;
android.icu.math.BigDecimal bme;
java.lang.RuntimeException e = null;
char[] ca;
double dzer;
double dpos;
double dneg;
double dpos5;
double dneg5;
double dmin;
double dmax;
double d;
java.lang.String[] badstrings;
int i = 0;
// constants [statically-called constructors]
TestFmwk.assertTrue("con001", (android.icu.math.BigDecimal.ZERO.toString()).equals("0"));
TestFmwk.assertTrue("con002", (android.icu.math.BigDecimal.ONE.toString()).equals("1"));
TestFmwk.assertTrue("con003", (android.icu.math.BigDecimal.TEN.toString()).equals("10"));
TestFmwk.assertTrue("con004", (android.icu.math.BigDecimal.ZERO.intValueExact()) == 0);
TestFmwk.assertTrue("con005", (android.icu.math.BigDecimal.ONE.intValueExact()) == 1);
TestFmwk.assertTrue("con006", (android.icu.math.BigDecimal.TEN.intValueExact()) == 10);
// [java.math.] BigDecimal
TestFmwk.assertTrue("cbd001", ((new android.icu.math.BigDecimal(new java.math.BigDecimal("0"))).toString()).equals("0"));
TestFmwk.assertTrue("cbd002", ((new android.icu.math.BigDecimal(new java.math.BigDecimal("1"))).toString()).equals("1"));
TestFmwk.assertTrue("cbd003", ((new android.icu.math.BigDecimal(new java.math.BigDecimal("10"))).toString()).equals("10"));
TestFmwk.assertTrue("cbd004", ((new android.icu.math.BigDecimal(new java.math.BigDecimal("1000"))).toString()).equals("1000"));
TestFmwk.assertTrue("cbd005", ((new android.icu.math.BigDecimal(new java.math.BigDecimal("10.0"))).toString()).equals("10.0"));
TestFmwk.assertTrue("cbd006", ((new android.icu.math.BigDecimal(new java.math.BigDecimal("10.1"))).toString()).equals("10.1"));
TestFmwk.assertTrue("cbd007", ((new android.icu.math.BigDecimal(new java.math.BigDecimal("-1.1"))).toString()).equals("-1.1"));
TestFmwk.assertTrue("cbd008", ((new android.icu.math.BigDecimal(new java.math.BigDecimal("-9.0"))).toString()).equals("-9.0"));
TestFmwk.assertTrue("cbd009", ((new android.icu.math.BigDecimal(new java.math.BigDecimal("0.9"))).toString()).equals("0.9"));
num = "123456789.123456789";
TestFmwk.assertTrue("cbd010", ((new android.icu.math.BigDecimal(new java.math.BigDecimal(num))).toString()).equals(num));
num = "123456789.000000000";
TestFmwk.assertTrue("cbd011", ((new android.icu.math.BigDecimal(new java.math.BigDecimal(num))).toString()).equals(num));
num = "123456789000000000";
TestFmwk.assertTrue("cbd012", ((new android.icu.math.BigDecimal(new java.math.BigDecimal(num))).toString()).equals(num));
num = "0.00000123456789";
TestFmwk.assertTrue("cbd013", ((new android.icu.math.BigDecimal(new java.math.BigDecimal(num))).toString()).equals(num));
num = "0.000000123456789";
// ignore format change issues with 1.5
if (!isJDK15OrLater)
TestFmwk.assertTrue("cbd014", ((new android.icu.math.BigDecimal(new java.math.BigDecimal(num))).toString()).equals(num));
try {
new android.icu.math.BigDecimal((java.math.BigDecimal) null);
flag = false;
} catch (java.lang.NullPointerException $3) {
flag = true;
}
/* checknull */
TestFmwk.assertTrue("cbi015", flag);
// BigInteger
// biggie +ve
bip = new BigInteger("987654321987654321987654321");
// biggie 0
biz = new BigInteger("0");
// biggie -ve
bin = new BigInteger("-12345678998765432112345678");
TestFmwk.assertTrue("cbi001", ((new android.icu.math.BigDecimal(bip)).toString()).equals(bip.toString()));
TestFmwk.assertTrue("cbi002", ((new android.icu.math.BigDecimal(biz)).toString()).equals("0"));
TestFmwk.assertTrue("cbi003", ((new android.icu.math.BigDecimal(bin)).toString()).equals(bin.toString()));
try {
new android.icu.math.BigDecimal((java.math.BigInteger) null);
flag = false;
} catch (java.lang.NullPointerException $4) {
flag = true;
}
/* checknull */
TestFmwk.assertTrue("cbi004", flag);
// BigInteger with scale
// bigish
bip = new BigInteger("123456789");
bda = new android.icu.math.BigDecimal(bip);
bdb = new android.icu.math.BigDecimal(bip, 5);
bmc = new android.icu.math.BigDecimal(bip, 15);
TestFmwk.assertTrue("cbs001", (bda.toString()).equals("123456789"));
TestFmwk.assertTrue("cbs002", (bdb.toString()).equals("1234.56789"));
TestFmwk.assertTrue("cbs003", (bmc.toString()).equals("0.000000123456789"));
// biggie
bip = new BigInteger("123456789123456789123456789");
bda = new android.icu.math.BigDecimal(bip);
bdb = new android.icu.math.BigDecimal(bip, 7);
bmc = new android.icu.math.BigDecimal(bip, 13);
bmd = new android.icu.math.BigDecimal(bip, 19);
bme = new android.icu.math.BigDecimal(bip, 29);
TestFmwk.assertTrue("cbs011", (bda.toString()).equals("123456789123456789123456789"));
TestFmwk.assertTrue("cbs012", (bdb.toString()).equals("12345678912345678912.3456789"));
TestFmwk.assertTrue("cbs013", (bmc.toString()).equals("12345678912345.6789123456789"));
TestFmwk.assertTrue("cbs014", (bmd.toString()).equals("12345678.9123456789123456789"));
TestFmwk.assertTrue("cbs015", (bme.toString()).equals("0.00123456789123456789123456789"));
try {
new android.icu.math.BigDecimal((java.math.BigInteger) null, 1);
flag = false;
} catch (java.lang.NullPointerException $5) {
flag = true;
}
/* checknull */
TestFmwk.assertTrue("cbs004", flag);
try {
new android.icu.math.BigDecimal(bip, -8);
flag = false;
} catch (java.lang.RuntimeException $6) {
e = $6;
flag = (e.getMessage()).equals("Negative scale: -8");
}
/* checkscale */
TestFmwk.assertTrue("cbs005", flag);
// char[]
// We just test it's there
// Functionality is tested by BigDecimal(String).
ca = ("123.45").toCharArray();
TestFmwk.assertTrue("cca001", ((new android.icu.math.BigDecimal(ca)).toString()).equals("123.45"));
try {
new android.icu.math.BigDecimal((char[]) null);
flag = false;
} catch (java.lang.NullPointerException $7) {
flag = true;
}
/* checknull */
TestFmwk.assertTrue("cca010", flag);
// char[],int,int
// We just test it's there, and that offsets work.
// Functionality is tested by BigDecimal(String).
ca = ("123.45").toCharArray();
TestFmwk.assertTrue("cca101", ((new android.icu.math.BigDecimal(ca, 0, 6)).toString()).equals("123.45"));
TestFmwk.assertTrue("cca102", ((new android.icu.math.BigDecimal(ca, 1, 5)).toString()).equals("23.45"));
TestFmwk.assertTrue("cca103", ((new android.icu.math.BigDecimal(ca, 2, 4)).toString()).equals("3.45"));
TestFmwk.assertTrue("cca104", ((new android.icu.math.BigDecimal(ca, 3, 3)).toString()).equals("0.45"));
TestFmwk.assertTrue("cca105", ((new android.icu.math.BigDecimal(ca, 4, 2)).toString()).equals("45"));
TestFmwk.assertTrue("cca106", ((new android.icu.math.BigDecimal(ca, 5, 1)).toString()).equals("5"));
TestFmwk.assertTrue("cca110", ((new android.icu.math.BigDecimal(ca, 0, 1)).toString()).equals("1"));
TestFmwk.assertTrue("cca111", ((new android.icu.math.BigDecimal(ca, 1, 1)).toString()).equals("2"));
TestFmwk.assertTrue("cca112", ((new android.icu.math.BigDecimal(ca, 2, 1)).toString()).equals("3"));
TestFmwk.assertTrue("cca113", ((new android.icu.math.BigDecimal(ca, 4, 1)).toString()).equals("4"));
TestFmwk.assertTrue("cca120", ((new android.icu.math.BigDecimal(ca, 0, 2)).toString()).equals("12"));
TestFmwk.assertTrue("cca121", ((new android.icu.math.BigDecimal(ca, 1, 2)).toString()).equals("23"));
TestFmwk.assertTrue("cca122", ((new android.icu.math.BigDecimal(ca, 2, 2)).toString()).equals("3"));
TestFmwk.assertTrue("cca123", ((new android.icu.math.BigDecimal(ca, 3, 2)).toString()).equals("0.4"));
TestFmwk.assertTrue("cca130", ((new android.icu.math.BigDecimal(ca, 0, 3)).toString()).equals("123"));
TestFmwk.assertTrue("cca131", ((new android.icu.math.BigDecimal(ca, 1, 3)).toString()).equals("23"));
TestFmwk.assertTrue("cca132", ((new android.icu.math.BigDecimal(ca, 2, 3)).toString()).equals("3.4"));
TestFmwk.assertTrue("cca140", ((new android.icu.math.BigDecimal(ca, 0, 4)).toString()).equals("123"));
TestFmwk.assertTrue("cca141", ((new android.icu.math.BigDecimal(ca, 1, 4)).toString()).equals("23.4"));
TestFmwk.assertTrue("cca150", ((new android.icu.math.BigDecimal(ca, 0, 5)).toString()).equals("123.4"));
// a couple of oddies
ca = ("x23.4x").toCharArray();
TestFmwk.assertTrue("cca160", ((new android.icu.math.BigDecimal(ca, 1, 4)).toString()).equals("23.4"));
TestFmwk.assertTrue("cca161", ((new android.icu.math.BigDecimal(ca, 1, 1)).toString()).equals("2"));
TestFmwk.assertTrue("cca162", ((new android.icu.math.BigDecimal(ca, 4, 1)).toString()).equals("4"));
ca = ("0123456789.9876543210").toCharArray();
TestFmwk.assertTrue("cca163", ((new android.icu.math.BigDecimal(ca, 0, 21)).toString()).equals("123456789.9876543210"));
TestFmwk.assertTrue("cca164", ((new android.icu.math.BigDecimal(ca, 1, 20)).toString()).equals("123456789.9876543210"));
TestFmwk.assertTrue("cca165", ((new android.icu.math.BigDecimal(ca, 2, 19)).toString()).equals("23456789.9876543210"));
TestFmwk.assertTrue("cca166", ((new android.icu.math.BigDecimal(ca, 2, 18)).toString()).equals("23456789.987654321"));
TestFmwk.assertTrue("cca167", ((new android.icu.math.BigDecimal(ca, 2, 17)).toString()).equals("23456789.98765432"));
TestFmwk.assertTrue("cca168", ((new android.icu.math.BigDecimal(ca, 2, 16)).toString()).equals("23456789.9876543"));
try {
new android.icu.math.BigDecimal((char[]) null, 0, 1);
flag = false;
} catch (java.lang.NullPointerException $8) {
flag = true;
}
/* checknull */
TestFmwk.assertTrue("cca200", flag);
try {
new android.icu.math.BigDecimal("123".toCharArray(), 0, 0);
flag = false;
} catch (java.lang.NumberFormatException $9) {
flag = true;
}
/* checklen */
TestFmwk.assertTrue("cca201", flag);
try {
new android.icu.math.BigDecimal("123".toCharArray(), 2, 4);
flag = false;
} catch (java.lang.RuntimeException $10) {
// anything OK
flag = true;
}
/* checkbound */
TestFmwk.assertTrue("cca202", flag);
try {
new android.icu.math.BigDecimal("123".toCharArray(), -1, 2);
flag = false;
} catch (java.lang.RuntimeException $11) {
// anything OK
flag = true;
}
/* checkbound2 */
TestFmwk.assertTrue("cca203", flag);
try {
new android.icu.math.BigDecimal("123".toCharArray(), 1, -2);
flag = false;
} catch (java.lang.RuntimeException $12) {
// anything OK
flag = true;
}
/* checkbound3 */
TestFmwk.assertTrue("cca204", flag);
// double [deprecated]
// Note that many of these differ from the valueOf(double) results.
dzer = 0;
dpos = 1;
dpos = dpos / (10);
dneg = -dpos;
TestFmwk.assertTrue("cdo001", ((new android.icu.math.BigDecimal(dneg)).toString()).equals("-0.1000000000000000055511151231257827021181583404541015625"));
// NB, not '0.0'
TestFmwk.assertTrue("cdo002", ((new android.icu.math.BigDecimal(dzer)).toString()).equals("0"));
TestFmwk.assertTrue("cdo003", ((new android.icu.math.BigDecimal(dpos)).toString()).equals("0.1000000000000000055511151231257827021181583404541015625"));
dpos5 = 0.5D;
dneg5 = -dpos5;
TestFmwk.assertTrue("cdo004", ((new android.icu.math.BigDecimal(dneg5)).toString()).equals("-0.5"));
TestFmwk.assertTrue("cdo005", ((new android.icu.math.BigDecimal(dpos5)).toString()).equals("0.5"));
dmin = java.lang.Double.MIN_VALUE;
dmax = java.lang.Double.MAX_VALUE;
if (// for some reason we format using scientific
!isJDK15OrLater)
// notation on 1.5 after 30 decimals or so
TestFmwk.assertTrue("cdo006", ((new android.icu.math.BigDecimal(dmin)).toString()).equals("0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004940656458412465441765687928682213723650598026143247644255856825006755072702087518652998363616359923797965646954457177309266567103559397963987747960107818781263007131903114045278458171678489821036887186360569987307230500063874091535649843873124733972731696151400317153853980741262385655911710266585566867681870395603106249319452715914924553293054565444011274801297099995419319894090804165633245247571478690147267801593552386115501348035264934720193790268107107491703332226844753335720832431936092382893458368060106011506169809753078342277318329247904982524730776375927247874656084778203734469699533647017972677717585125660551199131504891101451037862738167250955837389733598993664809941164205702637090279242767544565229087538682506419718265533447265625"));
TestFmwk.assertTrue("cdo007", ((new android.icu.math.BigDecimal(dmax)).toString()).equals("179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368"));
// nasties
d = 9;
d = d / (10);
TestFmwk.assertTrue("cdo010", ((new android.icu.math.BigDecimal(d)).toString()).equals("0.90000000000000002220446049250313080847263336181640625"));
d = d / (10);
TestFmwk.assertTrue("cdo011", ((new android.icu.math.BigDecimal(d)).toString()).equals("0.0899999999999999966693309261245303787291049957275390625"));
d = d / (10);
TestFmwk.assertTrue("cdo012", ((new android.icu.math.BigDecimal(d)).toString()).equals("0.00899999999999999931998839741709161899052560329437255859375"));
d = d / (10);
TestFmwk.assertTrue("cdo013", ((new android.icu.math.BigDecimal(d)).toString()).equals("0.00089999999999999997536692664112933925935067236423492431640625"));
d = d / (10);
TestFmwk.assertTrue("cdo014", ((new android.icu.math.BigDecimal(d)).toString()).equals("0.00008999999999999999211568180168541175589780323207378387451171875"));
d = d / (10);
TestFmwk.assertTrue("cdo015", ((new android.icu.math.BigDecimal(d)).toString()).equals("0.00000899999999999999853394182236510090433512232266366481781005859375"));
d = d / (10);
if (!isJDK15OrLater)
TestFmwk.assertTrue("cdo016", ((new android.icu.math.BigDecimal(d)).toString()).equals("0.000000899999999999999853394182236510090433512232266366481781005859375"));
d = d / (10);
if (!isJDK15OrLater)
TestFmwk.assertTrue("cdo017", ((new android.icu.math.BigDecimal(d)).toString()).equals("0.0000000899999999999999853394182236510090433512232266366481781005859375"));
d = d / (10);
if (!isJDK15OrLater)
TestFmwk.assertTrue("cdo018", ((new android.icu.math.BigDecimal(d)).toString()).equals("0.000000008999999999999997872197332322678764437995369007694534957408905029296875"));
try {
new android.icu.math.BigDecimal(java.lang.Double.POSITIVE_INFINITY);
flag = false;
} catch (java.lang.NumberFormatException $13) {
flag = true;
}
/* checkpin */
TestFmwk.assertTrue("cdo101", flag);
try {
new android.icu.math.BigDecimal(java.lang.Double.NEGATIVE_INFINITY);
flag = false;
} catch (java.lang.NumberFormatException $14) {
flag = true;
}
/* checknin */
TestFmwk.assertTrue("cdo102", flag);
try {
new android.icu.math.BigDecimal(java.lang.Double.NaN);
flag = false;
} catch (java.lang.NumberFormatException $15) {
flag = true;
}
/* checknan */
TestFmwk.assertTrue("cdo103", flag);
// int
TestFmwk.assertTrue("cin001", ((new android.icu.math.BigDecimal(imin)).toString()).equals("-2147483648"));
TestFmwk.assertTrue("cin002", ((new android.icu.math.BigDecimal(imax)).toString()).equals("2147483647"));
TestFmwk.assertTrue("cin003", ((new android.icu.math.BigDecimal(ineg)).toString()).equals("-1"));
TestFmwk.assertTrue("cin004", ((new android.icu.math.BigDecimal(izer)).toString()).equals("0"));
TestFmwk.assertTrue("cin005", ((new android.icu.math.BigDecimal(ipos)).toString()).equals("1"));
TestFmwk.assertTrue("cin006", ((new android.icu.math.BigDecimal(10)).toString()).equals("10"));
TestFmwk.assertTrue("cin007", ((new android.icu.math.BigDecimal(9)).toString()).equals("9"));
TestFmwk.assertTrue("cin008", ((new android.icu.math.BigDecimal(5)).toString()).equals("5"));
TestFmwk.assertTrue("cin009", ((new android.icu.math.BigDecimal(2)).toString()).equals("2"));
TestFmwk.assertTrue("cin010", ((new android.icu.math.BigDecimal(-2)).toString()).equals("-2"));
TestFmwk.assertTrue("cin011", ((new android.icu.math.BigDecimal(-5)).toString()).equals("-5"));
TestFmwk.assertTrue("cin012", ((new android.icu.math.BigDecimal(-9)).toString()).equals("-9"));
TestFmwk.assertTrue("cin013", ((new android.icu.math.BigDecimal(-10)).toString()).equals("-10"));
TestFmwk.assertTrue("cin014", ((new android.icu.math.BigDecimal(-11)).toString()).equals("-11"));
TestFmwk.assertTrue("cin015", ((new android.icu.math.BigDecimal(-99)).toString()).equals("-99"));
TestFmwk.assertTrue("cin016", ((new android.icu.math.BigDecimal(-100)).toString()).equals("-100"));
TestFmwk.assertTrue("cin017", ((new android.icu.math.BigDecimal(-999)).toString()).equals("-999"));
TestFmwk.assertTrue("cin018", ((new android.icu.math.BigDecimal(-1000)).toString()).equals("-1000"));
TestFmwk.assertTrue("cin019", ((new android.icu.math.BigDecimal(11)).toString()).equals("11"));
TestFmwk.assertTrue("cin020", ((new android.icu.math.BigDecimal(99)).toString()).equals("99"));
TestFmwk.assertTrue("cin021", ((new android.icu.math.BigDecimal(100)).toString()).equals("100"));
TestFmwk.assertTrue("cin022", ((new android.icu.math.BigDecimal(999)).toString()).equals("999"));
TestFmwk.assertTrue("cin023", ((new android.icu.math.BigDecimal(1000)).toString()).equals("1000"));
// long
TestFmwk.assertTrue("clo001", ((new android.icu.math.BigDecimal(lmin)).toString()).equals("-9223372036854775808"));
TestFmwk.assertTrue("clo002", ((new android.icu.math.BigDecimal(lmax)).toString()).equals("9223372036854775807"));
TestFmwk.assertTrue("clo003", ((new android.icu.math.BigDecimal(lneg)).toString()).equals("-1"));
TestFmwk.assertTrue("clo004", ((new android.icu.math.BigDecimal(lzer)).toString()).equals("0"));
TestFmwk.assertTrue("clo005", ((new android.icu.math.BigDecimal(lpos)).toString()).equals("1"));
// String [many more examples are elsewhere]
// strings without E cannot generate E in result
TestFmwk.assertTrue("cst001", ((new android.icu.math.BigDecimal("12")).toString()).equals("12"));
TestFmwk.assertTrue("cst002", ((new android.icu.math.BigDecimal("-76")).toString()).equals("-76"));
TestFmwk.assertTrue("cst003", ((new android.icu.math.BigDecimal("12.76")).toString()).equals("12.76"));
TestFmwk.assertTrue("cst004", ((new android.icu.math.BigDecimal("+12.76")).toString()).equals("12.76"));
TestFmwk.assertTrue("cst005", ((new android.icu.math.BigDecimal("012.76")).toString()).equals("12.76"));
TestFmwk.assertTrue("cst006", ((new android.icu.math.BigDecimal("+0.003")).toString()).equals("0.003"));
TestFmwk.assertTrue("cst007", ((new android.icu.math.BigDecimal("17.")).toString()).equals("17"));
TestFmwk.assertTrue("cst008", ((new android.icu.math.BigDecimal(".5")).toString()).equals("0.5"));
TestFmwk.assertTrue("cst009", ((new android.icu.math.BigDecimal("044")).toString()).equals("44"));
TestFmwk.assertTrue("cst010", ((new android.icu.math.BigDecimal("0044")).toString()).equals("44"));
TestFmwk.assertTrue("cst011", ((new android.icu.math.BigDecimal("0.0005")).toString()).equals("0.0005"));
TestFmwk.assertTrue("cst012", ((new android.icu.math.BigDecimal("00.00005")).toString()).equals("0.00005"));
TestFmwk.assertTrue("cst013", ((new android.icu.math.BigDecimal("0.000005")).toString()).equals("0.000005"));
// \NR
TestFmwk.assertTrue("cst014", ((new android.icu.math.BigDecimal("0.0000005")).toString()).equals("0.0000005"));
// \NR
TestFmwk.assertTrue("cst015", ((new android.icu.math.BigDecimal("0.00000005")).toString()).equals("0.00000005"));
TestFmwk.assertTrue("cst016", ((new android.icu.math.BigDecimal("12345678.876543210")).toString()).equals("12345678.876543210"));
TestFmwk.assertTrue("cst017", ((new android.icu.math.BigDecimal("2345678.876543210")).toString()).equals("2345678.876543210"));
TestFmwk.assertTrue("cst018", ((new android.icu.math.BigDecimal("345678.876543210")).toString()).equals("345678.876543210"));
TestFmwk.assertTrue("cst019", ((new android.icu.math.BigDecimal("0345678.87654321")).toString()).equals("345678.87654321"));
TestFmwk.assertTrue("cst020", ((new android.icu.math.BigDecimal("345678.8765432")).toString()).equals("345678.8765432"));
TestFmwk.assertTrue("cst021", ((new android.icu.math.BigDecimal("+345678.8765432")).toString()).equals("345678.8765432"));
TestFmwk.assertTrue("cst022", ((new android.icu.math.BigDecimal("+0345678.8765432")).toString()).equals("345678.8765432"));
TestFmwk.assertTrue("cst023", ((new android.icu.math.BigDecimal("+00345678.8765432")).toString()).equals("345678.8765432"));
TestFmwk.assertTrue("cst024", ((new android.icu.math.BigDecimal("-345678.8765432")).toString()).equals("-345678.8765432"));
TestFmwk.assertTrue("cst025", ((new android.icu.math.BigDecimal("-0345678.8765432")).toString()).equals("-345678.8765432"));
TestFmwk.assertTrue("cst026", ((new android.icu.math.BigDecimal("-00345678.8765432")).toString()).equals("-345678.8765432"));
// exotics --
TestFmwk.assertTrue("cst035", ((new android.icu.math.BigDecimal("\u0e57.\u0e50")).toString()).equals("7.0"));
TestFmwk.assertTrue("cst036", ((new android.icu.math.BigDecimal("\u0b66.\u0b67")).toString()).equals("0.1"));
TestFmwk.assertTrue("cst037", ((new android.icu.math.BigDecimal("\u0b66\u0b66")).toString()).equals("0"));
TestFmwk.assertTrue("cst038", ((new android.icu.math.BigDecimal("\u0b6a\u0b66")).toString()).equals("40"));
// strings with E
TestFmwk.assertTrue("cst040", ((new android.icu.math.BigDecimal("1E+9")).toString()).equals("1E+9"));
TestFmwk.assertTrue("cst041", ((new android.icu.math.BigDecimal("1e+09")).toString()).equals("1E+9"));
TestFmwk.assertTrue("cst042", ((new android.icu.math.BigDecimal("1E+90")).toString()).equals("1E+90"));
TestFmwk.assertTrue("cst043", ((new android.icu.math.BigDecimal("+1E+009")).toString()).equals("1E+9"));
TestFmwk.assertTrue("cst044", ((new android.icu.math.BigDecimal("0E+9")).toString()).equals("0"));
TestFmwk.assertTrue("cst045", ((new android.icu.math.BigDecimal("1E+9")).toString()).equals("1E+9"));
TestFmwk.assertTrue("cst046", ((new android.icu.math.BigDecimal("1E+09")).toString()).equals("1E+9"));
TestFmwk.assertTrue("cst047", ((new android.icu.math.BigDecimal("1e+90")).toString()).equals("1E+90"));
TestFmwk.assertTrue("cst048", ((new android.icu.math.BigDecimal("1E+009")).toString()).equals("1E+9"));
TestFmwk.assertTrue("cst049", ((new android.icu.math.BigDecimal("0E+9")).toString()).equals("0"));
TestFmwk.assertTrue("cst050", ((new android.icu.math.BigDecimal("1E9")).toString()).equals("1E+9"));
TestFmwk.assertTrue("cst051", ((new android.icu.math.BigDecimal("1e09")).toString()).equals("1E+9"));
TestFmwk.assertTrue("cst052", ((new android.icu.math.BigDecimal("1E90")).toString()).equals("1E+90"));
TestFmwk.assertTrue("cst053", ((new android.icu.math.BigDecimal("1E009")).toString()).equals("1E+9"));
TestFmwk.assertTrue("cst054", ((new android.icu.math.BigDecimal("0E9")).toString()).equals("0"));
TestFmwk.assertTrue("cst055", ((new android.icu.math.BigDecimal("0.000e+0")).toString()).equals("0"));
TestFmwk.assertTrue("cst056", ((new android.icu.math.BigDecimal("0.000E-1")).toString()).equals("0"));
TestFmwk.assertTrue("cst057", ((new android.icu.math.BigDecimal("4E+9")).toString()).equals("4E+9"));
TestFmwk.assertTrue("cst058", ((new android.icu.math.BigDecimal("44E+9")).toString()).equals("4.4E+10"));
TestFmwk.assertTrue("cst059", ((new android.icu.math.BigDecimal("0.73e-7")).toString()).equals("7.3E-8"));
TestFmwk.assertTrue("cst060", ((new android.icu.math.BigDecimal("00E+9")).toString()).equals("0"));
TestFmwk.assertTrue("cst061", ((new android.icu.math.BigDecimal("00E-9")).toString()).equals("0"));
TestFmwk.assertTrue("cst062", ((new android.icu.math.BigDecimal("10E+9")).toString()).equals("1.0E+10"));
TestFmwk.assertTrue("cst063", ((new android.icu.math.BigDecimal("10E+09")).toString()).equals("1.0E+10"));
TestFmwk.assertTrue("cst064", ((new android.icu.math.BigDecimal("10e+90")).toString()).equals("1.0E+91"));
TestFmwk.assertTrue("cst065", ((new android.icu.math.BigDecimal("10E+009")).toString()).equals("1.0E+10"));
TestFmwk.assertTrue("cst066", ((new android.icu.math.BigDecimal("100e+9")).toString()).equals("1.00E+11"));
TestFmwk.assertTrue("cst067", ((new android.icu.math.BigDecimal("100e+09")).toString()).equals("1.00E+11"));
TestFmwk.assertTrue("cst068", ((new android.icu.math.BigDecimal("100E+90")).toString()).equals("1.00E+92"));
TestFmwk.assertTrue("cst069", ((new android.icu.math.BigDecimal("100e+009")).toString()).equals("1.00E+11"));
TestFmwk.assertTrue("cst070", ((new android.icu.math.BigDecimal("1.265")).toString()).equals("1.265"));
TestFmwk.assertTrue("cst071", ((new android.icu.math.BigDecimal("1.265E-20")).toString()).equals("1.265E-20"));
TestFmwk.assertTrue("cst072", ((new android.icu.math.BigDecimal("1.265E-8")).toString()).equals("1.265E-8"));
TestFmwk.assertTrue("cst073", ((new android.icu.math.BigDecimal("1.265E-4")).toString()).equals("1.265E-4"));
TestFmwk.assertTrue("cst074", ((new android.icu.math.BigDecimal("1.265E-3")).toString()).equals("1.265E-3"));
TestFmwk.assertTrue("cst075", ((new android.icu.math.BigDecimal("1.265E-2")).toString()).equals("1.265E-2"));
TestFmwk.assertTrue("cst076", ((new android.icu.math.BigDecimal("1.265E-1")).toString()).equals("1.265E-1"));
TestFmwk.assertTrue("cst077", ((new android.icu.math.BigDecimal("1.265E-0")).toString()).equals("1.265"));
TestFmwk.assertTrue("cst078", ((new android.icu.math.BigDecimal("1.265E+1")).toString()).equals("1.265E+1"));
TestFmwk.assertTrue("cst079", ((new android.icu.math.BigDecimal("1.265E+2")).toString()).equals("1.265E+2"));
TestFmwk.assertTrue("cst080", ((new android.icu.math.BigDecimal("1.265E+3")).toString()).equals("1.265E+3"));
TestFmwk.assertTrue("cst081", ((new android.icu.math.BigDecimal("1.265E+4")).toString()).equals("1.265E+4"));
TestFmwk.assertTrue("cst082", ((new android.icu.math.BigDecimal("1.265E+8")).toString()).equals("1.265E+8"));
TestFmwk.assertTrue("cst083", ((new android.icu.math.BigDecimal("1.265E+20")).toString()).equals("1.265E+20"));
TestFmwk.assertTrue("cst090", ((new android.icu.math.BigDecimal("12.65")).toString()).equals("12.65"));
TestFmwk.assertTrue("cst091", ((new android.icu.math.BigDecimal("12.65E-20")).toString()).equals("1.265E-19"));
TestFmwk.assertTrue("cst092", ((new android.icu.math.BigDecimal("12.65E-8")).toString()).equals("1.265E-7"));
TestFmwk.assertTrue("cst093", ((new android.icu.math.BigDecimal("12.65E-4")).toString()).equals("1.265E-3"));
TestFmwk.assertTrue("cst094", ((new android.icu.math.BigDecimal("12.65E-3")).toString()).equals("1.265E-2"));
TestFmwk.assertTrue("cst095", ((new android.icu.math.BigDecimal("12.65E-2")).toString()).equals("1.265E-1"));
TestFmwk.assertTrue("cst096", ((new android.icu.math.BigDecimal("12.65E-1")).toString()).equals("1.265"));
TestFmwk.assertTrue("cst097", ((new android.icu.math.BigDecimal("12.65E-0")).toString()).equals("1.265E+1"));
TestFmwk.assertTrue("cst098", ((new android.icu.math.BigDecimal("12.65E+1")).toString()).equals("1.265E+2"));
TestFmwk.assertTrue("cst099", ((new android.icu.math.BigDecimal("12.65E+2")).toString()).equals("1.265E+3"));
TestFmwk.assertTrue("cst100", ((new android.icu.math.BigDecimal("12.65E+3")).toString()).equals("1.265E+4"));
TestFmwk.assertTrue("cst101", ((new android.icu.math.BigDecimal("12.65E+4")).toString()).equals("1.265E+5"));
TestFmwk.assertTrue("cst102", ((new android.icu.math.BigDecimal("12.65E+8")).toString()).equals("1.265E+9"));
TestFmwk.assertTrue("cst103", ((new android.icu.math.BigDecimal("12.65E+20")).toString()).equals("1.265E+21"));
TestFmwk.assertTrue("cst110", ((new android.icu.math.BigDecimal("126.5")).toString()).equals("126.5"));
TestFmwk.assertTrue("cst111", ((new android.icu.math.BigDecimal("126.5E-20")).toString()).equals("1.265E-18"));
TestFmwk.assertTrue("cst112", ((new android.icu.math.BigDecimal("126.5E-8")).toString()).equals("1.265E-6"));
TestFmwk.assertTrue("cst113", ((new android.icu.math.BigDecimal("126.5E-4")).toString()).equals("1.265E-2"));
TestFmwk.assertTrue("cst114", ((new android.icu.math.BigDecimal("126.5E-3")).toString()).equals("1.265E-1"));
TestFmwk.assertTrue("cst115", ((new android.icu.math.BigDecimal("126.5E-2")).toString()).equals("1.265"));
TestFmwk.assertTrue("cst116", ((new android.icu.math.BigDecimal("126.5E-1")).toString()).equals("1.265E+1"));
TestFmwk.assertTrue("cst117", ((new android.icu.math.BigDecimal("126.5E-0")).toString()).equals("1.265E+2"));
TestFmwk.assertTrue("cst118", ((new android.icu.math.BigDecimal("126.5E+1")).toString()).equals("1.265E+3"));
TestFmwk.assertTrue("cst119", ((new android.icu.math.BigDecimal("126.5E+2")).toString()).equals("1.265E+4"));
TestFmwk.assertTrue("cst120", ((new android.icu.math.BigDecimal("126.5E+3")).toString()).equals("1.265E+5"));
TestFmwk.assertTrue("cst121", ((new android.icu.math.BigDecimal("126.5E+4")).toString()).equals("1.265E+6"));
TestFmwk.assertTrue("cst122", ((new android.icu.math.BigDecimal("126.5E+8")).toString()).equals("1.265E+10"));
TestFmwk.assertTrue("cst123", ((new android.icu.math.BigDecimal("126.5E+20")).toString()).equals("1.265E+22"));
TestFmwk.assertTrue("cst130", ((new android.icu.math.BigDecimal("1265")).toString()).equals("1265"));
TestFmwk.assertTrue("cst131", ((new android.icu.math.BigDecimal("1265E-20")).toString()).equals("1.265E-17"));
TestFmwk.assertTrue("cst132", ((new android.icu.math.BigDecimal("1265E-8")).toString()).equals("1.265E-5"));
TestFmwk.assertTrue("cst133", ((new android.icu.math.BigDecimal("1265E-4")).toString()).equals("1.265E-1"));
TestFmwk.assertTrue("cst134", ((new android.icu.math.BigDecimal("1265E-3")).toString()).equals("1.265"));
TestFmwk.assertTrue("cst135", ((new android.icu.math.BigDecimal("1265E-2")).toString()).equals("1.265E+1"));
TestFmwk.assertTrue("cst136", ((new android.icu.math.BigDecimal("1265E-1")).toString()).equals("1.265E+2"));
TestFmwk.assertTrue("cst137", ((new android.icu.math.BigDecimal("1265E-0")).toString()).equals("1.265E+3"));
TestFmwk.assertTrue("cst138", ((new android.icu.math.BigDecimal("1265E+1")).toString()).equals("1.265E+4"));
TestFmwk.assertTrue("cst139", ((new android.icu.math.BigDecimal("1265E+2")).toString()).equals("1.265E+5"));
TestFmwk.assertTrue("cst140", ((new android.icu.math.BigDecimal("1265E+3")).toString()).equals("1.265E+6"));
TestFmwk.assertTrue("cst141", ((new android.icu.math.BigDecimal("1265E+4")).toString()).equals("1.265E+7"));
TestFmwk.assertTrue("cst142", ((new android.icu.math.BigDecimal("1265E+8")).toString()).equals("1.265E+11"));
TestFmwk.assertTrue("cst143", ((new android.icu.math.BigDecimal("1265E+20")).toString()).equals("1.265E+23"));
TestFmwk.assertTrue("cst150", ((new android.icu.math.BigDecimal("0.1265")).toString()).equals("0.1265"));
TestFmwk.assertTrue("cst151", ((new android.icu.math.BigDecimal("0.1265E-20")).toString()).equals("1.265E-21"));
TestFmwk.assertTrue("cst152", ((new android.icu.math.BigDecimal("0.1265E-8")).toString()).equals("1.265E-9"));
TestFmwk.assertTrue("cst153", ((new android.icu.math.BigDecimal("0.1265E-4")).toString()).equals("1.265E-5"));
TestFmwk.assertTrue("cst154", ((new android.icu.math.BigDecimal("0.1265E-3")).toString()).equals("1.265E-4"));
TestFmwk.assertTrue("cst155", ((new android.icu.math.BigDecimal("0.1265E-2")).toString()).equals("1.265E-3"));
TestFmwk.assertTrue("cst156", ((new android.icu.math.BigDecimal("0.1265E-1")).toString()).equals("1.265E-2"));
TestFmwk.assertTrue("cst157", ((new android.icu.math.BigDecimal("0.1265E-0")).toString()).equals("1.265E-1"));
TestFmwk.assertTrue("cst158", ((new android.icu.math.BigDecimal("0.1265E+1")).toString()).equals("1.265"));
TestFmwk.assertTrue("cst159", ((new android.icu.math.BigDecimal("0.1265E+2")).toString()).equals("1.265E+1"));
TestFmwk.assertTrue("cst160", ((new android.icu.math.BigDecimal("0.1265E+3")).toString()).equals("1.265E+2"));
TestFmwk.assertTrue("cst161", ((new android.icu.math.BigDecimal("0.1265E+4")).toString()).equals("1.265E+3"));
TestFmwk.assertTrue("cst162", ((new android.icu.math.BigDecimal("0.1265E+8")).toString()).equals("1.265E+7"));
TestFmwk.assertTrue("cst163", ((new android.icu.math.BigDecimal("0.1265E+20")).toString()).equals("1.265E+19"));
TestFmwk.assertTrue("cst170", ((new android.icu.math.BigDecimal("0.09e999999999")).toString()).equals("9E+999999997"));
TestFmwk.assertTrue("cst171", ((new android.icu.math.BigDecimal("0.9e999999999")).toString()).equals("9E+999999998"));
TestFmwk.assertTrue("cst172", ((new android.icu.math.BigDecimal("9e999999999")).toString()).equals("9E+999999999"));
TestFmwk.assertTrue("cst173", ((new android.icu.math.BigDecimal("9.9e999999999")).toString()).equals("9.9E+999999999"));
TestFmwk.assertTrue("cst174", ((new android.icu.math.BigDecimal("9.99e999999999")).toString()).equals("9.99E+999999999"));
TestFmwk.assertTrue("cst175", ((new android.icu.math.BigDecimal("9.99e-999999999")).toString()).equals("9.99E-999999999"));
TestFmwk.assertTrue("cst176", ((new android.icu.math.BigDecimal("9.9e-999999999")).toString()).equals("9.9E-999999999"));
TestFmwk.assertTrue("cst177", ((new android.icu.math.BigDecimal("9e-999999999")).toString()).equals("9E-999999999"));
TestFmwk.assertTrue("cst179", ((new android.icu.math.BigDecimal("99e-999999999")).toString()).equals("9.9E-999999998"));
TestFmwk.assertTrue("cst180", ((new android.icu.math.BigDecimal("999e-999999999")).toString()).equals("9.99E-999999997"));
// baddies --
badstrings = new java.lang.String[] { "1..2", ".", "..", "++1", "--1", "-+1", "+-1", "12e", "12e++", "12f4", " +1", "+ 1", "12 ", " + 1", " - 1 ", "x", "-1-", "12-", "3+", "", "1e-", "7e1000000000", "", "e100", "\u0e5a", "\u0b65", "99e999999999", "999e999999999", "0.9e-999999999", "0.09e-999999999", "0.1e1000000000", "10e-1000000000", "0.9e9999999999", "99e-9999999999", "111e9999999999", "1111e-9999999999" + " " + "111e*123", "111e123-", "111e+12+", "111e1-3-", "111e1*23", "111e1e+3", "1e1.0", "1e123e", "ten", "ONE", "1e.1", "1e1.", "1ee", // 200-203
"e+1" };
// 204-207
// 208-211
// 211-214
// 215-219
// 220-222
// 223-224
// 225-226
// 227-228
// 229-230
// 231-232
// 233-234
// 235-237
// 238-240
// 241-244
// 245-248
// watch out for commas on continuation lines
{
int $16 = badstrings.length;
i = 0;
for (; $16 > 0; $16--, i++) {
try {
new android.icu.math.BigDecimal(badstrings[i]);
say(">>> cst" + (200 + i) + ":" + " " + badstrings[i] + " " + (new android.icu.math.BigDecimal(badstrings[i])).toString());
flag = false;
} catch (java.lang.NumberFormatException $17) {
flag = true;
}
TestFmwk.assertTrue("cst" + (200 + i), flag);
}
}
try {
new android.icu.math.BigDecimal((java.lang.String) null);
flag = false;
} catch (java.lang.NullPointerException $18) {
flag = true;
}
/* checknull */
TestFmwk.assertTrue("cst301", flag);
return;
}
use of android.icu.math.BigDecimal in project j2objc by google.
the class DiagBigDecimalTest method diagcompareto.
/* ----------------------------------------------------------------- */
/**
* Test the {@link android.icu.math.BigDecimal#compareTo(BigDecimal)}
* method.
*/
@Test
public void diagcompareto() {
boolean flag = false;
java.lang.ArithmeticException ae = null;
// we assume add/subtract test function; this just
// tests existence, exceptions, and possible results
TestFmwk.assertTrue("cpt001", ((new android.icu.math.BigDecimal("5")).compareTo(new android.icu.math.BigDecimal("2"))) == 1);
TestFmwk.assertTrue("cpt002", ((new android.icu.math.BigDecimal("5")).compareTo(new android.icu.math.BigDecimal("5"))) == 0);
TestFmwk.assertTrue("cpt003", ((new android.icu.math.BigDecimal("5")).compareTo(new android.icu.math.BigDecimal("5.00"))) == 0);
TestFmwk.assertTrue("cpt004", ((new android.icu.math.BigDecimal("0.5")).compareTo(new android.icu.math.BigDecimal("0.5"))) == 0);
TestFmwk.assertTrue("cpt005", ((new android.icu.math.BigDecimal("2")).compareTo(new android.icu.math.BigDecimal("5"))) == (-1));
TestFmwk.assertTrue("cpt006", ((new android.icu.math.BigDecimal("2")).compareTo(new android.icu.math.BigDecimal("5"), mcdef)) == (-1));
TestFmwk.assertTrue("cpt007", ((new android.icu.math.BigDecimal("2")).compareTo(new android.icu.math.BigDecimal("5"), mc6)) == (-1));
TestFmwk.assertTrue("cpt008", ((new android.icu.math.BigDecimal("2")).compareTo(new android.icu.math.BigDecimal("5"), mcfd)) == (-1));
try {
ten.compareTo((android.icu.math.BigDecimal) null);
flag = false;
} catch (java.lang.NullPointerException $28) {
flag = true;
}
/* checknull */
TestFmwk.assertTrue("cpt100", flag);
try {
ten.compareTo(ten, (android.icu.math.MathContext) null);
flag = false;
} catch (java.lang.NullPointerException $29) {
flag = true;
}
/* checknull2 */
TestFmwk.assertTrue("cpt101", flag);
try {
tenlong.compareTo(android.icu.math.BigDecimal.ONE, mcld);
flag = false;
} catch (java.lang.ArithmeticException $30) {
ae = $30;
flag = (ae.getMessage()).equals("Too many digits:" + " " + tenlong.toString());
}
/* checkdigits */
TestFmwk.assertTrue("cpt102", flag);
try {
android.icu.math.BigDecimal.ONE.compareTo(tenlong, mcld);
flag = false;
} catch (java.lang.ArithmeticException $31) {
ae = $31;
flag = (ae.getMessage()).equals("Too many digits:" + " " + tenlong.toString());
}
/* checkdigits */
TestFmwk.assertTrue("cpt103", flag);
}
Aggregations