Package it.unich.jgmp
Class MPF
- java.lang.Object
-
- java.lang.Number
-
- it.unich.jgmp.MPF
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<MPF>
public class MPF extends java.lang.Number implements java.lang.Comparable<MPF>
Multi-precision floating point numbers. This class encapsulates thempf_t
data type, see the Floating-point Functions page of the GMP manual. In determining the names and signatures of the methods of theMPF
class, we adopt the rules described in the documentation of theit.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 thesetDefaultPrec(long)
method, with the excpetion of theinit2(long)
method where precision is specificied explicitly.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
MPF.MPFCleaner
Cleaning action for theMPF
class.
-
Field Summary
Fields Modifier and Type Field Description private MpfT
mpfNative
The pointer to the nativempf_t
object.private static long
serialVersionUID
Version for serializability.
-
Constructor Summary
Constructors Modifier Constructor Description MPF()
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.MPF(MPF op)
Build anMPF
whose value isop
, possibly truncated to the default precision.MPF(MPQ op)
Build anMPF
whose value isop
, possibly truncated to the default precision.MPF(MPZ op)
Build anMPF
whose value isop
, possibly truncated to the default precision.private
MPF(MpfT pointer)
A private constructor which build anMPF
starting from a pointer to its native data object.MPF(java.lang.String str)
Build anMPF
whose value is the number represented by the stringstr
in decimal base, possibly truncated to the default precision.MPF(java.lang.String str, int base)
Build anMPF
whose value is the number represented by the stringstr
in the specifiedbase
, possibly truncated to the default precision.MPF(java.math.BigDecimal op)
Builds anMPF
whose value is the same asop
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MPF
abs()
Return anMPF
whose value is the absolute value ofthis
.MPF
absAssign()
Set thisMPF
to its absolute value.MPF
absAssign(MPF op)
Set thisMPF
to the absolute value ofop
.MPF
add(MPF op)
Return anMPF
whose value is(this + op)
.MPF
addAssign(MPF op)
Set thisMPF
to(this + op)
MPF
addAssign(MPF op1, MPF op2)
Set thisMPF
to(op1 + op2)
.MPF
addUi(long op)
Return anMPF
whose value is(this + op)
.MPF
addUiAssign(long op)
Set thisMPF
to(this + op)
MPF
addUiAssign(MPF op1, long op2)
Set thisMPF
to(op1 + op2)
.MPF
ceil()
Return anMPF
whose value isthis
rounded to the next higher integer.MPF
ceilAssign()
Set thisMPF
to its value rounded to the next higher integer.MPF
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
cmp(MPF op)
Comparethis
withop
.int
cmp(MPZ op)
Comparethis
withop
.int
cmpUi(long op)
Comparethis
withop
.int
compareTo(MPF op)
Compare thisMPF
withop
.MPF
div(MPF op)
Return anMPF
whose value is(this / op)
.MPF
div2Exp(long b)
Return anMPF
whose value is(this * 2b)
.MPF
div2ExpAssign(long b)
Set thisMPF
to(this / 2b)
.MPF
div2ExpAssign(MPF op, long b)
Set thisMPF
to(op / 2b)
.MPF
divAssign(MPF op)
Set thisMPF
to(this / op)
MPF
divAssign(MPF op1, MPF op2)
Set thisMPF
to(op1 / op2)
.MPF
divUi(long op)
Return anMPF
whose value is(this / op)
.MPF
divUiAssign(long op)
Set thisMPF
to(this / op)
MPF
divUiAssign(MPF op1, long op2)
Set thisMPF
to(op1 / op2)
.double
doubleValue()
Convert thisMPF
to a double, truncating if necessary.boolean
equals(java.lang.Object obj)
Compare thisMPF
with the objectop
for equality.boolean
fitsSint()
Returntrue
if and only if thisMPF
fits into a native signed int.boolean
fitsSlong()
Returntrue
if and only if thisMPF
fits into a native signed long.boolean
fitsSshort()
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
fitsUlong()
Returntrue
if and only if thisMPF
fits into a native unsigned long.boolean
fitsUshort()
Returntrue
if and only if thisMPF
fits into a native unsigned short.float
floatValue()
Convert thisMPF
to a float, truncating if necessary.MPF
floor()
Return anMPF
whose value isthis
rounded to the next lower integer.MPF
floorAssign()
Set thisMPF
to its value rounded to the next lower integer.MPF
floorAssign(MPF op)
Set thisMPF
to the value ofop
rounded to the next lower integer.java.math.BigDecimal
getBigDecimal()
Convertthis
to aBigDecimal
.double
getD()
Convert thisMPF
to a double, truncating if necessary.org.javatuples.Pair<java.lang.Double,java.lang.Long>
getD2Exp()
Convert thisMPF
to a pair made of mantissa and exponent, truncating if necessary.static long
getDefaultPrec()
Return the default precision actually used.MpfT
getNative()
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.org.javatuples.Pair<java.lang.String,java.lang.Long>
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
initSet(MPF op)
Return anMPF
whose value isop
, possibly truncated to the default precision.static org.javatuples.Pair<java.lang.Integer,MPF>
initSet(java.lang.String str, int base)
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
isInteger()
Return whether thisMPF
is an integer.boolean
isZero()
Return true if and only if thisthis
MPF is zero.long
longValue()
Convert thisMPF
to along
, truncating any fraction part.MPF
mul(MPF op)
Return anMPF
whose value is(this * op)
.MPF
mul2Exp(long b)
Return anMPF
whose value is(this * 2b)
.MPF
mul2ExpAssign(long b)
Set thisMPF
to(this * 2b)
.MPF
mul2ExpAssign(MPF op, long b)
Set thisMPF
to(op * 2b)
.MPF
mulAssign(MPF op)
Set thisMPF
to(this * op)
MPF
mulAssign(MPF op1, MPF op2)
Set thisMPF
to(op1 * op2)
.MPF
mulUi(long op)
Return anMPF
whose value is(this * op)
.MPF
mulUiAssign(long op)
Set thisMPF
to(this * op)
MPF
mulUiAssign(MPF op1, long op2)
Set thisMPF
to(op1 * op2)
.MPF
neg()
Return anMPF
whose value is(- this)
.MPF
negAssign()
Set thisMPF
to its opposite.MPF
negAssign(MPF op)
Set thisMPF
to(- op)
.MPF
powUi(long exp)
Return anMPF
whose value is(thisexp)
.MPF
powUiAssign(long exp)
Set thisMPF
to(thisexp)
.MPF
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.MPF
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
readObject(java.io.ObjectInputStream in)
private void
readObjectNoData()
MPF
reldiff(MPF op)
Return the relative difference betweenthis
andthis
, i.e.,(abs(this-op)/this)
.MPF
reldiffAssign(MPF op)
Set thisMPF
to the relative difference betweenthis
andop
, i.e.,(abs(this-op)/this)
.MPF
reldiffAssign(MPF op1, MPF op2)
Set thisMPF
to the relative difference betweenop1
andop2
, i.e.,(abs(op1-op2)/op1)
.MPF
set(double op)
Set thisMPF
toop
, possibly truncated according to precision.MPF
set(long op)
Set thisMPF
toop
, possibly truncated according to precision.MPF
set(MPF op)
Set thisMPF
toop
, possibly truncated according to precision.MPF
set(MPQ op)
Set thisMPF
toop
, possibly truncated according to precision.MPF
set(MPZ op)
Set thisMPF
toop
, possibly truncated according to precision.int
set(java.lang.String str, int base)
Set thisMPF
to the number represented by the stringstr
in the specifiedbase
, possibly truncated according to precision.MPF
set(java.math.BigDecimal op)
Set thisMPF
to the big decimalop
.static void
setDefaultPrec(long prec)
Set the default precision to be at leastprec
bits.MPF
setPrec(long prec)
Set the precision of thisMPF
to be at leastprec
bits.MPF
setUi(long op)
Set thisMPF
toop
, possibly truncated according to precision.MPF
setValue(double op)
Set thisMPF
toop
, possibly truncated according to precision.MPF
setValue(long op)
Set thisMPF
toop
, possibly truncated according to precision.MPF
setValue(MPF op)
Set thisMPF
toop
, possibly truncated according to precision.MPF
setValue(MPQ op)
Set thisMPF
toop
, possibly truncated according to precision.MPF
setValue(MPZ op)
Set thisMPF
toop
, possibly truncated according to precision.MPF
setValue(java.lang.String str)
Set thisMPF
to the value represented by the stringstr
in decimal base, possibly truncated according to precision.MPF
setValue(java.lang.String str, int base)
Set thisMPF
to the number represented by the stringstr
in the specifiedbase
, possibly truncated according to precision.MPF
setValue(java.math.BigDecimal op)
Set thisMPF
to the big decimalop
.int
sgn()
Return+1
if(this > 0)
,0
if(this = 0)
and-1
if(this < 0)
.MPF
sqrt()
Return anMPF
whose value is the square root ofthis
.MPF
sqrtAssign()
Set thisMPF
to its square root.MPF
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
.MPF
sqrtUiAssign(long op)
Set thisMPF
to the the square root ofop
.MPF
sub(MPF op)
Return anMPF
whose value is(this - op)
.MPF
subAssign(MPF op)
Set thisMPF
to(this - op)
MPF
subAssign(MPF op1, MPF op2)
Set thisMPF
to(op1 - op2)
.MPF
subUi(long op)
Return anMPF
whose value is(this - op)
.MPF
subUiAssign(long op)
Set thisMPF
to(this - op)
MPF
subUiAssign(MPF op1, long op2)
Set thisMPF
to(op1 - op2)
.MPF
swap(MPF op)
Swap the value of thisMPF
with the value ofop
.java.lang.String
toString()
Convert thisMPF
to its decimal string representation.java.lang.String
toString(int base)
Convert thisMPF
to its string representation in the specifiedbase
, ornull
if the base is not valid.java.lang.String
toString(int base, long nDigits)
Convert thisMPF
to its string representation in the specifiedbase
, ornull
if the base is not valid.MPF
trunc()
Return anMPF
whose value isthis
rounded towards zero.MPF
truncAssign()
Set thisMPF
to its value rounded towards zero.MPF
truncAssign(MPF op)
Set thisMPF
to the value ofop
rounded towards zero.MPF
uiDiv(long op)
Return anMPF
whose value is(op / this)
.MPF
uiDivAssign(long op)
Set thisMPF
to(op / this)
MPF
uiDivAssign(long op1, MPF op2)
Set thisMPF
to(op1 / op2)
.MPF
uiSub(long op)
Return anMPF
whose value is(op - this)
.MPF
uiSubAssign(long op)
Set thisMPF
to(op - this)
MPF
uiSubAssign(long op1, MPF op2)
Set thisMPF
to(op1 - op2)
.static MPF
urandomb(RandState s, long nbits)
Return anMPF
whose value is an uniformly distributed random float in the range from0
included to1
excluded.MPF
urandombAssign(RandState s, long nbits)
Set thisMPF
to a uniformly distributed random float in the range from0
included to1
excluded.private void
writeObject(java.io.ObjectOutputStream out)
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Version for serializability.- See Also:
- Constant Field Values
-
mpfNative
private transient MpfT mpfNative
The pointer to the nativempf_t
object.
-
-
Constructor Detail
-
MPF
private MPF(MpfT pointer)
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
public MPF(MPF op)
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:
java.lang.ArithmeticException
- ifop
is not a finite number.
-
MPF
public MPF(MPQ op)
Build anMPF
whose value isop
, possibly truncated to the default precision.
-
MPF
public MPF(MPZ op)
Build anMPF
whose value isop
, possibly truncated to the default precision.
-
MPF
public MPF(java.lang.String str, int base)
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:
java.lang.NumberFormatException
- if eitherbase
is not valid orstr
is not a valid string in the specifiedbase
.
-
MPF
public MPF(java.lang.String str)
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:
java.lang.NumberFormatException
- ifstr
is not a valid number representation in decimal base.
-
MPF
public MPF(java.math.BigDecimal op)
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 Detail
-
getNative
public MpfT 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
public static MPF 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
public static MPF init2(long prec)
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
public MPF setPrec(long prec)
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
public MPF set(MPF op)
Set thisMPF
toop
, possibly truncated according to precision.- Returns:
- this
MPF
.
-
set
public MPF set(long op)
Set thisMPF
toop
, possibly truncated according to precision.- Returns:
- this
MPF
.
-
setUi
public MPF setUi(long op)
Set thisMPF
toop
, possibly truncated according to precision.- Returns:
- this
MPF
.
-
set
public MPF set(double op)
Set thisMPF
toop
, possibly truncated according to precision.- Returns:
- this
MPF
. - Throws:
java.lang.ArithmeticException
- ifop
is not a finite number. In this case,this
is not altered.
-
set
public MPF set(MPZ op)
Set thisMPF
toop
, possibly truncated according to precision.- Returns:
- this
MPF
.
-
set
public MPF set(MPQ op)
Set thisMPF
toop
, possibly truncated according to precision.- Returns:
- this
MPF
.
-
set
public int set(java.lang.String str, int base)
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
public MPF set(java.math.BigDecimal op)
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
public MPF swap(MPF op)
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
public static MPF initSet(MPF op)
Return anMPF
whose value isop
, possibly truncated to the default precision.- Throws:
java.lang.ArithmeticException
- ifop
is not a finite number. In this case,this
is not altered.
-
initSetUi
public static MPF initSetUi(long op)
Return anMPF
whose value isop
, possibly truncated to the default precision.
-
initSet
public static MPF initSet(long op)
Return anMPF
whose value isop
, possibly truncated to the default precision.
-
initSet
public static MPF initSet(double op)
Return anMPF
whose value isop
, possibly truncated to the default precision.- Throws:
java.lang.ArithmeticException
- ifop
is not a finite number.
-
initSet
public static org.javatuples.Pair<java.lang.Integer,MPF> initSet(java.lang.String str, int base)
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
public org.javatuples.Pair<java.lang.Double,java.lang.Long> 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
public org.javatuples.Pair<java.lang.String,java.lang.Long> getStr(int base, long nDigits)
Return the String representation of thisMPF
in the specifiedbase
, ornull
if the base is not valid. See the GMP functionmpf_get_str
.
-
getBigDecimal
public java.math.BigDecimal getBigDecimal()
Convertthis
to aBigDecimal
.
-
addUiAssign
public MPF addUiAssign(MPF op1, long op2)
Set thisMPF
to(op1 + op2)
.- Returns:
- this
MPF
.
-
addUiAssign
public MPF addUiAssign(long op)
Set thisMPF
to(this + op)
- Returns:
- this
MPF
-
addUi
public MPF addUi(long op)
Return anMPF
whose value is(this + op)
.
-
subUiAssign
public MPF subUiAssign(MPF op1, long op2)
Set thisMPF
to(op1 - op2)
.- Returns:
- this
MPF
.
-
subUiAssign
public MPF subUiAssign(long op)
Set thisMPF
to(this - op)
- Returns:
- this
MPF
-
subUi
public MPF subUi(long op)
Return anMPF
whose value is(this - op)
.
-
uiSubAssign
public MPF uiSubAssign(long op1, MPF op2)
Set thisMPF
to(op1 - op2)
.- Returns:
- this
MPF
.
-
uiSubAssign
public MPF uiSubAssign(long op)
Set thisMPF
to(op - this)
- Returns:
- this
MPF
-
uiSub
public MPF uiSub(long op)
Return anMPF
whose value is(op - this)
.
-
mulUiAssign
public MPF mulUiAssign(MPF op1, long op2)
Set thisMPF
to(op1 * op2)
.- Returns:
- this
MPF
.
-
mulUiAssign
public MPF mulUiAssign(long op)
Set thisMPF
to(this * op)
- Returns:
- this
MPF
-
mulUi
public MPF mulUi(long op)
Return anMPF
whose value is(this * op)
.
-
divAssign
public MPF divAssign(MPF op1, MPF op2)
Set thisMPF
to(op1 / op2)
.- Returns:
- this
MPF
. - Throws:
java.lang.ArithmeticException
- ifop2
is zero.
-
divAssign
public MPF divAssign(MPF op)
Set thisMPF
to(this / op)
- Returns:
- this
MPF
- Throws:
java.lang.ArithmeticException
- ifop
is zero.
-
div
public MPF div(MPF op)
Return anMPF
whose value is(this / op)
.- Throws:
java.lang.ArithmeticException
- ifop
is zero.
-
divUiAssign
public MPF divUiAssign(MPF op1, long op2)
Set thisMPF
to(op1 / op2)
.- Returns:
- this
MPF
. - Throws:
java.lang.ArithmeticException
- ifop2
is zero.
-
divUiAssign
public MPF divUiAssign(long op)
Set thisMPF
to(this / op)
- Returns:
- this
MPF
- Throws:
java.lang.ArithmeticException
- ifop
is zero.
-
divUi
public MPF divUi(long op)
Return anMPF
whose value is(this / op)
.- Throws:
java.lang.ArithmeticException
- ifop
is zero.
-
uiDivAssign
public MPF uiDivAssign(long op1, MPF op2)
Set thisMPF
to(op1 / op2)
.- Returns:
- this
MPF
. - Throws:
java.lang.ArithmeticException
- ifop2
is zero.
-
uiDivAssign
public MPF uiDivAssign(long op)
Set thisMPF
to(op / this)
- Returns:
- this
MPF
- Throws:
java.lang.ArithmeticException
- ifthis
is zero.
-
uiDiv
public MPF uiDiv(long op)
Return anMPF
whose value is(op / this)
.- Throws:
java.lang.ArithmeticException
- ifthis
is zero.
-
sqrtAssign
public MPF sqrtAssign(MPF op)
Set thisMPF
to the the square root ofop
.- Returns:
- this
MPF
.
-
sqrtAssign
public MPF sqrtAssign()
Set thisMPF
to its square root.- Returns:
- this
MPF
.
-
sqrt
public MPF sqrt()
Return anMPF
whose value is the square root ofthis
.
-
sqrtUiAssign
public MPF sqrtUiAssign(long op)
Set thisMPF
to the the square root ofop
.- Returns:
- this
MPF
.
-
sqrtUi
public static MPF sqrtUi(long op)
Return anMPF
whose value is the square root ofthis
.
-
powUiAssign
public MPF powUiAssign(MPF base, long exp)
Set thisMPF
to(baseexp)
. The case00
yields1
.- Returns:
- this
MPF
.
-
powUiAssign
public MPF powUiAssign(long exp)
Set thisMPF
to(thisexp)
. The case00
yields1
.- Returns:
- this
MPF
.
-
powUi
public MPF powUi(long exp)
Return anMPF
whose value is(thisexp)
. The case00
yields1
.
-
negAssign
public MPF negAssign()
Set thisMPF
to its opposite.- Returns:
- this
MPF
.
-
neg
public MPF neg()
Return anMPF
whose value is(- this)
.
-
absAssign
public MPF absAssign(MPF op)
Set thisMPF
to the absolute value ofop
.- Returns:
- this
MPF
.
-
absAssign
public MPF absAssign()
Set thisMPF
to its absolute value.- Returns:
- this
MPF
.
-
abs
public MPF abs()
Return anMPF
whose value is the absolute value ofthis
.
-
mul2ExpAssign
public MPF mul2ExpAssign(MPF op, long b)
Set thisMPF
to(op * 2b)
.- Returns:
- this
MPF
.
-
mul2ExpAssign
public MPF mul2ExpAssign(long b)
Set thisMPF
to(this * 2b)
.- Returns:
- this
MPF
.
-
mul2Exp
public MPF mul2Exp(long b)
Return anMPF
whose value is(this * 2b)
.
-
div2ExpAssign
public MPF div2ExpAssign(MPF op, long b)
Set thisMPF
to(op / 2b)
.- Returns:
- this
MPF
.
-
div2ExpAssign
public MPF div2ExpAssign(long b)
Set thisMPF
to(this / 2b)
.- Returns:
- this
MPF
.
-
div2Exp
public MPF div2Exp(long b)
Return anMPF
whose value is(this * 2b)
.
-
cmp
public int cmp(MPF op)
Comparethis
withop
. Return a positive value if(this > op)
, zero if(this = op)
, or a negative value if(this < op)
.
-
cmp
public int cmp(MPZ 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.
-
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:
java.lang.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
public MPF reldiffAssign(MPF op1, MPF op2)
Set thisMPF
to the relative difference betweenop1
andop2
, i.e.,(abs(op1-op2)/op1)
.- Returns:
- this
MPF
.
-
reldiffAssign
public MPF reldiffAssign(MPF op)
Set thisMPF
to the relative difference betweenthis
andop
, i.e.,(abs(this-op)/this)
.- Returns:
- this
MPF
.
-
reldiff
public MPF reldiff(MPF op)
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
public MPF ceilAssign(MPF op)
Set thisMPF
to the value ofop
rounded to the next higher integer.- Returns:
- this
MPF
.
-
ceilAssign
public MPF ceilAssign()
Set thisMPF
to its value rounded to the next higher integer.- Returns:
- this
MPF
.
-
ceil
public MPF ceil()
Return anMPF
whose value isthis
rounded to the next higher integer.
-
floorAssign
public MPF floorAssign(MPF op)
Set thisMPF
to the value ofop
rounded to the next lower integer.- Returns:
- this
MPF
.
-
floorAssign
public MPF floorAssign()
Set thisMPF
to its value rounded to the next lower integer.- Returns:
- this
MPF
.
-
floor
public MPF floor()
Return anMPF
whose value isthis
rounded to the next lower integer.
-
truncAssign
public MPF truncAssign(MPF op)
Set thisMPF
to the value ofop
rounded towards zero.- Returns:
- this
MPF
.
-
truncAssign
public MPF truncAssign()
Set thisMPF
to its value rounded towards zero.- Returns:
- this
MPF
.
-
trunc
public 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
public MPF urandombAssign(RandState s, long nbits)
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
public static MPF urandomb(RandState s, long nbits)
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
public MPF 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. 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
public 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. 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
public MPF setValue(MPF op)
Set thisMPF
toop
, possibly truncated according to precision.- Returns:
- this
MPF
.
-
setValue
public MPF setValue(long op)
Set thisMPF
toop
, possibly truncated according to precision.- Returns:
- this
MPF
.
-
setValue
public MPF setValue(double op)
Set thisMPF
toop
, possibly truncated according to precision.- Returns:
- this
MPF
. - Throws:
java.lang.ArithmeticException
- ifop
is not a finite number. In this case,this
is not altered.
-
setValue
public MPF setValue(MPZ op)
Set thisMPF
toop
, possibly truncated according to precision.- Returns:
- this
MPF
.
-
setValue
public MPF setValue(MPQ op)
Set thisMPF
toop
, possibly truncated according to precision.- Returns:
- this
MPF
.
-
setValue
public MPF setValue(java.lang.String str, int base)
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:
java.lang.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
public MPF setValue(java.lang.String str)
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:
java.lang.ArithmeticException
- ifstr
is not a valid number representation in decimal base.- See Also:
setValue(java.lang.String,int)
-
setValue
public MPF setValue(java.math.BigDecimal op)
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
public int compareTo(MPF op)
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 interfacejava.lang.Comparable<MPF>
-
equals
public boolean equals(java.lang.Object obj)
Compare thisMPF
with the objectop
for equality. It returnstrue
if and only ifop
is anMPF
with the same value ofthis
.- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
Return a hash code value for thisMPF
.- Overrides:
hashCode
in classjava.lang.Object
-
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.- Specified by:
longValue
in classjava.lang.Number
-
intValue
public int intValue()
Convert thisMPF
to anint
.- Specified by:
intValue
in classjava.lang.Number
-
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 classjava.lang.Number
-
floatValue
public float floatValue()
Convert thisMPF
to a float, truncating if necessary.- Specified by:
floatValue
in classjava.lang.Number
-
toString
public java.lang.String toString(int base, long nDigits)
Convert thisMPF
to its string representation in the specifiedbase
, ornull
if the base is not valid. See the GMP functionmpf_get_str
.- Throws:
java.lang.IllegalArgumentException
- if the base is not valid.
-
toString
public java.lang.String toString(int base)
Convert thisMPF
to its string representation in the specifiedbase
, ornull
if the base is not valid. See the GMP functionmpf_get_str
.
-
toString
public java.lang.String toString()
Convert thisMPF
to its decimal string representation.- Overrides:
toString
in classjava.lang.Object
-
writeObject
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException
- Throws:
java.io.IOException
-
readObject
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
readObjectNoData
private void readObjectNoData() throws java.io.ObjectStreamException
- Throws:
java.io.ObjectStreamException
-
-