Package it.unich.jgmp
Class MPF
java.lang.Object
java.lang.Number
it.unich.jgmp.MPF
- All Implemented Interfaces:
Serializable
,Comparable<MPF>
Multi-precision floating point numbers. This class encapsulates the
mpf_t
data type, see the
Floating-point Functions page of the GMP manual. In determining
the names and signatures of the methods of the MPF
class, we adopt
the rules described in the documentation of the it.unich.jgmp
package, enriched with the following ones:
- the function
mpf_set_prec_raw
is not exposed by theMPF
class; - the functions in the "I/O of Floats" category are not exposed by
the
MPF
class.
Every method which returns a new MPF
, use the default precision set
by the setDefaultPrec(long)
method, with the excpetion of the init2(long)
method where precision is specificied explicitly.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Cleaning action for theMPF
class. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate MpfT
The pointer to the nativempf_t
object.private static final long
Version for serializability. -
Constructor Summary
ConstructorsModifierConstructorDescriptionMPF()
Build anMPF
whose value is zero.MPF
(double op) Build anMPF
whose value isop
, possibly truncated to the default precision.MPF
(long op) Build anMPF
whose value isop
, possibly truncated to the default precision.Build anMPF
whose value isop
, possibly truncated to the default precision.Build anMPF
whose value isop
, possibly truncated to the default precision.Build anMPF
whose value isop
, possibly truncated to the default precision.private
A private constructor which build anMPF
starting from a pointer to its native data object.Build anMPF
whose value is the number represented by the stringstr
in decimal base, possibly truncated to the default precision.Build anMPF
whose value is the number represented by the stringstr
in the specifiedbase
, possibly truncated to the default precision.MPF
(BigDecimal op) Builds anMPF
whose value is the same asop
. -
Method Summary
Modifier and TypeMethodDescriptionabs()
Return anMPF
whose value is the absolute value ofthis
.Set thisMPF
to its absolute value.Set thisMPF
to the absolute value ofop
.Return anMPF
whose value is(this + op)
.Set thisMPF
to(this + op)
Set thisMPF
to(op1 + op2)
.addUi
(long op) Return anMPF
whose value is(this + op)
.addUiAssign
(long op) Set thisMPF
to(this + op)
addUiAssign
(MPF op1, long op2) Set thisMPF
to(op1 + op2)
.ceil()
Return anMPF
whose value isthis
rounded to the next higher integer.Set thisMPF
to its value rounded to the next higher integer.ceilAssign
(MPF op) Set thisMPF
to the value ofop
rounded to the next higher integer.int
cmp
(double op) Comparethis
withop
.int
cmp
(long op) Comparethis
withop
.int
Comparethis
withop
.int
Comparethis
withop
.int
cmpUi
(long op) Comparethis
withop
.int
Compare thisMPF
withop
.Return anMPF
whose value is(this / op)
.div2Exp
(long b) Return anMPF
whose value is(this * 2b)
.div2ExpAssign
(long b) Set thisMPF
to(this / 2b)
.div2ExpAssign
(MPF op, long b) Set thisMPF
to(op / 2b)
.Set thisMPF
to(this / op)
Set thisMPF
to(op1 / op2)
.divUi
(long op) Return anMPF
whose value is(this / op)
.divUiAssign
(long op) Set thisMPF
to(this / op)
divUiAssign
(MPF op1, long op2) Set thisMPF
to(op1 / op2)
.double
Convert thisMPF
to a double, truncating if necessary.boolean
Compare thisMPF
with the objectop
for equality.boolean
fitsSint()
Returntrue
if and only if thisMPF
fits into a native signed int.boolean
Returntrue
if and only if thisMPF
fits into a native signed long.boolean
Returntrue
if and only if thisMPF
fits into a native signed short.boolean
fitsUint()
Returntrue
if and only if thisMPF
fits into a native unsigned int.boolean
Returntrue
if and only if thisMPF
fits into a native unsigned long.boolean
Returntrue
if and only if thisMPF
fits into a native unsigned short.float
Convert thisMPF
to a float, truncating if necessary.floor()
Return anMPF
whose value isthis
rounded to the next lower integer.Set thisMPF
to its value rounded to the next lower integer.floorAssign
(MPF op) Set thisMPF
to the value ofop
rounded to the next lower integer.Convertthis
to aBigDecimal
.double
getD()
Convert thisMPF
to a double, truncating if necessary.getD2Exp()
Convert thisMPF
to a pair made of mantissa and exponent, truncating if necessary.static long
Return the default precision actually used.Return the native pointer to the GMP object.long
getPrec()
Return the current precision of thisMPF
, in bits.long
getSi()
Convert thisMPF
to a long, truncating any fraction part.getStr
(int base, long nDigits) Return the String representation of thisMPF
in the specifiedbase
, ornull
if the base is not valid.long
getUi()
Convert thisMPF
to an unsigned long, truncating any fraction part.int
hashCode()
Return a hash code value for thisMPF
.static MPF
init()
Return anMPF
whose value is zero.static MPF
init2
(long prec) Return anMPF
whose value is zero, and set its precision to be at leastprec
bits.static MPF
initSet
(double op) Return anMPF
whose value isop
, possibly truncated to the default precision.static MPF
initSet
(long op) Return anMPF
whose value isop
, possibly truncated to the default precision.static MPF
Return anMPF
whose value isop
, possibly truncated to the default precision.Return anMPF
whose value is the number represented by the stringstr
in the specifiedbase
, possibly truncated to the default precision.static MPF
initSetUi
(long op) Return anMPF
whose value isop
, possibly truncated to the default precision.int
intValue()
Convert thisMPF
to anint
.boolean
Return whether thisMPF
is an integer.boolean
isZero()
Return true if and only if thisthis
MPF is zero.long
Convert thisMPF
to along
, truncating any fraction part.Return anMPF
whose value is(this * op)
.mul2Exp
(long b) Return anMPF
whose value is(this * 2b)
.mul2ExpAssign
(long b) Set thisMPF
to(this * 2b)
.mul2ExpAssign
(MPF op, long b) Set thisMPF
to(op * 2b)
.Set thisMPF
to(this * op)
Set thisMPF
to(op1 * op2)
.mulUi
(long op) Return anMPF
whose value is(this * op)
.mulUiAssign
(long op) Set thisMPF
to(this * op)
mulUiAssign
(MPF op1, long op2) Set thisMPF
to(op1 * op2)
.neg()
Return anMPF
whose value is(- this)
.Set thisMPF
to its opposite.Set thisMPF
to(- op)
.powUi
(long exp) Return anMPF
whose value is(thisexp)
.powUiAssign
(long exp) Set thisMPF
to(thisexp)
.powUiAssign
(MPF base, long exp) Set thisMPF
to(baseexp)
.static MPF
random2
(long maxSize, long exp) Return anMPF
whose value is a random integer of at mostmaxSize
limbs, with long strings of zeros and ones in the binary representation.random2Assign
(long maxSize, long exp) Set thisMPF
to a random integer of at mostmaxSize
limbs, with long strings of zeros and ones in the binary representation.private void
private void
Return the relative difference betweenthis
andthis
, i.e.,(abs(this-op)/this)
.reldiffAssign
(MPF op) Set thisMPF
to the relative difference betweenthis
andop
, i.e.,(abs(this-op)/this)
.reldiffAssign
(MPF op1, MPF op2) Set thisMPF
to the relative difference betweenop1
andop2
, i.e.,(abs(op1-op2)/op1)
.set
(double op) Set thisMPF
toop
, possibly truncated according to precision.set
(long op) Set thisMPF
toop
, possibly truncated according to precision.Set thisMPF
toop
, possibly truncated according to precision.Set thisMPF
toop
, possibly truncated according to precision.Set thisMPF
toop
, possibly truncated according to precision.int
Set thisMPF
to the number represented by the stringstr
in the specifiedbase
, possibly truncated according to precision.set
(BigDecimal op) Set thisMPF
to the big decimalop
.static void
setDefaultPrec
(long prec) Set the default precision to be at leastprec
bits.setPrec
(long prec) Set the precision of thisMPF
to be at leastprec
bits.setUi
(long op) Set thisMPF
toop
, possibly truncated according to precision.setValue
(double op) Set thisMPF
toop
, possibly truncated according to precision.setValue
(long op) Set thisMPF
toop
, possibly truncated according to precision.Set thisMPF
toop
, possibly truncated according to precision.Set thisMPF
toop
, possibly truncated according to precision.Set thisMPF
toop
, possibly truncated according to precision.Set thisMPF
to the value represented by the stringstr
in decimal base, possibly truncated according to precision.Set thisMPF
to the number represented by the stringstr
in the specifiedbase
, possibly truncated according to precision.setValue
(BigDecimal op) Set thisMPF
to the big decimalop
.int
sgn()
Return+1
if(this > 0)
,0
if(this = 0)
and-1
if(this < 0)
.sqrt()
Return anMPF
whose value is the square root ofthis
.Set thisMPF
to its square root.sqrtAssign
(MPF op) Set thisMPF
to the the square root ofop
.static MPF
sqrtUi
(long op) Return anMPF
whose value is the square root ofthis
.sqrtUiAssign
(long op) Set thisMPF
to the the square root ofop
.Return anMPF
whose value is(this - op)
.Set thisMPF
to(this - op)
Set thisMPF
to(op1 - op2)
.subUi
(long op) Return anMPF
whose value is(this - op)
.subUiAssign
(long op) Set thisMPF
to(this - op)
subUiAssign
(MPF op1, long op2) Set thisMPF
to(op1 - op2)
.Swap the value of thisMPF
with the value ofop
.toString()
Convert thisMPF
to its decimal string representation.toString
(int base) Convert thisMPF
to its string representation in the specifiedbase
, ornull
if the base is not valid.toString
(int base, long nDigits) Convert thisMPF
to its string representation in the specifiedbase
, ornull
if the base is not valid.trunc()
Return anMPF
whose value isthis
rounded towards zero.Set thisMPF
to its value rounded towards zero.truncAssign
(MPF op) Set thisMPF
to the value ofop
rounded towards zero.uiDiv
(long op) Return anMPF
whose value is(op / this)
.uiDivAssign
(long op) Set thisMPF
to(op / this)
uiDivAssign
(long op1, MPF op2) Set thisMPF
to(op1 / op2)
.uiSub
(long op) Return anMPF
whose value is(op - this)
.uiSubAssign
(long op) Set thisMPF
to(op - this)
uiSubAssign
(long op1, MPF op2) Set thisMPF
to(op1 - op2)
.static MPF
Return anMPF
whose value is an uniformly distributed random float in the range from0
included to1
excluded.urandombAssign
(RandState s, long nbits) Set thisMPF
to a uniformly distributed random float in the range from0
included to1
excluded.private void
Methods inherited from class java.lang.Number
byteValue, shortValue
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDVersion for serializability.- See Also:
-
mpfNative
The pointer to the nativempf_t
object.
-
-
Constructor Details
-
MPF
A private constructor which build anMPF
starting from a pointer to its native data object. The native object needs to be already initialized. -
MPF
public MPF()Build anMPF
whose value is zero. -
MPF
Build anMPF
whose value isop
, possibly truncated to the default precision. -
MPF
public MPF(long op) Build anMPF
whose value isop
, possibly truncated to the default precision. -
MPF
public MPF(double op) Build anMPF
whose value isop
, possibly truncated to the default precision.- Throws:
ArithmeticException
- ifop
is not a finite number.
-
MPF
Build anMPF
whose value isop
, possibly truncated to the default precision. -
MPF
Build anMPF
whose value isop
, possibly truncated to the default precision. -
MPF
Build anMPF
whose value is the number represented by the stringstr
in the specifiedbase
, possibly truncated to the default precision. See the GMP functionmpf_init_set_str
.- Throws:
NumberFormatException
- if eitherbase
is not valid orstr
is not a valid string in the specifiedbase
.
-
MPF
Build anMPF
whose value is the number represented by the stringstr
in decimal base, possibly truncated to the default precision. See the GMP functionmpf_init_set_str
.- Throws:
NumberFormatException
- ifstr
is not a valid number representation in decimal base.
-
MPF
Builds anMPF
whose value is the same asop
. Note that, sinceBigDecimal
represents number in thedecimal base whileMPF
use the binary base, rounding is possible.
-
-
Method Details
-
getNative
Return the native pointer to the GMP object. -
setDefaultPrec
public static void setDefaultPrec(long prec) Set the default precision to be at leastprec
bits. Previously initialized variables are unaffected. -
getDefaultPrec
public static long getDefaultPrec()Return the default precision actually used. -
init
Return anMPF
whose value is zero. The precision of the result will be taken from the active default precision, as set bysetDefaultPrec(long)
. -
init2
Return anMPF
whose value is zero, and set its precision to be at leastprec
bits. -
getPrec
public long getPrec()Return the current precision of thisMPF
, in bits. -
setPrec
Set the precision of thisMPF
to be at leastprec
bits. The value will be truncated to the new precision. This function requires a reallocation, and should not be used in a tight loop.- Returns:
- this
MPF
-
set
Set thisMPF
toop
, possibly truncated according to precision.- Returns:
- this
MPF
.
-
set
Set thisMPF
toop
, possibly truncated according to precision.- Returns:
- this
MPF
.
-
setUi
Set thisMPF
toop
, possibly truncated according to precision.- Returns:
- this
MPF
.
-
set
Set thisMPF
toop
, possibly truncated according to precision.- Returns:
- this
MPF
. - Throws:
ArithmeticException
- ifop
is not a finite number. In this case,this
is not altered.
-
set
Set thisMPF
toop
, possibly truncated according to precision.- Returns:
- this
MPF
.
-
set
Set thisMPF
toop
, possibly truncated according to precision.- Returns:
- this
MPF
.
-
set
Set thisMPF
to the number represented by the stringstr
in the specifiedbase
, possibly truncated according to precision. See the GMP functionmpf_set_str
. The decimal point character is taken from the current system locale, which may be different from the Java locale.- Returns:
- 0 if the operation succeeded, -1 otherwise. In the latter case,
this
is not altered.
-
set
Set thisMPF
to the big decimalop
. Note that, sinceBigDecimal
represents number in thedecimal base whileMPF
use the binary base, rounding is possible.- Returns:
- this
MPF
.
-
swap
Swap the value of thisMPF
with the value ofop
. Both the value and the precision of the two objects are swapped.- Returns:
- this
MPF
.
-
initSet
Return anMPF
whose value isop
, possibly truncated to the default precision.- Throws:
ArithmeticException
- ifop
is not a finite number. In this case,this
is not altered.
-
initSetUi
Return anMPF
whose value isop
, possibly truncated to the default precision. -
initSet
Return anMPF
whose value isop
, possibly truncated to the default precision. -
initSet
Return anMPF
whose value isop
, possibly truncated to the default precision.- Throws:
ArithmeticException
- ifop
is not a finite number.
-
initSet
Return anMPF
whose value is the number represented by the stringstr
in the specifiedbase
, possibly truncated to the default precision. See the GMP functionmpf_init_set_str
. The decimal point character is taken from the current system locale, which may be different from the Java locale.- Returns:
- a pair whose first component is
0
if the operation succeeded, and-1
if eitherbase
is not valid, orstr
is not a valid numeric representation in the specified base. The second component of the pair is the number represented instr
if the operation succeeded,0
otherwise.
-
getD
public double getD()Convert thisMPF
to a double, truncating if necessary. If the exponent from the conversion is too big or too small, the result is system dependent. For too big an infinity is returned when available. For too small 0.0 is normally returned. Hardware overflow, underflow and denorm traps may or may not occur. -
getD2Exp
Convert thisMPF
to a pair made of mantissa and exponent, truncating if necessary. See the GMP functionmpf_get_d_2exp
. -
getUi
public long getUi()Convert thisMPF
to an unsigned long, truncating any fraction part. If this number is too big to fit an unsigned long, the result is undefined. -
getSi
public long getSi()Convert thisMPF
to a long, truncating any fraction part. If this number is too big to fit a long, the result is undefined. -
getStr
Return the String representation of thisMPF
in the specifiedbase
, ornull
if the base is not valid. See the GMP functionmpf_get_str
. -
getBigDecimal
Convertthis
to aBigDecimal
. -
addAssign
Set thisMPF
to(op1 + op2)
.- Returns:
- this
MPF
.
-
addAssign
Set thisMPF
to(this + op)
- Returns:
- this
MPF
-
add
Return anMPF
whose value is(this + op)
. -
addUiAssign
Set thisMPF
to(op1 + op2)
.- Returns:
- this
MPF
.
-
addUiAssign
Set thisMPF
to(this + op)
- Returns:
- this
MPF
-
addUi
Return anMPF
whose value is(this + op)
. -
subAssign
Set thisMPF
to(op1 - op2)
.- Returns:
- this
MPF
.
-
subAssign
Set thisMPF
to(this - op)
- Returns:
- this
MPF
-
sub
Return anMPF
whose value is(this - op)
. -
subUiAssign
Set thisMPF
to(op1 - op2)
.- Returns:
- this
MPF
.
-
subUiAssign
Set thisMPF
to(this - op)
- Returns:
- this
MPF
-
subUi
Return anMPF
whose value is(this - op)
. -
uiSubAssign
Set thisMPF
to(op1 - op2)
.- Returns:
- this
MPF
.
-
uiSubAssign
Set thisMPF
to(op - this)
- Returns:
- this
MPF
-
uiSub
Return anMPF
whose value is(op - this)
. -
mulAssign
Set thisMPF
to(op1 * op2)
.- Returns:
- this
MPF
.
-
mulAssign
Set thisMPF
to(this * op)
- Returns:
- this
MPF
-
mul
Return anMPF
whose value is(this * op)
. -
mulUiAssign
Set thisMPF
to(op1 * op2)
.- Returns:
- this
MPF
.
-
mulUiAssign
Set thisMPF
to(this * op)
- Returns:
- this
MPF
-
mulUi
Return anMPF
whose value is(this * op)
. -
divAssign
Set thisMPF
to(op1 / op2)
.- Returns:
- this
MPF
. - Throws:
ArithmeticException
- ifop2
is zero.
-
divAssign
Set thisMPF
to(this / op)
- Returns:
- this
MPF
- Throws:
ArithmeticException
- ifop
is zero.
-
div
Return anMPF
whose value is(this / op)
.- Throws:
ArithmeticException
- ifop
is zero.
-
divUiAssign
Set thisMPF
to(op1 / op2)
.- Returns:
- this
MPF
. - Throws:
ArithmeticException
- ifop2
is zero.
-
divUiAssign
Set thisMPF
to(this / op)
- Returns:
- this
MPF
- Throws:
ArithmeticException
- ifop
is zero.
-
divUi
Return anMPF
whose value is(this / op)
.- Throws:
ArithmeticException
- ifop
is zero.
-
uiDivAssign
Set thisMPF
to(op1 / op2)
.- Returns:
- this
MPF
. - Throws:
ArithmeticException
- ifop2
is zero.
-
uiDivAssign
Set thisMPF
to(op / this)
- Returns:
- this
MPF
- Throws:
ArithmeticException
- ifthis
is zero.
-
uiDiv
Return anMPF
whose value is(op / this)
.- Throws:
ArithmeticException
- ifthis
is zero.
-
sqrtAssign
Set thisMPF
to the the square root ofop
.- Returns:
- this
MPF
.
-
sqrtAssign
Set thisMPF
to its square root.- Returns:
- this
MPF
.
-
sqrt
Return anMPF
whose value is the square root ofthis
. -
sqrtUiAssign
Set thisMPF
to the the square root ofop
.- Returns:
- this
MPF
.
-
sqrtUi
Return anMPF
whose value is the square root ofthis
. -
powUiAssign
Set thisMPF
to(baseexp)
. The case00
yields1
.- Returns:
- this
MPF
.
-
powUiAssign
Set thisMPF
to(thisexp)
. The case00
yields1
.- Returns:
- this
MPF
.
-
powUi
Return anMPF
whose value is(thisexp)
. The case00
yields1
. -
negAssign
Set thisMPF
to(- op)
.- Returns:
- this
MPF
.
-
negAssign
Set thisMPF
to its opposite.- Returns:
- this
MPF
.
-
neg
Return anMPF
whose value is(- this)
. -
absAssign
Set thisMPF
to the absolute value ofop
.- Returns:
- this
MPF
.
-
absAssign
Set thisMPF
to its absolute value.- Returns:
- this
MPF
.
-
abs
Return anMPF
whose value is the absolute value ofthis
. -
mul2ExpAssign
Set thisMPF
to(op * 2b)
.- Returns:
- this
MPF
.
-
mul2ExpAssign
Set thisMPF
to(this * 2b)
.- Returns:
- this
MPF
.
-
mul2Exp
Return anMPF
whose value is(this * 2b)
. -
div2ExpAssign
Set thisMPF
to(op / 2b)
.- Returns:
- this
MPF
.
-
div2ExpAssign
Set thisMPF
to(this / 2b)
.- Returns:
- this
MPF
.
-
div2Exp
Return anMPF
whose value is(this * 2b)
. -
cmp
Comparethis
withop
. Return a positive value if(this > op)
, zero if(this = op)
, or a negative value if(this < op)
. -
cmp
Comparethis
withop
. Return a positive value if(this > op)
, zero if(this = op)
, or a negative value if(this < op)
. The value ofop
may be infinite, but the result is undefined on NaNs. -
cmp
public int cmp(double op) Comparethis
withop
. Return a positive value if(this > op)
, zero if(this = op)
, or a negative value if(this < op)
. The value ofop
may be infinite, but the result is undefined on NaNs.- Throws:
ArithmeticException
- ifop
is a NaN.
-
cmp
public int cmp(long op) Comparethis
withop
. Return a positive value if(this > op)
, zero if(this = op)
, or a negative value if(this < op)
. -
cmpUi
public int cmpUi(long op) Comparethis
withop
. Return a positive value if(this > op)
, zero if(this = op)
, or a negative value if(this < op)
. -
reldiffAssign
Set thisMPF
to the relative difference betweenop1
andop2
, i.e.,(abs(op1-op2)/op1)
.- Returns:
- this
MPF
.
-
reldiffAssign
Set thisMPF
to the relative difference betweenthis
andop
, i.e.,(abs(this-op)/this)
.- Returns:
- this
MPF
.
-
reldiff
Return the relative difference betweenthis
andthis
, i.e.,(abs(this-op)/this)
. -
sgn
public int sgn()Return+1
if(this > 0)
,0
if(this = 0)
and-1
if(this < 0)
. -
ceilAssign
Set thisMPF
to the value ofop
rounded to the next higher integer.- Returns:
- this
MPF
.
-
ceilAssign
Set thisMPF
to its value rounded to the next higher integer.- Returns:
- this
MPF
.
-
ceil
Return anMPF
whose value isthis
rounded to the next higher integer. -
floorAssign
Set thisMPF
to the value ofop
rounded to the next lower integer.- Returns:
- this
MPF
.
-
floorAssign
Set thisMPF
to its value rounded to the next lower integer.- Returns:
- this
MPF
.
-
floor
Return anMPF
whose value isthis
rounded to the next lower integer. -
truncAssign
Set thisMPF
to the value ofop
rounded towards zero.- Returns:
- this
MPF
.
-
truncAssign
Set thisMPF
to its value rounded towards zero.- Returns:
- this
MPF
.
-
trunc
Return anMPF
whose value isthis
rounded towards zero. -
isInteger
public boolean isInteger()Return whether thisMPF
is an integer. -
fitsUlong
public boolean fitsUlong()Returntrue
if and only if thisMPF
fits into a native unsigned long. -
fitsSlong
public boolean fitsSlong()Returntrue
if and only if thisMPF
fits into a native signed long. -
fitsUint
public boolean fitsUint()Returntrue
if and only if thisMPF
fits into a native unsigned int. -
fitsSint
public boolean fitsSint()Returntrue
if and only if thisMPF
fits into a native signed int. -
fitsUshort
public boolean fitsUshort()Returntrue
if and only if thisMPF
fits into a native unsigned short. -
fitsSshort
public boolean fitsSshort()Returntrue
if and only if thisMPF
fits into a native signed short. -
isZero
public boolean isZero()Return true if and only if thisthis
MPF is zero. -
urandombAssign
Set thisMPF
to a uniformly distributed random float in the range from0
included to1
excluded. The result hasnbits
significant bits in the mantissa, or less if the precision of thisMPF
is smaller. -
urandomb
Return anMPF
whose value is an uniformly distributed random float in the range from0
included to1
excluded. The result hasnbits
significant bits in the mantissa, or less if the default precision is smaller. -
random2Assign
Set thisMPF
to a random integer of at mostmaxSize
limbs, with long strings of zeros and ones in the binary representation. The exponent of the number is in the interval-exp
toexp
(in limbs). This function is useful for testing functions and algorithms, since these kind of random numbers have proven to be more likely to trigger corner-case bugs. Negative random numbers are generated whenmaxSize
is negative.- Returns:
- this
MPF
.
-
random2
Return anMPF
whose value is a random integer of at mostmaxSize
limbs, with long strings of zeros and ones in the binary representation. The exponent of the number is in the interval-exp
toexp
(in limbs). This function is useful for testing functions and algorithms, since these kind of random numbers have proven to be more likely to trigger corner-case bugs. Negative random numbers are generated whenmaxSize
is negative. -
setValue
Set thisMPF
toop
, possibly truncated according to precision.- Returns:
- this
MPF
.
-
setValue
Set thisMPF
toop
, possibly truncated according to precision.- Returns:
- this
MPF
.
-
setValue
Set thisMPF
toop
, possibly truncated according to precision.- Returns:
- this
MPF
. - Throws:
ArithmeticException
- ifop
is not a finite number. In this case,this
is not altered.
-
setValue
Set thisMPF
toop
, possibly truncated according to precision.- Returns:
- this
MPF
.
-
setValue
Set thisMPF
toop
, possibly truncated according to precision.- Returns:
- this
MPF
.
-
setValue
Set thisMPF
to the number represented by the stringstr
in the specifiedbase
, possibly truncated according to precision. See the GMP functionmpf_set_str
. The decimal point character is taken from the current system locale, which may be different from the Java locale.- Throws:
ArithmeticException
- if eitherbase
is not valid orstr
is not a valid number representation in the specified base. In this case,this
is not altered.
-
setValue
Set thisMPF
to the value represented by the stringstr
in decimal base, possibly truncated according to precision. The decimal point character is taken from the current system locale, which may be different from the Java locale.- Throws:
ArithmeticException
- ifstr
is not a valid number representation in decimal base.- See Also:
-
setValue
Set thisMPF
to the big decimalop
. Note that, sinceBigDecimal
represents number in thedecimal base whileMPF
use the binary base, rounding is possible.- Returns:
- this
MPF
.
-
compareTo
Compare thisMPF
withop
. Return a positive value if(this > op)
, zero if(this = op)
, or a negative value if(this < op)
. This order is compatible with equality.- Specified by:
compareTo
in interfaceComparable<MPF>
-
equals
Compare thisMPF
with the objectop
for equality. It returnstrue
if and only ifop
is anMPF
with the same value ofthis
. -
hashCode
public int hashCode()Return a hash code value for thisMPF
. -
longValue
public long longValue()Convert thisMPF
to along
, truncating any fraction part. If this number is too big to fit along
, the result is undefined. -
intValue
public int intValue()Convert thisMPF
to anint
. -
doubleValue
public double doubleValue()Convert thisMPF
to a double, truncating if necessary. If the exponent from the conversion is too big or too small to fit a double then the result is system dependent. For too big an infinity is returned when available. For too small 0.0 is normally returned. Hardware overflow, underflow and denorm traps may or may not occur.- Specified by:
doubleValue
in classNumber
-
floatValue
public float floatValue()Convert thisMPF
to a float, truncating if necessary.- Specified by:
floatValue
in classNumber
-
toString
Convert thisMPF
to its string representation in the specifiedbase
, ornull
if the base is not valid. See the GMP functionmpf_get_str
.- Throws:
IllegalArgumentException
- if the base is not valid.
-
toString
Convert thisMPF
to its string representation in the specifiedbase
, ornull
if the base is not valid. See the GMP functionmpf_get_str
. -
toString
Convert thisMPF
to its decimal string representation. -
writeObject
- Throws:
IOException
-
readObject
- Throws:
IOException
ClassNotFoundException
-
readObjectNoData
- Throws:
ObjectStreamException
-