< prev index next >

src/java.base/share/classes/java/math/BigInteger.java

Print this page

        

*** 50,71 **** * Additionally, BigInteger provides operations for modular arithmetic, GCD * calculation, primality testing, prime generation, bit manipulation, * and a few other miscellaneous operations. * * <p>Semantics of arithmetic operations exactly mimic those of Java's integer ! * arithmetic operators, as defined in <i>The Java Language Specification</i>. * 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. * * <p>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. * * <p>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 --- 50,68 ---- * Additionally, BigInteger provides operations for modular arithmetic, GCD * calculation, primality testing, prime generation, bit manipulation, * and a few other miscellaneous operations. * * <p>Semantics of arithmetic operations exactly mimic those of Java's integer ! * arithmetic operators, as defined in <i>The Java&trade; Language Specification</i>. * For example, division by zero throws an {@code ArithmeticException}, and * division of a negative by a positive yields a negative (or zero) remainder. * * <p>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 arbitrarily large abstraction * provided by this class. * * <p>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
*** 82,93 **** * <p>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. * * <p>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 is * that of the BigInteger {@code i} plus that of the BigInteger {@code j}." --- 79,90 ---- * <p>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 ! * arbitrarily large abstraction provided by this class ensures that conceptually ! * there are infinitely many "virtual sign bits" preceding each BigInteger. * * <p>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 is * that of the BigInteger {@code i} plus that of the BigInteger {@code j}."
*** 103,119 **** * BigInteger must support values in the range * -2<sup>{@code Integer.MAX_VALUE}</sup> (exclusive) to * +2<sup>{@code Integer.MAX_VALUE}</sup> (exclusive) * and may support values outside of that range. * * The range of probable prime values is limited and may be less than * the full supported positive range of {@code BigInteger}. * The range must be at least 1 to 2<sup>500000000</sup>. * * @implNote ! * BigInteger constructors and operations throw {@code ArithmeticException} when ! * the result is out of the supported range of * -2<sup>{@code Integer.MAX_VALUE}</sup> (exclusive) to * +2<sup>{@code Integer.MAX_VALUE}</sup> (exclusive). * * @see BigDecimal * @jls 4.2.2 Integer Operations --- 100,121 ---- * BigInteger must support values in the range * -2<sup>{@code Integer.MAX_VALUE}</sup> (exclusive) to * +2<sup>{@code Integer.MAX_VALUE}</sup> (exclusive) * and may support values outside of that range. * + * An {@code ArithmeticException} is thrown when a BigInteger + * constructor or method would generate a value outside of the + * supported range. + * * The range of probable prime values is limited and may be less than * the full supported positive range of {@code BigInteger}. * The range must be at least 1 to 2<sup>500000000</sup>. * * @implNote ! * In the reference implementation, BigInteger constructors and ! * operations throw {@code ArithmeticException} when the result is out ! * of the supported range of * -2<sup>{@code Integer.MAX_VALUE}</sup> (exclusive) to * +2<sup>{@code Integer.MAX_VALUE}</sup> (exclusive). * * @see BigDecimal * @jls 4.2.2 Integer Operations
< prev index next >