## Examples of java.math.BigInteger

• java.math.BigInteger
Immutable arbitrary-precision integers. All operations behave as if BigIntegers were represented in two's-complement notation (like Java's primitive integer types). BigInteger provides analogues to all of Java's primitive integer operators, and all relevant methods from java.lang.Math. Additionally, BigInteger provides operations for modular arithmetic, GCD calculation, primality testing, prime generation, bit manipulation, and a few other miscellaneous operations.

Semantics of arithmetic operations exactly mimic those of Java's integer arithmetic operators, as defined in The Java Language Specification. For example, division by zero throws an {@code ArithmeticException}, and division of a negative by a positive yields a negative (or zero) remainder. All of the details in the Spec concerning overflow are ignored, as BigIntegers are made as large as necessary to accommodate the results of an operation.

Semantics of shift operations extend those of Java's shift operators to allow for negative shift distances. A right-shift with a negative shift distance results in a left shift, and vice-versa. The unsigned right shift operator ( {@code >>>}) is omitted, as this operation makes little sense in combination with the "infinite word size" abstraction provided by this class.

Semantics of bitwise logical operations exactly mimic those of Java's bitwise integer operators. The binary operators ( {@code and}, {@code or}, {@code xor}) implicitly perform sign extension on the shorter of the two operands prior to performing the operation.

Comparison operations perform signed integer comparisons, analogous to those performed by Java's relational and equality operators.

Modular arithmetic operations are provided to compute residues, perform exponentiation, and compute multiplicative inverses. These methods always return a non-negative result, between {@code 0} and {@code (modulus - 1)}, inclusive.

Bit operations operate on a single bit of the two's-complement representation of their operand. If necessary, the operand is sign- extended so that it contains the designated bit. None of the single-bit operations can produce a BigInteger with a different sign from the BigInteger being operated on, as they affect only a single bit, and the "infinite word size" abstraction provided by this class ensures that there are infinitely many "virtual sign bits" preceding each BigInteger.

For the sake of brevity and clarity, pseudo-code is used throughout the descriptions of BigInteger methods. The pseudo-code expression {@code (i + j)} is shorthand for "a BigInteger whose value isthat of the BigInteger {@code i} plus that of the BigInteger {@code j}." The pseudo-code expression {@code (i == j)} is shorthand for" {@code true} if and only if the BigInteger {@code i} represents the samevalue as the BigInteger {@code j}." Other pseudo-code expressions are interpreted similarly.

All methods and constructors in this class throw {@code NullPointerException} when passeda null object reference for any input parameter. @see BigDecimal @author Josh Bloch @author Michael McCloskey @since JDK1.1

 `1089109010911092109310941095` ```  }   public static Object parseBigInteger(String number, String format)     throws FunctionExecutionException {     Number bigIntegerNum = parseNumberHelper(number, format);     return new BigInteger(bigIntegerNum.toString());   } ```
View Full Code Here

 `770771772773774775776777778779780781782` ```    private Object consumeMsg(BigInteger object, Element cellElement) throws JDOMException {         // -----------------------         // Process the element ...         // -----------------------         BigInteger result;         try {             result = new BigInteger(cellElement.getTextTrim());         } catch ( NumberFormatException e ) {             throw new JDOMException("Unable to parse the value for " + cellElement.getName() + //\$NON-NLS-1\$                                     " element: " + cellElement.getTextTrim(), e); //\$NON-NLS-1\$         }         return result; ```
View Full Code Here

 `551552553554555556557` ```    @Test public void testInvokeMinus4() {         helpInvokeMethod("-", new Object[] { new Double(3), new Double(2) }, new Double(1)); //\$NON-NLS-1\$     }     @Test public void testInvokeMinus5() {         helpInvokeMethod("-", new Object[] { new BigInteger("3"), new BigInteger("2") }, new BigInteger("1")); //\$NON-NLS-1\$ //\$NON-NLS-2\$ //\$NON-NLS-3\$ //\$NON-NLS-4\$     } ```
