cs1.5 谁有个性化的btnsbar .btn.ok_ma...

BigInteger (Java Platform SE 7 )
JavaScript is disabled on your browser.
Class BigInteger
java.math.BigInteger
All Implemented Interfaces:
public class BigInteger
implements &&
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 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 (&&&) 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 (and,
or, 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 0 and (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
(i + j) is shorthand for "a BigInteger whose value is
that of the BigInteger i plus that of the BigInteger j."
The pseudo-code expression (i == j) is shorthand for
"true if and only if the BigInteger i represents the same
value as the BigInteger j."
Other pseudo-code expressions are
interpreted similarly.
All methods and constructors in this class throw
NullPointerException when passed
a null object reference for any input parameter.
See Also:,
Field Summary
Modifier and Type
Field and Description
The BigInteger constant one.
The BigInteger constant ten.
The BigInteger constant zero.
Constructor Summary
Constructors&
Constructor and Description
(byte[]&val)
Translates a byte array containing the two's-complement binary
representation of a BigInteger into a BigInteger.
(int&signum,
byte[]&magnitude)
Translates the sign-magnitude representation of a BigInteger into a
BigInteger.
(int&bitLength,
int&certainty,
Constructs a randomly generated positive BigInteger that is probably
prime, with the specified bitLength.
(int&numBits,
Constructs a randomly generated BigInteger, uniformly distributed over
the range 0 to (2numBits - 1), inclusive.
Translates the decimal String representation of a BigInteger into a
BigInteger.
int&radix)
Translates the String representation of a BigInteger in the
specified radix into a BigInteger.
Method Summary
Modifier and Type
Method and Description
Returns a BigInteger whose value is the absolute value of this
BigInteger.
Returns a BigInteger whose value is (this + val).
Returns a BigInteger whose value is (this & val).
Returns a BigInteger whose value is (this & ~val).
Returns the number of bits in the two's complement representation
of this BigInteger that differ from its sign bit.
Returns the number of bits in the minimal two's-complement
representation of this BigInteger, excluding a sign bit.
Returns a BigInteger whose value is equivalent to this BigInteger
with the designated bit cleared.
Compares this BigInteger with the specified BigInteger.
Returns a BigInteger whose value is (this / val).
Returns an array of two BigIntegers containing (this / val)
followed by (this % val).
Converts this BigInteger to a double.
Compares this BigInteger with the specified Object for equality.
Returns a BigInteger whose value is equivalent to this BigInteger
with the designated bit flipped.
Converts this BigInteger to a float.
Returns a BigInteger whose value is the greatest common divisor of
abs(this) and abs(val).
Returns the index of the rightmost (lowest-order) one bit in this
BigInteger (the number of zero bits to the right of the rightmost
Returns the hash code for this BigInteger.
Converts this BigInteger to an int.
(int&certainty)
Returns true if this BigInteger is probably prime,
false if it's definitely composite.
Converts this BigInteger to a long.
Returns the maximum of this BigInteger and val.
Returns the minimum of this BigInteger and val.
Returns a BigInteger whose value is (this mod m).
Returns a BigInteger whose value is (this-1 mod m).
(&exponent,
Returns a BigInteger whose value is
(thisexponent mod m).
Returns a BigInteger whose value is (this * val).
Returns a BigInteger whose value is (-this).
Returns the first integer greater than this BigInteger that
is probably prime.
Returns a BigInteger whose value is (~this).
Returns a BigInteger whose value is (this | val).
(int&exponent)
Returns a BigInteger whose value is (thisexponent).
(int&bitLength,
Returns a positive BigInteger that is probably prime, with the
specified bitLength.
Returns a BigInteger whose value is (this % val).
Returns a BigInteger whose value is equivalent to this BigInteger
with the designated bit set.
Returns a BigInteger whose value is (this && n).
Returns a BigInteger whose value is (this && n).
Returns the signum function of this BigInteger.
Returns a BigInteger whose value is (this - val).
Returns true if and only if the designated bit is set.
Returns a byte array containing the two's-complement
representation of this BigInteger.
Returns the decimal String representation of this BigInteger.
(int&radix)
Returns the String representation of this BigInteger in the
given radix.
(long&val)
Returns a BigInteger whose value is equal to that of the
specified long.
Returns a BigInteger whose value is (this ^ val).
Methods inherited from class&java.lang.
Methods inherited from class&java.lang.
, , , , , , ,
Field Detail
public static final& ZERO
The BigInteger constant zero.
public static final& ONE
The BigInteger constant one.
public static final& TEN
The BigInteger constant ten.
Constructor Detail
BigInteger
public&BigInteger(byte[]&val)
Translates a byte array containing the two's-complement binary
representation of a BigInteger into a BigInteger.
The input array is
assumed to be in big-endian byte-order: the most significant
byte is in the zeroth element.
Parameters:val - big-endian two's-complement binary representation of
BigInteger.
- val is zero bytes long.
BigInteger
public&BigInteger(int&signum,
byte[]&magnitude)
Translates the sign-magnitude representation of a BigInteger into a
BigInteger.
The sign is represented as an integer signum value: -1 for
negative, 0 for zero, or 1 for positive.
The magnitude is a byte array
in big-endian byte-order: the most significant byte is in the
zeroth element.
A zero-length magnitude array is permissible, and will
result in a BigInteger value of 0, whether signum is -1, 0 or 1.
Parameters:signum - signum of the number (-1 for negative, 0 for zero, 1
for positive).magnitude - big-endian binary representation of the magnitude of
the number.
- signum is not one of the three
legal values (-1, 0, and 1), or signum is 0 and
magnitude contains one or more non-zero bytes.
BigInteger
public&BigInteger(&val,
int&radix)
Translates the String representation of a BigInteger in the
specified radix into a BigInteger.
The String representation
consists of an optional minus or plus sign followed by a
sequence of one or more digits in the specified radix.
character-to-digit mapping is provided by Character.digit.
The String may not contain any extraneous
characters (whitespace, for example).
Parameters:val - String representation of BigInteger.radix - radix to be used in interpreting val.
- val is not a valid representation
of a BigInteger in the specified radix, or radix is
outside the range from
, inclusive.See Also:
BigInteger
public&BigInteger(&val)
Translates the decimal String representation of a BigInteger into a
BigInteger.
The String representation consists of an optional minus
sign followed by a sequence of one or more decimal digits.
character-to-digit mapping is provided by Character.digit.
The String may not contain any extraneous characters (whitespace, for
Parameters:val - decimal String representation of BigInteger.
- val is not a valid representation
of a BigInteger.See Also:
BigInteger
public&BigInteger(int&numBits,
Constructs a randomly generated BigInteger, uniformly distributed over
the range 0 to (2numBits - 1), inclusive.
The uniformity of the distribution assumes that a fair source of random
bits is provided in rnd.
Note that this constructor always
constructs a non-negative BigInteger.
Parameters:numBits - maximum bitLength of the new BigInteger.rnd - source of randomness to be used in computing the new
BigInteger.
- numBits is negative.See Also:
BigInteger
public&BigInteger(int&bitLength,
int&certainty,
Constructs a randomly generated positive BigInteger that is probably
prime, with the specified bitLength.
It is recommended that the
method be used in preference to this constructor unless there
is a compelling need to specify a certainty.
Parameters:bitLength - bitLength of the returned BigInteger.certainty - a measure of the uncertainty that the caller is
willing to tolerate.
The probability that the new BigInteger
represents a prime number will exceed
(1 - 1/2certainty).
The execution time of
this constructor is proportional to the value of this parameter.rnd - source of random bits used to select candidates to be
tested for primality.
- bitLength & 2.See Also:
Method Detail
probablePrime
public static&&probablePrime(int&bitLength,
Returns a positive BigInteger that is probably prime, with the
specified bitLength. The probability that a BigInteger returned
by this method is composite does not exceed 2-100.
Parameters:bitLength - bitLength of the returned BigInteger.rnd - source of random bits used to select candidates to be
tested for primality.
Returns:a BigInteger of bitLength bits that is probably prime
- bitLength & 2.Since:
nextProbablePrime
public&&nextProbablePrime()
Returns the first integer greater than this BigInteger that
is probably prime.
The probability that the number returned by this
method is composite does not exceed 2-100. This method will
never skip over a prime when searching: if it returns p, there
is no prime q such that this & q & p.
Returns:the first integer greater than this BigInteger that
is probably prime.
- this & 0.Since:
public static&&valueOf(long&val)
Returns a BigInteger whose value is equal to that of the
specified long.
This "static factory method" is
provided in preference to a (long) constructor
because it allows for reuse of frequently used BigIntegers.
Parameters:val - value of the BigInteger to return.
Returns:a BigInteger with the specified value.
public&&add(&val)
Returns a BigInteger whose value is (this + val).
Parameters:val - value to be added to this BigInteger.
Returns:this + val
public&&subtract(&val)
Returns a BigInteger whose value is (this - val).
Parameters:val - value to be subtracted from this BigInteger.
Returns:this - val
public&&multiply(&val)
Returns a BigInteger whose value is (this * val).
Parameters:val - value to be multiplied by this BigInteger.
Returns:this * val
public&÷(&val)
Returns a BigInteger whose value is (this / val).
Parameters:val - value by which this BigInteger is to be divided.
Returns:this / val
- if val is zero.
divideAndRemainder
public&[]÷AndRemainder(&val)
Returns an array of two BigIntegers containing (this / val)
followed by (this % val).
Parameters:val - value by which this BigInteger is to be divided, and the
remainder computed.
Returns:an array of two BigIntegers: the quotient (this / val)
is the initial element, and the remainder (this % val)
is the final element.
- if val is zero.
public&&remainder(&val)
Returns a BigInteger whose value is (this % val).
Parameters:val - value by which this BigInteger is to be divided, and the
remainder computed.
Returns:this % val
- if val is zero.
public&&pow(int&exponent)
Returns a BigInteger whose value is (thisexponent).
Note that exponent is an integer rather than a BigInteger.
Parameters:exponent - exponent to which this BigInteger is to be raised.
Returns:thisexponent
- exponent is negative.
(This would
cause the operation to yield a non-integer value.)
public&&gcd(&val)
Returns a BigInteger whose value is the greatest common divisor of
abs(this) and abs(val).
Returns 0 if
this==0 && val==0.
Parameters:val - value with which the GCD is to be computed.
Returns:GCD(abs(this), abs(val))
public&&abs()
Returns a BigInteger whose value is the absolute value of this
BigInteger.
Returns:abs(this)
public&&negate()
Returns a BigInteger whose value is (-this).
Returns:-this
public&int&signum()
Returns the signum function of this BigInteger.
Returns:-1, 0 or 1 as the value of this BigInteger is negative, zero or
public&&mod(&m)
Returns a BigInteger whose value is (this mod m).
This method
differs from remainder in that it always returns a
non-negative BigInteger.
Parameters:m - the modulus.
Returns:this mod m
- m & 0See Also:
public&&modPow(&exponent,
Returns a BigInteger whose value is
(thisexponent mod m).
(Unlike pow, this
method permits negative exponents.)
Parameters:exponent - the exponent.m - the modulus.
Returns:thisexponent mod m
- m & 0 or the exponent is
negative and this BigInteger is not relatively
prime to m.See Also:
modInverse
public&&modInverse(&m)
Returns a BigInteger whose value is (this-1 mod m).
Parameters:m - the modulus.
Returns:this-1 mod m.
- m & 0, or this BigInteger
has no multiplicative inverse mod m (that is, this BigInteger
is not relatively prime to m).
public&&shiftLeft(int&n)
Returns a BigInteger whose value is (this && n).
The shift distance, n, may be negative, in which case
this method performs a right shift.
(Computes floor(this * 2n).)
Parameters:n - shift distance, in bits.
Returns:this && n
- if the shift distance is Integer.MIN_VALUE.See Also:
shiftRight
public&&shiftRight(int&n)
Returns a BigInteger whose value is (this && n).
extension is performed.
The shift distance, n, may be
negative, in which case this method performs a left shift.
(Computes floor(this / 2n).)
Parameters:n - shift distance, in bits.
Returns:this && n
- if the shift distance is Integer.MIN_VALUE.See Also:
public&&and(&val)
Returns a BigInteger whose value is (this & val).
method returns a negative BigInteger if and only if this and val are
both negative.)
Parameters:val - value to be AND'ed with this BigInteger.
Returns:this & val
public&&or(&val)
Returns a BigInteger whose value is (this | val).
(This method
returns a negative BigInteger if and only if either this or val is
negative.)
Parameters:val - value to be OR'ed with this BigInteger.
Returns:this | val
public&&xor(&val)
Returns a BigInteger whose value is (this ^ val).
(This method
returns a negative BigInteger if and only if exactly one of this and
val are negative.)
Parameters:val - value to be XOR'ed with this BigInteger.
Returns:this ^ val
public&¬()
Returns a BigInteger whose value is (~this).
(This method
returns a negative value if and only if this BigInteger is
non-negative.)
Returns:~this
public&&andNot(&val)
Returns a BigInteger whose value is (this & ~val).
method, which is equivalent to and(val.not()), is provided as
a convenience for masking operations.
(This method returns a negative
BigInteger if and only if this is negative and val is
positive.)
Parameters:val - value to be complemented and AND'ed with this BigInteger.
Returns:this & ~val
public&boolean&testBit(int&n)
Returns true if and only if the designated bit is set.
(Computes ((this & (1&&n)) != 0).)
Parameters:n - index of bit to test.
Returns:true if and only if the designated bit is set.
- n is negative.
public&&setBit(int&n)
Returns a BigInteger whose value is equivalent to this BigInteger
with the designated bit set.
(Computes (this | (1&&n)).)
Parameters:n - index of bit to set.
Returns:this | (1&&n)
- n is negative.
public&&clearBit(int&n)
Returns a BigInteger whose value is equivalent to this BigInteger
with the designated bit cleared.
(Computes (this & ~(1&&n)).)
Parameters:n - index of bit to clear.
Returns:this & ~(1&&n)
- n is negative.
public&&flipBit(int&n)
Returns a BigInteger whose value is equivalent to this BigInteger
with the designated bit flipped.
(Computes (this ^ (1&&n)).)
Parameters:n - index of bit to flip.
Returns:this ^ (1&&n)
- n is negative.
getLowestSetBit
public&int&getLowestSetBit()
Returns the index of the rightmost (lowest-order) one bit in this
BigInteger (the number of zero bits to the right of the rightmost
Returns -1 if this BigInteger contains no one bits.
(Computes (this==0? -1 : log2(this & -this)).)
Returns:index of the rightmost one bit in this BigInteger.
public&int&bitLength()
Returns the number of bits in the minimal two's-complement
representation of this BigInteger, excluding a sign bit.
For positive BigIntegers, this is equivalent to the number of bits in
the ordinary binary representation.
(ceil(log2(this & 0 ? -this : this+1))).)
Returns:number of bits in the minimal two's-complement
representation of this BigInteger, excluding a sign bit.
public&int&bitCount()
Returns the number of bits in the two's complement representation
of this BigInteger that differ from its sign bit.
This method is
useful when implementing bit-vector style sets atop BigIntegers.
Returns:number of bits in the two's complement representation
of this BigInteger that differ from its sign bit.
isProbablePrime
public&boolean&isProbablePrime(int&certainty)
Returns true if this BigInteger is probably prime,
false if it's definitely composite.
certainty is & 0, true is
Parameters:certainty - a measure of the uncertainty that the caller is
willing to tolerate: if the call returns true
the probability that this BigInteger is prime exceeds
(1 - 1/2certainty).
The execution time of
this method is proportional to the value of this parameter.
Returns:true if this BigInteger is probably prime,
false if it's definitely composite.
public&int&compareTo(&val)
Compares this BigInteger with the specified BigInteger.
method is provided in preference to individual methods for each
of the six boolean comparison operators (&, ==,
&, &=, !=, &=).
The suggested
idiom for performing these comparisons is: (x.compareTo(y) &op& 0), where
&op& is one of the six comparison operators.
Specified by:
&in interface&&&
Parameters:val - BigInteger to which this BigInteger is to be compared.
Returns:-1, 0 or 1 as this BigInteger is numerically less than, equal
to, or greater than val.
public&boolean&equals(&x)
Compares this BigInteger with the specified Object for equality.
Overrides:
&in class&
Parameters:x - Object to which this BigInteger is to be compared.
Returns:true if and only if the specified Object is a
BigInteger whose value is numerically equal to this BigInteger.See Also:,
public&&min(&val)
Returns the minimum of this BigInteger and val.
Parameters:val - value with which the minimum is to be computed.
Returns:the BigInteger whose value is the lesser of this BigInteger and
If they are equal, either may be returned.
public&&max(&val)
Returns the maximum of this BigInteger and val.
Parameters:val - value with which the maximum is to be computed.
Returns:the BigInteger whose value is the greater of this and
If they are equal, either may be returned.
public&int&hashCode()
Returns the hash code for this BigInteger.
Overrides:
&in class&
Returns:hash code for this BigInteger.See Also:,
public&&toString(int&radix)
Returns the String representation of this BigInteger in the
given radix.
If the radix is outside the range from
inclusive,
it will default to 10 (as is the case for
Integer.toString).
The digit-to-character mapping
provided by Character.forDigit is used, and a minus
sign is prepended if appropriate.
(This representation is
compatible with the
constructor.)
Parameters:radix - radix of the String representation.
Returns:String representation of this BigInteger in the given radix.See Also:,
public&&toString()
Returns the decimal String representation of this BigInteger.
The digit-to-character mapping provided by
Character.forDigit is used, and a minus sign is
prepended if appropriate.
(This representation is compatible
constructor, and
allows for String concatenation with Java's + operator.)
Overrides:
&in class&
Returns:decimal String representation of this BigInteger.See Also:,
toByteArray
public&byte[]&toByteArray()
Returns a byte array containing the two's-complement
representation of this BigInteger.
The byte array will be in
big-endian byte-order: the most significant byte is in
the zeroth element.
The array will contain the minimum number
of bytes required to represent this BigInteger, including at
least one sign bit, which is (ceil((this.bitLength() +
(This representation is compatible with the
constructor.)
Returns:a byte array containing the two's-complement representation of
this BigInteger.See Also:
public&int&intValue()
Converts this BigInteger to an int.
conversion is analogous to a
narrowing primitive conversion from long to
int as defined in section 5.1.3 of
The Java& Language Specification:
if this BigInteger is too big to fit in an
int, only the low-order 32 bits are returned.
Note that this conversion can lose information about the
overall magnitude of the BigInteger value as well as return a
result with the opposite sign.
Specified by:
&in class&
Returns:this BigInteger converted to an int.
public&long&longValue()
Converts this BigInteger to a long.
conversion is analogous to a
narrowing primitive conversion from long to
int as defined in section 5.1.3 of
The Java& Language Specification:
if this BigInteger is too big to fit in a
long, only the low-order 64 bits are returned.
Note that this conversion can lose information about the
overall magnitude of the BigInteger value as well as return a
result with the opposite sign.
Specified by:
&in class&
Returns:this BigInteger converted to a long.
floatValue
public&float&floatValue()
Converts this BigInteger to a float.
conversion is similar to the
narrowing primitive conversion from double to
float as defined in section 5.1.3 of
The Java& Language Specification:
if this BigInteger has too great a magnitude
to represent as a float, it will be converted to
as appropriate.
Note that even when
the return value is finite, this conversion can lose
information about the precision of the BigInteger value.
Specified by:
&in class&
Returns:this BigInteger converted to a float.
doubleValue
public&double&doubleValue()
Converts this BigInteger to a double.
conversion is similar to the
narrowing primitive conversion from double to
float as defined in section 5.1.3 of
The Java& Language Specification:
if this BigInteger has too great a magnitude
to represent as a double, it will be converted to
as appropriate.
Note that even when
the return value is finite, this conversion can lose
information about the precision of the BigInteger value.
Specified by:
&in class&
Returns:this BigInteger converted to a double.
For further API reference and developer documentation, see . That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
© , Oracle and/or its affiliates.
All rights reserved. Use is subject to . Also see the .
Scripting on this page tracks web page traffic, but does not change the content in any way.

参考资料

 

随机推荐