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_tdata type, see the Floating-point Functions page of the GMP manual. In determining the names and signatures of the methods of theMPFclass, we adopt the rules described in the documentation of theit.unich.jgmppackage, enriched with the following ones:- the function
mpf_set_prec_rawis not exposed by theMPFclass; - the functions in the "I/O of Floats" category are not exposed by
the
MPFclass.
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 classMPF.MPFCleanerCleaning action for theMPFclass.
-
Field Summary
Fields Modifier and Type Field Description private MpfTmpfNativeThe pointer to the nativempf_tobject.private static longserialVersionUIDVersion for serializability.
-
Constructor Summary
Constructors Modifier Constructor Description MPF()Build anMPFwhose value is zero.MPF(double op)Build anMPFwhose value isop, possibly truncated to the default precision.MPF(long op)Build anMPFwhose value isop, possibly truncated to the default precision.MPF(MPF op)Build anMPFwhose value isop, possibly truncated to the default precision.MPF(MPQ op)Build anMPFwhose value isop, possibly truncated to the default precision.MPF(MPZ op)Build anMPFwhose value isop, possibly truncated to the default precision.privateMPF(MpfT pointer)A private constructor which build anMPFstarting from a pointer to its native data object.MPF(java.lang.String str)Build anMPFwhose value is the number represented by the stringstrin decimal base, possibly truncated to the default precision.MPF(java.lang.String str, int base)Build anMPFwhose value is the number represented by the stringstrin the specifiedbase, possibly truncated to the default precision.MPF(java.math.BigDecimal op)Builds anMPFwhose value is the same asop.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MPFabs()Return anMPFwhose value is the absolute value ofthis.MPFabsAssign()Set thisMPFto its absolute value.MPFabsAssign(MPF op)Set thisMPFto the absolute value ofop.MPFadd(MPF op)Return anMPFwhose value is(this + op).MPFaddAssign(MPF op)Set thisMPFto(this + op)MPFaddAssign(MPF op1, MPF op2)Set thisMPFto(op1 + op2).MPFaddUi(long op)Return anMPFwhose value is(this + op).MPFaddUiAssign(long op)Set thisMPFto(this + op)MPFaddUiAssign(MPF op1, long op2)Set thisMPFto(op1 + op2).MPFceil()Return anMPFwhose value isthisrounded to the next higher integer.MPFceilAssign()Set thisMPFto its value rounded to the next higher integer.MPFceilAssign(MPF op)Set thisMPFto the value ofoprounded to the next higher integer.intcmp(double op)Comparethiswithop.intcmp(long op)Comparethiswithop.intcmp(MPF op)Comparethiswithop.intcmp(MPZ op)Comparethiswithop.intcmpUi(long op)Comparethiswithop.intcompareTo(MPF op)Compare thisMPFwithop.MPFdiv(MPF op)Return anMPFwhose value is(this / op).MPFdiv2Exp(long b)Return anMPFwhose value is(this * 2b).MPFdiv2ExpAssign(long b)Set thisMPFto(this / 2b).MPFdiv2ExpAssign(MPF op, long b)Set thisMPFto(op / 2b).MPFdivAssign(MPF op)Set thisMPFto(this / op)MPFdivAssign(MPF op1, MPF op2)Set thisMPFto(op1 / op2).MPFdivUi(long op)Return anMPFwhose value is(this / op).MPFdivUiAssign(long op)Set thisMPFto(this / op)MPFdivUiAssign(MPF op1, long op2)Set thisMPFto(op1 / op2).doubledoubleValue()Convert thisMPFto a double, truncating if necessary.booleanequals(java.lang.Object obj)Compare thisMPFwith the objectopfor equality.booleanfitsSint()Returntrueif and only if thisMPFfits into a native signed int.booleanfitsSlong()Returntrueif and only if thisMPFfits into a native signed long.booleanfitsSshort()Returntrueif and only if thisMPFfits into a native signed short.booleanfitsUint()Returntrueif and only if thisMPFfits into a native unsigned int.booleanfitsUlong()Returntrueif and only if thisMPFfits into a native unsigned long.booleanfitsUshort()Returntrueif and only if thisMPFfits into a native unsigned short.floatfloatValue()Convert thisMPFto a float, truncating if necessary.MPFfloor()Return anMPFwhose value isthisrounded to the next lower integer.MPFfloorAssign()Set thisMPFto its value rounded to the next lower integer.MPFfloorAssign(MPF op)Set thisMPFto the value ofoprounded to the next lower integer.java.math.BigDecimalgetBigDecimal()Convertthisto aBigDecimal.doublegetD()Convert thisMPFto a double, truncating if necessary.org.javatuples.Pair<java.lang.Double,java.lang.Long>getD2Exp()Convert thisMPFto a pair made of mantissa and exponent, truncating if necessary.static longgetDefaultPrec()Return the default precision actually used.MpfTgetNative()Return the native pointer to the GMP object.longgetPrec()Return the current precision of thisMPF, in bits.longgetSi()Convert thisMPFto 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 thisMPFin the specifiedbase, ornullif the base is not valid.longgetUi()Convert thisMPFto an unsigned long, truncating any fraction part.inthashCode()Return a hash code value for thisMPF.static MPFinit()Return anMPFwhose value is zero.static MPFinit2(long prec)Return anMPFwhose value is zero, and set its precision to be at leastprecbits.static MPFinitSet(double op)Return anMPFwhose value isop, possibly truncated to the default precision.static MPFinitSet(long op)Return anMPFwhose value isop, possibly truncated to the default precision.static MPFinitSet(MPF op)Return anMPFwhose value isop, possibly truncated to the default precision.static org.javatuples.Pair<java.lang.Integer,MPF>initSet(java.lang.String str, int base)Return anMPFwhose value is the number represented by the stringstrin the specifiedbase, possibly truncated to the default precision.static MPFinitSetUi(long op)Return anMPFwhose value isop, possibly truncated to the default precision.intintValue()Convert thisMPFto anint.booleanisInteger()Return whether thisMPFis an integer.booleanisZero()Return true if and only if thisthisMPF is zero.longlongValue()Convert thisMPFto along, truncating any fraction part.MPFmul(MPF op)Return anMPFwhose value is(this * op).MPFmul2Exp(long b)Return anMPFwhose value is(this * 2b).MPFmul2ExpAssign(long b)Set thisMPFto(this * 2b).MPFmul2ExpAssign(MPF op, long b)Set thisMPFto(op * 2b).MPFmulAssign(MPF op)Set thisMPFto(this * op)MPFmulAssign(MPF op1, MPF op2)Set thisMPFto(op1 * op2).MPFmulUi(long op)Return anMPFwhose value is(this * op).MPFmulUiAssign(long op)Set thisMPFto(this * op)MPFmulUiAssign(MPF op1, long op2)Set thisMPFto(op1 * op2).MPFneg()Return anMPFwhose value is(- this).MPFnegAssign()Set thisMPFto its opposite.MPFnegAssign(MPF op)Set thisMPFto(- op).MPFpowUi(long exp)Return anMPFwhose value is(thisexp).MPFpowUiAssign(long exp)Set thisMPFto(thisexp).MPFpowUiAssign(MPF base, long exp)Set thisMPFto(baseexp).static MPFrandom2(long maxSize, long exp)Return anMPFwhose value is a random integer of at mostmaxSizelimbs, with long strings of zeros and ones in the binary representation.MPFrandom2Assign(long maxSize, long exp)Set thisMPFto a random integer of at mostmaxSizelimbs, with long strings of zeros and ones in the binary representation.private voidreadObject(java.io.ObjectInputStream in)private voidreadObjectNoData()MPFreldiff(MPF op)Return the relative difference betweenthisandthis, i.e.,(abs(this-op)/this).MPFreldiffAssign(MPF op)Set thisMPFto the relative difference betweenthisandop, i.e.,(abs(this-op)/this).MPFreldiffAssign(MPF op1, MPF op2)Set thisMPFto the relative difference betweenop1andop2, i.e.,(abs(op1-op2)/op1).MPFset(double op)Set thisMPFtoop, possibly truncated according to precision.MPFset(long op)Set thisMPFtoop, possibly truncated according to precision.MPFset(MPF op)Set thisMPFtoop, possibly truncated according to precision.MPFset(MPQ op)Set thisMPFtoop, possibly truncated according to precision.MPFset(MPZ op)Set thisMPFtoop, possibly truncated according to precision.intset(java.lang.String str, int base)Set thisMPFto the number represented by the stringstrin the specifiedbase, possibly truncated according to precision.MPFset(java.math.BigDecimal op)Set thisMPFto the big decimalop.static voidsetDefaultPrec(long prec)Set the default precision to be at leastprecbits.MPFsetPrec(long prec)Set the precision of thisMPFto be at leastprecbits.MPFsetUi(long op)Set thisMPFtoop, possibly truncated according to precision.MPFsetValue(double op)Set thisMPFtoop, possibly truncated according to precision.MPFsetValue(long op)Set thisMPFtoop, possibly truncated according to precision.MPFsetValue(MPF op)Set thisMPFtoop, possibly truncated according to precision.MPFsetValue(MPQ op)Set thisMPFtoop, possibly truncated according to precision.MPFsetValue(MPZ op)Set thisMPFtoop, possibly truncated according to precision.MPFsetValue(java.lang.String str)Set thisMPFto the value represented by the stringstrin decimal base, possibly truncated according to precision.MPFsetValue(java.lang.String str, int base)Set thisMPFto the number represented by the stringstrin the specifiedbase, possibly truncated according to precision.MPFsetValue(java.math.BigDecimal op)Set thisMPFto the big decimalop.intsgn()Return+1if(this > 0),0if(this = 0)and-1if(this < 0).MPFsqrt()Return anMPFwhose value is the square root ofthis.MPFsqrtAssign()Set thisMPFto its square root.MPFsqrtAssign(MPF op)Set thisMPFto the the square root ofop.static MPFsqrtUi(long op)Return anMPFwhose value is the square root ofthis.MPFsqrtUiAssign(long op)Set thisMPFto the the square root ofop.MPFsub(MPF op)Return anMPFwhose value is(this - op).MPFsubAssign(MPF op)Set thisMPFto(this - op)MPFsubAssign(MPF op1, MPF op2)Set thisMPFto(op1 - op2).MPFsubUi(long op)Return anMPFwhose value is(this - op).MPFsubUiAssign(long op)Set thisMPFto(this - op)MPFsubUiAssign(MPF op1, long op2)Set thisMPFto(op1 - op2).MPFswap(MPF op)Swap the value of thisMPFwith the value ofop.java.lang.StringtoString()Convert thisMPFto its decimal string representation.java.lang.StringtoString(int base)Convert thisMPFto its string representation in the specifiedbase, ornullif the base is not valid.java.lang.StringtoString(int base, long nDigits)Convert thisMPFto its string representation in the specifiedbase, ornullif the base is not valid.MPFtrunc()Return anMPFwhose value isthisrounded towards zero.MPFtruncAssign()Set thisMPFto its value rounded towards zero.MPFtruncAssign(MPF op)Set thisMPFto the value ofoprounded towards zero.MPFuiDiv(long op)Return anMPFwhose value is(op / this).MPFuiDivAssign(long op)Set thisMPFto(op / this)MPFuiDivAssign(long op1, MPF op2)Set thisMPFto(op1 / op2).MPFuiSub(long op)Return anMPFwhose value is(op - this).MPFuiSubAssign(long op)Set thisMPFto(op - this)MPFuiSubAssign(long op1, MPF op2)Set thisMPFto(op1 - op2).static MPFurandomb(RandState s, long nbits)Return anMPFwhose value is an uniformly distributed random float in the range from0included to1excluded.MPFurandombAssign(RandState s, long nbits)Set thisMPFto a uniformly distributed random float in the range from0included to1excluded.private voidwriteObject(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_tobject.
-
-
Constructor Detail
-
MPF
private MPF(MpfT pointer)
A private constructor which build anMPFstarting from a pointer to its native data object. The native object needs to be already initialized.
-
MPF
public MPF()
Build anMPFwhose value is zero.
-
MPF
public MPF(MPF op)
Build anMPFwhose value isop, possibly truncated to the default precision.
-
MPF
public MPF(long op)
Build anMPFwhose value isop, possibly truncated to the default precision.
-
MPF
public MPF(double op)
Build anMPFwhose value isop, possibly truncated to the default precision.- Throws:
java.lang.ArithmeticException- ifopis not a finite number.
-
MPF
public MPF(MPQ op)
Build anMPFwhose value isop, possibly truncated to the default precision.
-
MPF
public MPF(MPZ op)
Build anMPFwhose value isop, possibly truncated to the default precision.
-
MPF
public MPF(java.lang.String str, int base)Build anMPFwhose value is the number represented by the stringstrin the specifiedbase, possibly truncated to the default precision. See the GMP functionmpf_init_set_str.- Throws:
java.lang.NumberFormatException- if eitherbaseis not valid orstris not a valid string in the specifiedbase.
-
MPF
public MPF(java.lang.String str)
Build anMPFwhose value is the number represented by the stringstrin decimal base, possibly truncated to the default precision. See the GMP functionmpf_init_set_str.- Throws:
java.lang.NumberFormatException- ifstris not a valid number representation in decimal base.
-
MPF
public MPF(java.math.BigDecimal op)
Builds anMPFwhose value is the same asop. Note that, sinceBigDecimalrepresents number in thedecimal base whileMPFuse 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 leastprecbits. Previously initialized variables are unaffected.
-
getDefaultPrec
public static long getDefaultPrec()
Return the default precision actually used.
-
init
public static MPF init()
Return anMPFwhose 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 anMPFwhose value is zero, and set its precision to be at leastprecbits.
-
getPrec
public long getPrec()
Return the current precision of thisMPF, in bits.
-
setPrec
public MPF setPrec(long prec)
Set the precision of thisMPFto be at leastprecbits. 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 thisMPFtoop, possibly truncated according to precision.- Returns:
- this
MPF.
-
set
public MPF set(long op)
Set thisMPFtoop, possibly truncated according to precision.- Returns:
- this
MPF.
-
setUi
public MPF setUi(long op)
Set thisMPFtoop, possibly truncated according to precision.- Returns:
- this
MPF.
-
set
public MPF set(double op)
Set thisMPFtoop, possibly truncated according to precision.- Returns:
- this
MPF. - Throws:
java.lang.ArithmeticException- ifopis not a finite number. In this case,thisis not altered.
-
set
public MPF set(MPZ op)
Set thisMPFtoop, possibly truncated according to precision.- Returns:
- this
MPF.
-
set
public MPF set(MPQ op)
Set thisMPFtoop, possibly truncated according to precision.- Returns:
- this
MPF.
-
set
public int set(java.lang.String str, int base)Set thisMPFto the number represented by the stringstrin 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,
thisis not altered.
-
set
public MPF set(java.math.BigDecimal op)
Set thisMPFto the big decimalop. Note that, sinceBigDecimalrepresents number in thedecimal base whileMPFuse the binary base, rounding is possible.- Returns:
- this
MPF.
-
swap
public MPF swap(MPF op)
Swap the value of thisMPFwith 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 anMPFwhose value isop, possibly truncated to the default precision.- Throws:
java.lang.ArithmeticException- ifopis not a finite number. In this case,thisis not altered.
-
initSetUi
public static MPF initSetUi(long op)
Return anMPFwhose value isop, possibly truncated to the default precision.
-
initSet
public static MPF initSet(long op)
Return anMPFwhose value isop, possibly truncated to the default precision.
-
initSet
public static MPF initSet(double op)
Return anMPFwhose value isop, possibly truncated to the default precision.- Throws:
java.lang.ArithmeticException- ifopis not a finite number.
-
initSet
public static org.javatuples.Pair<java.lang.Integer,MPF> initSet(java.lang.String str, int base)
Return anMPFwhose value is the number represented by the stringstrin 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
0if the operation succeeded, and-1if eitherbaseis not valid, orstris not a valid numeric representation in the specified base. The second component of the pair is the number represented instrif the operation succeeded,0otherwise.
-
getD
public double getD()
Convert thisMPFto 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 thisMPFto a pair made of mantissa and exponent, truncating if necessary. See the GMP functionmpf_get_d_2exp.
-
getUi
public long getUi()
Convert thisMPFto 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 thisMPFto 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 thisMPFin the specifiedbase, ornullif the base is not valid. See the GMP functionmpf_get_str.
-
getBigDecimal
public java.math.BigDecimal getBigDecimal()
Convertthisto aBigDecimal.
-
addUiAssign
public MPF addUiAssign(MPF op1, long op2)
Set thisMPFto(op1 + op2).- Returns:
- this
MPF.
-
addUiAssign
public MPF addUiAssign(long op)
Set thisMPFto(this + op)- Returns:
- this
MPF
-
addUi
public MPF addUi(long op)
Return anMPFwhose value is(this + op).
-
subUiAssign
public MPF subUiAssign(MPF op1, long op2)
Set thisMPFto(op1 - op2).- Returns:
- this
MPF.
-
subUiAssign
public MPF subUiAssign(long op)
Set thisMPFto(this - op)- Returns:
- this
MPF
-
subUi
public MPF subUi(long op)
Return anMPFwhose value is(this - op).
-
uiSubAssign
public MPF uiSubAssign(long op1, MPF op2)
Set thisMPFto(op1 - op2).- Returns:
- this
MPF.
-
uiSubAssign
public MPF uiSubAssign(long op)
Set thisMPFto(op - this)- Returns:
- this
MPF
-
uiSub
public MPF uiSub(long op)
Return anMPFwhose value is(op - this).
-
mulUiAssign
public MPF mulUiAssign(MPF op1, long op2)
Set thisMPFto(op1 * op2).- Returns:
- this
MPF.
-
mulUiAssign
public MPF mulUiAssign(long op)
Set thisMPFto(this * op)- Returns:
- this
MPF
-
mulUi
public MPF mulUi(long op)
Return anMPFwhose value is(this * op).
-
divAssign
public MPF divAssign(MPF op1, MPF op2)
Set thisMPFto(op1 / op2).- Returns:
- this
MPF. - Throws:
java.lang.ArithmeticException- ifop2is zero.
-
divAssign
public MPF divAssign(MPF op)
Set thisMPFto(this / op)- Returns:
- this
MPF - Throws:
java.lang.ArithmeticException- ifopis zero.
-
div
public MPF div(MPF op)
Return anMPFwhose value is(this / op).- Throws:
java.lang.ArithmeticException- ifopis zero.
-
divUiAssign
public MPF divUiAssign(MPF op1, long op2)
Set thisMPFto(op1 / op2).- Returns:
- this
MPF. - Throws:
java.lang.ArithmeticException- ifop2is zero.
-
divUiAssign
public MPF divUiAssign(long op)
Set thisMPFto(this / op)- Returns:
- this
MPF - Throws:
java.lang.ArithmeticException- ifopis zero.
-
divUi
public MPF divUi(long op)
Return anMPFwhose value is(this / op).- Throws:
java.lang.ArithmeticException- ifopis zero.
-
uiDivAssign
public MPF uiDivAssign(long op1, MPF op2)
Set thisMPFto(op1 / op2).- Returns:
- this
MPF. - Throws:
java.lang.ArithmeticException- ifop2is zero.
-
uiDivAssign
public MPF uiDivAssign(long op)
Set thisMPFto(op / this)- Returns:
- this
MPF - Throws:
java.lang.ArithmeticException- ifthisis zero.
-
uiDiv
public MPF uiDiv(long op)
Return anMPFwhose value is(op / this).- Throws:
java.lang.ArithmeticException- ifthisis zero.
-
sqrtAssign
public MPF sqrtAssign(MPF op)
Set thisMPFto the the square root ofop.- Returns:
- this
MPF.
-
sqrtAssign
public MPF sqrtAssign()
Set thisMPFto its square root.- Returns:
- this
MPF.
-
sqrt
public MPF sqrt()
Return anMPFwhose value is the square root ofthis.
-
sqrtUiAssign
public MPF sqrtUiAssign(long op)
Set thisMPFto the the square root ofop.- Returns:
- this
MPF.
-
sqrtUi
public static MPF sqrtUi(long op)
Return anMPFwhose value is the square root ofthis.
-
powUiAssign
public MPF powUiAssign(MPF base, long exp)
Set thisMPFto(baseexp). The case00yields1.- Returns:
- this
MPF.
-
powUiAssign
public MPF powUiAssign(long exp)
Set thisMPFto(thisexp). The case00yields1.- Returns:
- this
MPF.
-
powUi
public MPF powUi(long exp)
Return anMPFwhose value is(thisexp). The case00yields1.
-
negAssign
public MPF negAssign()
Set thisMPFto its opposite.- Returns:
- this
MPF.
-
neg
public MPF neg()
Return anMPFwhose value is(- this).
-
absAssign
public MPF absAssign(MPF op)
Set thisMPFto the absolute value ofop.- Returns:
- this
MPF.
-
absAssign
public MPF absAssign()
Set thisMPFto its absolute value.- Returns:
- this
MPF.
-
abs
public MPF abs()
Return anMPFwhose value is the absolute value ofthis.
-
mul2ExpAssign
public MPF mul2ExpAssign(MPF op, long b)
Set thisMPFto(op * 2b).- Returns:
- this
MPF.
-
mul2ExpAssign
public MPF mul2ExpAssign(long b)
Set thisMPFto(this * 2b).- Returns:
- this
MPF.
-
mul2Exp
public MPF mul2Exp(long b)
Return anMPFwhose value is(this * 2b).
-
div2ExpAssign
public MPF div2ExpAssign(MPF op, long b)
Set thisMPFto(op / 2b).- Returns:
- this
MPF.
-
div2ExpAssign
public MPF div2ExpAssign(long b)
Set thisMPFto(this / 2b).- Returns:
- this
MPF.
-
div2Exp
public MPF div2Exp(long b)
Return anMPFwhose value is(this * 2b).
-
cmp
public int cmp(MPF op)
Comparethiswithop. Return a positive value if(this > op), zero if(this = op), or a negative value if(this < op).
-
cmp
public int cmp(MPZ op)
Comparethiswithop. Return a positive value if(this > op), zero if(this = op), or a negative value if(this < op). The value ofopmay be infinite, but the result is undefined on NaNs.
-
cmp
public int cmp(double op)
Comparethiswithop. Return a positive value if(this > op), zero if(this = op), or a negative value if(this < op). The value ofopmay be infinite, but the result is undefined on NaNs.- Throws:
java.lang.ArithmeticException- ifopis a NaN.
-
cmp
public int cmp(long op)
Comparethiswithop. Return a positive value if(this > op), zero if(this = op), or a negative value if(this < op).
-
cmpUi
public int cmpUi(long op)
Comparethiswithop. 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 thisMPFto the relative difference betweenop1andop2, i.e.,(abs(op1-op2)/op1).- Returns:
- this
MPF.
-
reldiffAssign
public MPF reldiffAssign(MPF op)
Set thisMPFto the relative difference betweenthisandop, i.e.,(abs(this-op)/this).- Returns:
- this
MPF.
-
reldiff
public MPF reldiff(MPF op)
Return the relative difference betweenthisandthis, i.e.,(abs(this-op)/this).
-
sgn
public int sgn()
Return+1if(this > 0),0if(this = 0)and-1if(this < 0).
-
ceilAssign
public MPF ceilAssign(MPF op)
Set thisMPFto the value ofoprounded to the next higher integer.- Returns:
- this
MPF.
-
ceilAssign
public MPF ceilAssign()
Set thisMPFto its value rounded to the next higher integer.- Returns:
- this
MPF.
-
ceil
public MPF ceil()
Return anMPFwhose value isthisrounded to the next higher integer.
-
floorAssign
public MPF floorAssign(MPF op)
Set thisMPFto the value ofoprounded to the next lower integer.- Returns:
- this
MPF.
-
floorAssign
public MPF floorAssign()
Set thisMPFto its value rounded to the next lower integer.- Returns:
- this
MPF.
-
floor
public MPF floor()
Return anMPFwhose value isthisrounded to the next lower integer.
-
truncAssign
public MPF truncAssign(MPF op)
Set thisMPFto the value ofoprounded towards zero.- Returns:
- this
MPF.
-
truncAssign
public MPF truncAssign()
Set thisMPFto its value rounded towards zero.- Returns:
- this
MPF.
-
trunc
public MPF trunc()
Return anMPFwhose value isthisrounded towards zero.
-
isInteger
public boolean isInteger()
Return whether thisMPFis an integer.
-
fitsUlong
public boolean fitsUlong()
Returntrueif and only if thisMPFfits into a native unsigned long.
-
fitsSlong
public boolean fitsSlong()
Returntrueif and only if thisMPFfits into a native signed long.
-
fitsUint
public boolean fitsUint()
Returntrueif and only if thisMPFfits into a native unsigned int.
-
fitsSint
public boolean fitsSint()
Returntrueif and only if thisMPFfits into a native signed int.
-
fitsUshort
public boolean fitsUshort()
Returntrueif and only if thisMPFfits into a native unsigned short.
-
fitsSshort
public boolean fitsSshort()
Returntrueif and only if thisMPFfits into a native signed short.
-
isZero
public boolean isZero()
Return true if and only if thisthisMPF is zero.
-
urandombAssign
public MPF urandombAssign(RandState s, long nbits)
Set thisMPFto a uniformly distributed random float in the range from0included to1excluded. The result hasnbitssignificant bits in the mantissa, or less if the precision of thisMPFis smaller.
-
urandomb
public static MPF urandomb(RandState s, long nbits)
Return anMPFwhose value is an uniformly distributed random float in the range from0included to1excluded. The result hasnbitssignificant bits in the mantissa, or less if the default precision is smaller.
-
random2Assign
public MPF random2Assign(long maxSize, long exp)
Set thisMPFto a random integer of at mostmaxSizelimbs, with long strings of zeros and ones in the binary representation. The exponent of the number is in the interval-exptoexp(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 whenmaxSizeis negative.- Returns:
- this
MPF.
-
random2
public static MPF random2(long maxSize, long exp)
Return anMPFwhose value is a random integer of at mostmaxSizelimbs, with long strings of zeros and ones in the binary representation. The exponent of the number is in the interval-exptoexp(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 whenmaxSizeis negative.
-
setValue
public MPF setValue(MPF op)
Set thisMPFtoop, possibly truncated according to precision.- Returns:
- this
MPF.
-
setValue
public MPF setValue(long op)
Set thisMPFtoop, possibly truncated according to precision.- Returns:
- this
MPF.
-
setValue
public MPF setValue(double op)
Set thisMPFtoop, possibly truncated according to precision.- Returns:
- this
MPF. - Throws:
java.lang.ArithmeticException- ifopis not a finite number. In this case,thisis not altered.
-
setValue
public MPF setValue(MPZ op)
Set thisMPFtoop, possibly truncated according to precision.- Returns:
- this
MPF.
-
setValue
public MPF setValue(MPQ op)
Set thisMPFtoop, possibly truncated according to precision.- Returns:
- this
MPF.
-
setValue
public MPF setValue(java.lang.String str, int base)
Set thisMPFto the number represented by the stringstrin 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 eitherbaseis not valid orstris not a valid number representation in the specified base. In this case,thisis not altered.
-
setValue
public MPF setValue(java.lang.String str)
Set thisMPFto the value represented by the stringstrin 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- ifstris not a valid number representation in decimal base.- See Also:
setValue(java.lang.String,int)
-
setValue
public MPF setValue(java.math.BigDecimal op)
Set thisMPFto the big decimalop. Note that, sinceBigDecimalrepresents number in thedecimal base whileMPFuse the binary base, rounding is possible.- Returns:
- this
MPF.
-
compareTo
public int compareTo(MPF op)
Compare thisMPFwithop. 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:
compareToin interfacejava.lang.Comparable<MPF>
-
equals
public boolean equals(java.lang.Object obj)
Compare thisMPFwith the objectopfor equality. It returnstrueif and only ifopis anMPFwith the same value ofthis.- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
Return a hash code value for thisMPF.- Overrides:
hashCodein classjava.lang.Object
-
longValue
public long longValue()
Convert thisMPFto along, truncating any fraction part. If this number is too big to fit along, the result is undefined.- Specified by:
longValuein classjava.lang.Number
-
intValue
public int intValue()
Convert thisMPFto anint.- Specified by:
intValuein classjava.lang.Number
-
doubleValue
public double doubleValue()
Convert thisMPFto 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:
doubleValuein classjava.lang.Number
-
floatValue
public float floatValue()
Convert thisMPFto a float, truncating if necessary.- Specified by:
floatValuein classjava.lang.Number
-
toString
public java.lang.String toString(int base, long nDigits)Convert thisMPFto its string representation in the specifiedbase, ornullif 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 thisMPFto its string representation in the specifiedbase, ornullif the base is not valid. See the GMP functionmpf_get_str.
-
toString
public java.lang.String toString()
Convert thisMPFto its decimal string representation.- Overrides:
toStringin 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.IOExceptionjava.lang.ClassNotFoundException
-
readObjectNoData
private void readObjectNoData() throws java.io.ObjectStreamException- Throws:
java.io.ObjectStreamException
-
-