View Full Code Here

 `575576577578579580581` ```    @Test public void testInvokeMultiply4() {         helpInvokeMethod("*", new Object[] { new Double(3), new Double(2) }, new Double(6)); //\$NON-NLS-1\$     }     @Test public void testInvokeMultiply5() {         helpInvokeMethod("*", new Object[] { new BigInteger("3"), new BigInteger("2") }, new BigInteger("6")); //\$NON-NLS-1\$ //\$NON-NLS-2\$ //\$NON-NLS-3\$ //\$NON-NLS-4\$     } ```
View Full Code Here

 `599600601602603604605` ```    @Test public void testInvokeDivide4() {         helpInvokeMethod("/", new Object[] { new Double(3), new Double(2) }, new Double(1.5)); //\$NON-NLS-1\$     }     @Test public void testInvokeDivide5() {         helpInvokeMethod("/", new Object[] { new BigInteger("3"), new BigInteger("2") }, new BigInteger("1")); //\$NON-NLS-1\$ //\$NON-NLS-2\$ //\$NON-NLS-3\$ //\$NON-NLS-4\$     } ```
View Full Code Here

 `632633634635636637638` ```    @Test public void testInvokeAbs4() {         helpInvokeMethod("abs", new Object[] { new Double(-3) }, new Double(3)); //\$NON-NLS-1\$     }     @Test public void testInvokeAbs5() {         helpInvokeMethod("abs", new Object[] { new BigInteger("-3") }, new BigInteger("3")); //\$NON-NLS-1\$ //\$NON-NLS-2\$ //\$NON-NLS-3\$     } ```
View Full Code Here

 `866867868869870871872` ```  @Test public void testInvokeParseFloat() {     helpInvokeMethod("parseFloat", new Object[] {new String("1234.56"), new String("####.###")}, new Float(1234.56));   //\$NON-NLS-1\$ //\$NON-NLS-2\$ //\$NON-NLS-3\$   }     @Test public void testInvokeParseBigInteger() {     helpInvokeMethod("parseBigInteger", new Object[] {new String("12345678"), new String("###,###")}, new BigInteger("12345678"));   //\$NON-NLS-1\$ //\$NON-NLS-2\$ //\$NON-NLS-3\$ //\$NON-NLS-4\$   } ```
View Full Code Here

 `890891892893894895896` ```  @Test public void testInvokeFormatFloat() {     helpInvokeMethod("formatFloat", new Object[] {new Float(1234.67), new String("###.###")}, "1234.67");   //\$NON-NLS-1\$ //\$NON-NLS-2\$ //\$NON-NLS-3\$   }     @Test public void testInvokeFormatBigInteger() {     helpInvokeMethod("formatBigInteger", new Object[] {new BigInteger("45"), new String("###.###")}, "45");   //\$NON-NLS-1\$ //\$NON-NLS-2\$ //\$NON-NLS-3\$ //\$NON-NLS-4\$   } ```
View Full Code Here

 `7879808182838485868788899091` ```                                                new List[] { Arrays.asList(new Object[] {                             ts,                             new Double(Double.NEGATIVE_INFINITY),                             new Float(Float.POSITIVE_INFINITY),                             new BigInteger("100"), //\$NON-NLS-1\$                             new BigInteger("100"), //\$NON-NLS-1\$                             ts,                             new BigInteger("100"), //\$NON-NLS-1\$                             ts,                             "1" //\$NON-NLS-1\$                                                    })});                 ```
View Full Code Here

 `590591592593594595596597598599600` ```      SimpleMetaType st = (SimpleMetaType) type;       if (SimpleMetaType.BIGDECIMAL.equals(st)) {         return new SimpleValueSupport(st, new BigDecimal(value));       } else if (SimpleMetaType.BIGINTEGER.equals(st)) {         return new SimpleValueSupport(st, new BigInteger(value));       } else if (SimpleMetaType.BOOLEAN.equals(st)) {         return new SimpleValueSupport(st, Boolean.valueOf(value));       } else if (SimpleMetaType.BOOLEAN_PRIMITIVE.equals(st)) {         return new SimpleValueSupport(st, Boolean.valueOf(value)             .booleanValue()); ```
View Full Code Here