go to previous page   go to home page   go to next page highlighting

Answer:

What would you do if you need to raise an integer to a non-integer power?

If you are dealing with non-integer powers, you should use double precision variables and the pow() method from Java.lang.Math .


Other Methods

Here are some additional methods of the BigInteger class. See its documentation for details. The exercises discuss some of them.

public BigInteger abs()

Returns a BigInteger whose values is the absolute value of this BigInteger.

public int bitLength()

Returns the smallest number of bits it would take to represent this BigInteger using two's complement, excluding the sign bit. For positive integers this is the number of bits it would take to represent the integer using the same type of representation as used in ints.

public double doubleValue()

Returns the value of this BigInteger as a double. The result may not be exact. It the BigInteger is too big or too negative the value of the double will be set to a special value, Double.NEGATIVE_INFINITY or Double.POSITIVE_INFINITY.

public BigInteger gcd(BigInteger val)

Returns the value of the greatest common divisor of this BigInteger and val. The gcd is always zero or positive. It is zero when either of the arguments is zero.

public int intValue()

Returns the value of this BigInteger as an int. If the value is too big, the least-significant 32 bits are returned. No error indication is given if this happens, so be careful.

public long longValue()

Returns the value of this BigInteger as an int. If the value is too big, the least-significant 64 bits are returned. No error indication is given if this happens, so be careful.

public BigInteger mod(BigInteger modulus)

Returns a BigInteger whose value is (this mod m). This is different than remainder because mod always returns a zero or positive BigInteger. remainder() returns a value that is sometimes negative. The value returned by mod() and remainder() is the same if the operands are positive.

public static BigInteger valueOf(long val)

Returns a BigInteger whose value the same as val. This may be more convenient than using a constructor.

In addition to the above, there are bit-manipulation methods, shift right and shift left, and methods that return integers that are likely to be prime.


QUESTION 24:

How can an integer only be a "likely prime" ?


go to previous page   go to home page   go to next page