Search in sources :

Example 51 with RoundingMode

use of java.math.RoundingMode in project guava by hceylan.

the class BigIntegerMathTest method testDivByZeroAlwaysFails.

public void testDivByZeroAlwaysFails() {
    for (BigInteger p : ALL_BIGINTEGER_CANDIDATES) {
        for (RoundingMode mode : ALL_ROUNDING_MODES) {
            try {
                BigIntegerMath.divide(p, ZERO, mode);
                fail("Expected ArithmeticException");
            } catch (ArithmeticException expected) {
            }
        }
    }
}
Also used : RoundingMode(java.math.RoundingMode) BigInteger(java.math.BigInteger)

Example 52 with RoundingMode

use of java.math.RoundingMode in project guava by hceylan.

the class BigIntegerMathTest method testDivNonZero.

public void testDivNonZero() {
    for (BigInteger p : NONZERO_BIGINTEGER_CANDIDATES) {
        for (BigInteger q : NONZERO_BIGINTEGER_CANDIDATES) {
            for (RoundingMode mode : ALL_SAFE_ROUNDING_MODES) {
                BigInteger expected = new BigDecimal(p).divide(new BigDecimal(q), 0, mode).toBigIntegerExact();
                assertEquals(expected, BigIntegerMath.divide(p, q, mode));
            }
        }
    }
}
Also used : RoundingMode(java.math.RoundingMode) BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal)

Example 53 with RoundingMode

use of java.math.RoundingMode in project guava by hceylan.

the class BigIntegerMathTest method testLog10Floor.

public void testLog10Floor() {
    for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) {
        for (RoundingMode mode : asList(FLOOR, DOWN)) {
            int result = BigIntegerMath.log10(x, mode);
            assertTrue(TEN.pow(result).compareTo(x) <= 0);
            assertTrue(TEN.pow(result + 1).compareTo(x) > 0);
        }
    }
}
Also used : RoundingMode(java.math.RoundingMode) BigInteger(java.math.BigInteger)

Example 54 with RoundingMode

use of java.math.RoundingMode in project guava by hceylan.

the class IntMathTest method testLog2ZeroAlwaysThrows.

@GwtIncompatible("log2")
public void testLog2ZeroAlwaysThrows() {
    for (RoundingMode mode : ALL_ROUNDING_MODES) {
        try {
            IntMath.log2(0, mode);
            fail("Expected IllegalArgumentException");
        } catch (IllegalArgumentException expected) {
        }
    }
}
Also used : RoundingMode(java.math.RoundingMode) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 55 with RoundingMode

use of java.math.RoundingMode in project guava by hceylan.

the class IntMathTest method testDivByZeroAlwaysFails.

@GwtIncompatible("pow()")
public void testDivByZeroAlwaysFails() {
    for (int p : ALL_INTEGER_CANDIDATES) {
        for (RoundingMode mode : ALL_ROUNDING_MODES) {
            try {
                IntMath.divide(p, 0, mode);
                fail("Expected ArithmeticException");
            } catch (ArithmeticException expected) {
            }
        }
    }
}
Also used : RoundingMode(java.math.RoundingMode) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Aggregations

RoundingMode (java.math.RoundingMode)206 BigDecimal (java.math.BigDecimal)127 BigInteger (java.math.BigInteger)88 MathContext (java.math.MathContext)72 GwtIncompatible (com.google.common.annotations.GwtIncompatible)39 DecimalFormat (java.text.DecimalFormat)5 IDataMap (permafrost.tundra.data.IDataMap)5 Test (org.junit.Test)3 MifosConfigurationManager (org.mifos.config.business.MifosConfigurationManager)3 GridBagConstraints (java.awt.GridBagConstraints)2 GridBagLayout (java.awt.GridBagLayout)2 Insets (java.awt.Insets)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 ButtonGroup (javax.swing.ButtonGroup)2 JLabel (javax.swing.JLabel)2 JPanel (javax.swing.JPanel)2 JRadioButton (javax.swing.JRadioButton)2 JSpinner (javax.swing.JSpinner)2 SpinnerNumberModel (javax.swing.SpinnerNumberModel)2