Package it.unich.jgmp

Class 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 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 the MPF 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:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  MPF.MPFCleaner
      Cleaning action for the MPF class.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private MpfT mpfNative
      The pointer to the native mpf_t object.
      private static long serialVersionUID
      Version for serializability.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        MPF()
      Build an MPF whose value is zero.
        MPF​(double op)
      Build an MPF whose value is op, possibly truncated to the default precision.
        MPF​(long op)
      Build an MPF whose value is op, possibly truncated to the default precision.
        MPF​(MPF op)
      Build an MPF whose value is op, possibly truncated to the default precision.
        MPF​(MPQ op)
      Build an MPF whose value is op, possibly truncated to the default precision.
        MPF​(MPZ op)
      Build an MPF whose value is op, possibly truncated to the default precision.
      private MPF​(MpfT pointer)
      A private constructor which build an MPF starting from a pointer to its native data object.
        MPF​(java.lang.String str)
      Build an MPF whose value is the number represented by the string str in decimal base, possibly truncated to the default precision.
        MPF​(java.lang.String str, int base)
      Build an MPF whose value is the number represented by the string str in the specified base, possibly truncated to the default precision.
        MPF​(java.math.BigDecimal op)
      Builds an MPF whose value is the same as op.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      MPF abs()
      Return an MPF whose value is the absolute value of this.
      MPF absAssign()
      Set this MPF to its absolute value.
      MPF absAssign​(MPF op)
      Set this MPF to the absolute value of op.
      MPF add​(MPF op)
      Return an MPF whose value is (this + op).
      MPF addAssign​(MPF op)
      Set this MPF to (this + op)
      MPF addAssign​(MPF op1, MPF op2)
      Set this MPF to (op1 + op2).
      MPF addUi​(long op)
      Return an MPF whose value is (this + op).
      MPF addUiAssign​(long op)
      Set this MPF to (this + op)
      MPF addUiAssign​(MPF op1, long op2)
      Set this MPF to (op1 + op2).
      MPF ceil()
      Return an MPF whose value is this rounded to the next higher integer.
      MPF ceilAssign()
      Set this MPF to its value rounded to the next higher integer.
      MPF ceilAssign​(MPF op)
      Set this MPF to the value of op rounded to the next higher integer.
      int cmp​(double op)
      Compare this with op.
      int cmp​(long op)
      Compare this with op.
      int cmp​(MPF op)
      Compare this with op.
      int cmp​(MPZ op)
      Compare this with op.
      int cmpUi​(long op)
      Compare this with op.
      int compareTo​(MPF op)
      Compare this MPF with op.
      MPF div​(MPF op)
      Return an MPF whose value is (this / op).
      MPF div2Exp​(long b)
      Return an MPF whose value is (this * 2b).
      MPF div2ExpAssign​(long b)
      Set this MPF to (this / 2b).
      MPF div2ExpAssign​(MPF op, long b)
      Set this MPF to (op / 2b).
      MPF divAssign​(MPF op)
      Set this MPF to (this / op)
      MPF divAssign​(MPF op1, MPF op2)
      Set this MPF to (op1 / op2).
      MPF divUi​(long op)
      Return an MPF whose value is (this / op).
      MPF divUiAssign​(long op)
      Set this MPF to (this / op)
      MPF divUiAssign​(MPF op1, long op2)
      Set this MPF to (op1 / op2).
      double doubleValue()
      Convert this MPF to a double, truncating if necessary.
      boolean equals​(java.lang.Object obj)
      Compare this MPF with the object op for equality.
      boolean fitsSint()
      Return true if and only if this MPF fits into a native signed int.
      boolean fitsSlong()
      Return true if and only if this MPF fits into a native signed long.
      boolean fitsSshort()
      Return true if and only if this MPF fits into a native signed short.
      boolean fitsUint()
      Return true if and only if this MPF fits into a native unsigned int.
      boolean fitsUlong()
      Return true if and only if this MPF fits into a native unsigned long.
      boolean fitsUshort()
      Return true if and only if this MPF fits into a native unsigned short.
      float floatValue()
      Convert this MPF to a float, truncating if necessary.
      MPF floor()
      Return an MPF whose value is this rounded to the next lower integer.
      MPF floorAssign()
      Set this MPF to its value rounded to the next lower integer.
      MPF floorAssign​(MPF op)
      Set this MPF to the value of op rounded to the next lower integer.
      java.math.BigDecimal getBigDecimal()
      Convert this to a BigDecimal.
      double getD()
      Convert this MPF to a double, truncating if necessary.
      org.javatuples.Pair<java.lang.Double,​java.lang.Long> getD2Exp()
      Convert this MPF 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 this MPF, in bits.
      long getSi()
      Convert this MPF 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 this MPF in the specified base, or null if the base is not valid.
      long getUi()
      Convert this MPF to an unsigned long, truncating any fraction part.
      int hashCode()
      Return a hash code value for this MPF.
      static MPF init()
      Return an MPF whose value is zero.
      static MPF init2​(long prec)
      Return an MPF whose value is zero, and set its precision to be at least prec bits.
      static MPF initSet​(double op)
      Return an MPF whose value is op, possibly truncated to the default precision.
      static MPF initSet​(long op)
      Return an MPF whose value is op, possibly truncated to the default precision.
      static MPF initSet​(MPF op)
      Return an MPF whose value is op, possibly truncated to the default precision.
      static org.javatuples.Pair<java.lang.Integer,​MPF> initSet​(java.lang.String str, int base)
      Return an MPF whose value is the number represented by the string str in the specified base, possibly truncated to the default precision.
      static MPF initSetUi​(long op)
      Return an MPF whose value is op, possibly truncated to the default precision.
      int intValue()
      Convert this MPF to an int.
      boolean isInteger()
      Return whether this MPF is an integer.
      boolean isZero()
      Return true if and only if this this MPF is zero.
      long longValue()
      Convert this MPF to a long, truncating any fraction part.
      MPF mul​(MPF op)
      Return an MPF whose value is (this * op).
      MPF mul2Exp​(long b)
      Return an MPF whose value is (this * 2b).
      MPF mul2ExpAssign​(long b)
      Set this MPF to (this * 2b).
      MPF mul2ExpAssign​(MPF op, long b)
      Set this MPF to (op * 2b).
      MPF mulAssign​(MPF op)
      Set this MPF to (this * op)
      MPF mulAssign​(MPF op1, MPF op2)
      Set this MPF to (op1 * op2).
      MPF mulUi​(long op)
      Return an MPF whose value is (this * op).
      MPF mulUiAssign​(long op)
      Set this MPF to (this * op)
      MPF mulUiAssign​(MPF op1, long op2)
      Set this MPF to (op1 * op2).
      MPF neg()
      Return an MPF whose value is (- this).
      MPF negAssign()
      Set this MPF to its opposite.
      MPF negAssign​(MPF op)
      Set this MPF to (- op).
      MPF powUi​(long exp)
      Return an MPF whose value is (thisexp).
      MPF powUiAssign​(long exp)
      Set this MPF to (thisexp).
      MPF powUiAssign​(MPF base, long exp)
      Set this MPF to (baseexp).
      static MPF random2​(long maxSize, long exp)
      Return an MPF whose value is a random integer of at most maxSize limbs, with long strings of zeros and ones in the binary representation.
      MPF random2Assign​(long maxSize, long exp)
      Set this MPF to a random integer of at most maxSize 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 between this and this, i.e., (abs(this-op)/this).
      MPF reldiffAssign​(MPF op)
      Set this MPF to the relative difference between this and op, i.e., (abs(this-op)/this).
      MPF reldiffAssign​(MPF op1, MPF op2)
      Set this MPF to the relative difference between op1 and op2, i.e., (abs(op1-op2)/op1).
      MPF set​(double op)
      Set this MPF to op, possibly truncated according to precision.
      MPF set​(long op)
      Set this MPF to op, possibly truncated according to precision.
      MPF set​(MPF op)
      Set this MPF to op, possibly truncated according to precision.
      MPF set​(MPQ op)
      Set this MPF to op, possibly truncated according to precision.
      MPF set​(MPZ op)
      Set this MPF to op, possibly truncated according to precision.
      int set​(java.lang.String str, int base)
      Set this MPF to the number represented by the string str in the specified base, possibly truncated according to precision.
      MPF set​(java.math.BigDecimal op)
      Set this MPF to the big decimal op.
      static void setDefaultPrec​(long prec)
      Set the default precision to be at least prec bits.
      MPF setPrec​(long prec)
      Set the precision of this MPF to be at least prec bits.
      MPF setUi​(long op)
      Set this MPF to op, possibly truncated according to precision.
      MPF setValue​(double op)
      Set this MPF to op, possibly truncated according to precision.
      MPF setValue​(long op)
      Set this MPF to op, possibly truncated according to precision.
      MPF setValue​(MPF op)
      Set this MPF to op, possibly truncated according to precision.
      MPF setValue​(MPQ op)
      Set this MPF to op, possibly truncated according to precision.
      MPF setValue​(MPZ op)
      Set this MPF to op, possibly truncated according to precision.
      MPF setValue​(java.lang.String str)
      Set this MPF to the value represented by the string str in decimal base, possibly truncated according to precision.
      MPF setValue​(java.lang.String str, int base)
      Set this MPF to the number represented by the string str in the specified base, possibly truncated according to precision.
      MPF setValue​(java.math.BigDecimal op)
      Set this MPF to the big decimal op.
      int sgn()
      Return +1 if (this > 0), 0 if (this = 0) and -1 if (this < 0).
      MPF sqrt()
      Return an MPF whose value is the square root of this.
      MPF sqrtAssign()
      Set this MPF to its square root.
      MPF sqrtAssign​(MPF op)
      Set this MPF to the the square root of op.
      static MPF sqrtUi​(long op)
      Return an MPF whose value is the square root of this.
      MPF sqrtUiAssign​(long op)
      Set this MPF to the the square root of op.
      MPF sub​(MPF op)
      Return an MPF whose value is (this - op).
      MPF subAssign​(MPF op)
      Set this MPF to (this - op)
      MPF subAssign​(MPF op1, MPF op2)
      Set this MPF to (op1 - op2).
      MPF subUi​(long op)
      Return an MPF whose value is (this - op).
      MPF subUiAssign​(long op)
      Set this MPF to (this - op)
      MPF subUiAssign​(MPF op1, long op2)
      Set this MPF to (op1 - op2).
      MPF swap​(MPF op)
      Swap the value of this MPF with the value of op.
      java.lang.String toString()
      Convert this MPF to its decimal string representation.
      java.lang.String toString​(int base)
      Convert this MPF to its string representation in the specified base, or null if the base is not valid.
      java.lang.String toString​(int base, long nDigits)
      Convert this MPF to its string representation in the specified base, or null if the base is not valid.
      MPF trunc()
      Return an MPF whose value is this rounded towards zero.
      MPF truncAssign()
      Set this MPF to its value rounded towards zero.
      MPF truncAssign​(MPF op)
      Set this MPF to the value of op rounded towards zero.
      MPF uiDiv​(long op)
      Return an MPF whose value is (op / this).
      MPF uiDivAssign​(long op)
      Set this MPF to (op / this)
      MPF uiDivAssign​(long op1, MPF op2)
      Set this MPF to (op1 / op2).
      MPF uiSub​(long op)
      Return an MPF whose value is (op - this).
      MPF uiSubAssign​(long op)
      Set this MPF to (op - this)
      MPF uiSubAssign​(long op1, MPF op2)
      Set this MPF to (op1 - op2).
      static MPF urandomb​(RandState s, long nbits)
      Return an MPF whose value is an uniformly distributed random float in the range from 0 included to 1 excluded.
      MPF urandombAssign​(RandState s, long nbits)
      Set this MPF to a uniformly distributed random float in the range from 0 included to 1 excluded.
      private void writeObject​(java.io.ObjectOutputStream out)  
      • Methods inherited from class java.lang.Number

        byteValue, shortValue
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • 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 native mpf_t object.
    • Constructor Detail

      • MPF

        private MPF​(MpfT pointer)
        A private constructor which build an MPF starting from a pointer to its native data object. The native object needs to be already initialized.
      • MPF

        public MPF()
        Build an MPF whose value is zero.
      • MPF

        public MPF​(MPF op)
        Build an MPF whose value is op, possibly truncated to the default precision.
      • MPF

        public MPF​(long op)
        Build an MPF whose value is op, possibly truncated to the default precision.
      • MPF

        public MPF​(double op)
        Build an MPF whose value is op, possibly truncated to the default precision.
        Throws:
        java.lang.ArithmeticException - if op is not a finite number.
      • MPF

        public MPF​(MPQ op)
        Build an MPF whose value is op, possibly truncated to the default precision.
      • MPF

        public MPF​(MPZ op)
        Build an MPF whose value is op, possibly truncated to the default precision.
      • MPF

        public MPF​(java.lang.String str,
                   int base)
        Build an MPF whose value is the number represented by the string str in the specified base, possibly truncated to the default precision. See the GMP function mpf_init_set_str.
        Throws:
        java.lang.NumberFormatException - if either base is not valid or str is not a valid string in the specified base.
      • MPF

        public MPF​(java.lang.String str)
        Build an MPF whose value is the number represented by the string str in decimal base, possibly truncated to the default precision. See the GMP function mpf_init_set_str.
        Throws:
        java.lang.NumberFormatException - if str is not a valid number representation in decimal base.
      • MPF

        public MPF​(java.math.BigDecimal op)
        Builds an MPF whose value is the same as op. Note that, since BigDecimal represents number in thedecimal base while MPF 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 least prec bits. Previously initialized variables are unaffected.
      • getDefaultPrec

        public static long getDefaultPrec()
        Return the default precision actually used.
      • init

        public static MPF init()
        Return an MPF whose value is zero. The precision of the result will be taken from the active default precision, as set by setDefaultPrec(long).
      • init2

        public static MPF init2​(long prec)
        Return an MPF whose value is zero, and set its precision to be at least prec bits.
      • getPrec

        public long getPrec()
        Return the current precision of this MPF, in bits.
      • setPrec

        public MPF setPrec​(long prec)
        Set the precision of this MPF to be at least prec 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 this MPF to op, possibly truncated according to precision.
        Returns:
        this MPF.
      • set

        public MPF set​(long op)
        Set this MPF to op, possibly truncated according to precision.
        Returns:
        this MPF.
      • setUi

        public MPF setUi​(long op)
        Set this MPF to op, possibly truncated according to precision.
        Returns:
        this MPF.
      • set

        public MPF set​(double op)
        Set this MPF to op, possibly truncated according to precision.
        Returns:
        this MPF.
        Throws:
        java.lang.ArithmeticException - if op is not a finite number. In this case, this is not altered.
      • set

        public MPF set​(MPZ op)
        Set this MPF to op, possibly truncated according to precision.
        Returns:
        this MPF.
      • set

        public MPF set​(MPQ op)
        Set this MPF to op, possibly truncated according to precision.
        Returns:
        this MPF.
      • set

        public int set​(java.lang.String str,
                       int base)
        Set this MPF to the number represented by the string str in the specified base, possibly truncated according to precision. See the GMP function mpf_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 this MPF to the big decimal op. Note that, since BigDecimal represents number in thedecimal base while MPF use the binary base, rounding is possible.
        Returns:
        this MPF.
      • swap

        public MPF swap​(MPF op)
        Swap the value of this MPF with the value of op. Both the value and the precision of the two objects are swapped.
        Returns:
        this MPF.
      • initSet

        public static MPF initSet​(MPF op)
        Return an MPF whose value is op, possibly truncated to the default precision.
        Throws:
        java.lang.ArithmeticException - if op is not a finite number. In this case, this is not altered.
      • initSetUi

        public static MPF initSetUi​(long op)
        Return an MPF whose value is op, possibly truncated to the default precision.
      • initSet

        public static MPF initSet​(long op)
        Return an MPF whose value is op, possibly truncated to the default precision.
      • initSet

        public static MPF initSet​(double op)
        Return an MPF whose value is op, possibly truncated to the default precision.
        Throws:
        java.lang.ArithmeticException - if op is not a finite number.
      • initSet

        public static org.javatuples.Pair<java.lang.Integer,​MPF> initSet​(java.lang.String str,
                                                                               int base)
        Return an MPF whose value is the number represented by the string str in the specified base, possibly truncated to the default precision. See the GMP function mpf_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 either base is not valid, or str is not a valid numeric representation in the specified base. The second component of the pair is the number represented in str if the operation succeeded, 0 otherwise.
      • getD

        public double getD()
        Convert this MPF 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 this MPF to a pair made of mantissa and exponent, truncating if necessary. See the GMP function mpf_get_d_2exp.
      • getUi

        public long getUi()
        Convert this MPF 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 this MPF 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 this MPF in the specified base, or null if the base is not valid. See the GMP function mpf_get_str.
      • getBigDecimal

        public java.math.BigDecimal getBigDecimal()
        Convert this to a BigDecimal.
      • addAssign

        public MPF addAssign​(MPF op1,
                             MPF op2)
        Set this MPF to (op1 + op2).
        Returns:
        this MPF.
      • addAssign

        public MPF addAssign​(MPF op)
        Set this MPF to (this + op)
        Returns:
        this MPF
      • add

        public MPF add​(MPF op)
        Return an MPF whose value is (this + op).
      • addUiAssign

        public MPF addUiAssign​(MPF op1,
                               long op2)
        Set this MPF to (op1 + op2).
        Returns:
        this MPF.
      • addUiAssign

        public MPF addUiAssign​(long op)
        Set this MPF to (this + op)
        Returns:
        this MPF
      • addUi

        public MPF addUi​(long op)
        Return an MPF whose value is (this + op).
      • subAssign

        public MPF subAssign​(MPF op1,
                             MPF op2)
        Set this MPF to (op1 - op2).
        Returns:
        this MPF.
      • subAssign

        public MPF subAssign​(MPF op)
        Set this MPF to (this - op)
        Returns:
        this MPF
      • sub

        public MPF sub​(MPF op)
        Return an MPF whose value is (this - op).
      • subUiAssign

        public MPF subUiAssign​(MPF op1,
                               long op2)
        Set this MPF to (op1 - op2).
        Returns:
        this MPF.
      • subUiAssign

        public MPF subUiAssign​(long op)
        Set this MPF to (this - op)
        Returns:
        this MPF
      • subUi

        public MPF subUi​(long op)
        Return an MPF whose value is (this - op).
      • uiSubAssign

        public MPF uiSubAssign​(long op1,
                               MPF op2)
        Set this MPF to (op1 - op2).
        Returns:
        this MPF.
      • uiSubAssign

        public MPF uiSubAssign​(long op)
        Set this MPF to (op - this)
        Returns:
        this MPF
      • uiSub

        public MPF uiSub​(long op)
        Return an MPF whose value is (op - this).
      • mulAssign

        public MPF mulAssign​(MPF op1,
                             MPF op2)
        Set this MPF to (op1 * op2).
        Returns:
        this MPF.
      • mulAssign

        public MPF mulAssign​(MPF op)
        Set this MPF to (this * op)
        Returns:
        this MPF
      • mul

        public MPF mul​(MPF op)
        Return an MPF whose value is (this * op).
      • mulUiAssign

        public MPF mulUiAssign​(MPF op1,
                               long op2)
        Set this MPF to (op1 * op2).
        Returns:
        this MPF.
      • mulUiAssign

        public MPF mulUiAssign​(long op)
        Set this MPF to (this * op)
        Returns:
        this MPF
      • mulUi

        public MPF mulUi​(long op)
        Return an MPF whose value is (this * op).
      • divAssign

        public MPF divAssign​(MPF op1,
                             MPF op2)
        Set this MPF to (op1 / op2).
        Returns:
        this MPF.
        Throws:
        java.lang.ArithmeticException - if op2 is zero.
      • divAssign

        public MPF divAssign​(MPF op)
        Set this MPF to (this / op)
        Returns:
        this MPF
        Throws:
        java.lang.ArithmeticException - if op is zero.
      • div

        public MPF div​(MPF op)
        Return an MPF whose value is (this / op).
        Throws:
        java.lang.ArithmeticException - if op is zero.
      • divUiAssign

        public MPF divUiAssign​(MPF op1,
                               long op2)
        Set this MPF to (op1 / op2).
        Returns:
        this MPF.
        Throws:
        java.lang.ArithmeticException - if op2 is zero.
      • divUiAssign

        public MPF divUiAssign​(long op)
        Set this MPF to (this / op)
        Returns:
        this MPF
        Throws:
        java.lang.ArithmeticException - if op is zero.
      • divUi

        public MPF divUi​(long op)
        Return an MPF whose value is (this / op).
        Throws:
        java.lang.ArithmeticException - if op is zero.
      • uiDivAssign

        public MPF uiDivAssign​(long op1,
                               MPF op2)
        Set this MPF to (op1 / op2).
        Returns:
        this MPF.
        Throws:
        java.lang.ArithmeticException - if op2 is zero.
      • uiDivAssign

        public MPF uiDivAssign​(long op)
        Set this MPF to (op / this)
        Returns:
        this MPF
        Throws:
        java.lang.ArithmeticException - if this is zero.
      • uiDiv

        public MPF uiDiv​(long op)
        Return an MPF whose value is (op / this).
        Throws:
        java.lang.ArithmeticException - if this is zero.
      • sqrtAssign

        public MPF sqrtAssign​(MPF op)
        Set this MPF to the the square root of op.
        Returns:
        this MPF.
      • sqrtAssign

        public MPF sqrtAssign()
        Set this MPF to its square root.
        Returns:
        this MPF.
      • sqrt

        public MPF sqrt()
        Return an MPF whose value is the square root of this.
      • sqrtUiAssign

        public MPF sqrtUiAssign​(long op)
        Set this MPF to the the square root of op.
        Returns:
        this MPF.
      • sqrtUi

        public static MPF sqrtUi​(long op)
        Return an MPF whose value is the square root of this.
      • powUiAssign

        public MPF powUiAssign​(MPF base,
                               long exp)
        Set this MPF to (baseexp). The case 00 yields 1.
        Returns:
        this MPF.
      • powUiAssign

        public MPF powUiAssign​(long exp)
        Set this MPF to (thisexp). The case 00 yields 1.
        Returns:
        this MPF.
      • powUi

        public MPF powUi​(long exp)
        Return an MPF whose value is (thisexp). The case 00 yields 1.
      • negAssign

        public MPF negAssign​(MPF op)
        Set this MPF to (- op).
        Returns:
        this MPF.
      • negAssign

        public MPF negAssign()
        Set this MPF to its opposite.
        Returns:
        this MPF.
      • neg

        public MPF neg()
        Return an MPF whose value is (- this).
      • absAssign

        public MPF absAssign​(MPF op)
        Set this MPF to the absolute value of op.
        Returns:
        this MPF.
      • absAssign

        public MPF absAssign()
        Set this MPF to its absolute value.
        Returns:
        this MPF.
      • abs

        public MPF abs()
        Return an MPF whose value is the absolute value of this.
      • mul2ExpAssign

        public MPF mul2ExpAssign​(MPF op,
                                 long b)
        Set this MPF to (op * 2b).
        Returns:
        this MPF.
      • mul2ExpAssign

        public MPF mul2ExpAssign​(long b)
        Set this MPF to (this * 2b).
        Returns:
        this MPF.
      • mul2Exp

        public MPF mul2Exp​(long b)
        Return an MPF whose value is (this * 2b).
      • div2ExpAssign

        public MPF div2ExpAssign​(MPF op,
                                 long b)
        Set this MPF to (op / 2b).
        Returns:
        this MPF.
      • div2ExpAssign

        public MPF div2ExpAssign​(long b)
        Set this MPF to (this / 2b).
        Returns:
        this MPF.
      • div2Exp

        public MPF div2Exp​(long b)
        Return an MPF whose value is (this * 2b).
      • cmp

        public int cmp​(MPF op)
        Compare this with op. Return a positive value if (this > op), zero if (this = op), or a negative value if (this < op).
      • cmp

        public int cmp​(MPZ op)
        Compare this with op. Return a positive value if (this > op), zero if (this = op), or a negative value if (this < op). The value of op may be infinite, but the result is undefined on NaNs.
      • cmp

        public int cmp​(double op)
        Compare this with op. Return a positive value if (this > op), zero if (this = op), or a negative value if (this < op). The value of op may be infinite, but the result is undefined on NaNs.
        Throws:
        java.lang.ArithmeticException - if op is a NaN.
      • cmp

        public int cmp​(long op)
        Compare this with op. Return a positive value if (this > op), zero if (this = op), or a negative value if (this < op).
      • cmpUi

        public int cmpUi​(long op)
        Compare this with op. 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 this MPF to the relative difference between op1 and op2, i.e., (abs(op1-op2)/op1).
        Returns:
        this MPF.
      • reldiffAssign

        public MPF reldiffAssign​(MPF op)
        Set this MPF to the relative difference between this and op, i.e., (abs(this-op)/this).
        Returns:
        this MPF.
      • reldiff

        public MPF reldiff​(MPF op)
        Return the relative difference between this and this, 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 this MPF to the value of op rounded to the next higher integer.
        Returns:
        this MPF.
      • ceilAssign

        public MPF ceilAssign()
        Set this MPF to its value rounded to the next higher integer.
        Returns:
        this MPF.
      • ceil

        public MPF ceil()
        Return an MPF whose value is this rounded to the next higher integer.
      • floorAssign

        public MPF floorAssign​(MPF op)
        Set this MPF to the value of op rounded to the next lower integer.
        Returns:
        this MPF.
      • floorAssign

        public MPF floorAssign()
        Set this MPF to its value rounded to the next lower integer.
        Returns:
        this MPF.
      • floor

        public MPF floor()
        Return an MPF whose value is this rounded to the next lower integer.
      • truncAssign

        public MPF truncAssign​(MPF op)
        Set this MPF to the value of op rounded towards zero.
        Returns:
        this MPF.
      • truncAssign

        public MPF truncAssign()
        Set this MPF to its value rounded towards zero.
        Returns:
        this MPF.
      • trunc

        public MPF trunc()
        Return an MPF whose value is this rounded towards zero.
      • isInteger

        public boolean isInteger()
        Return whether this MPF is an integer.
      • fitsUlong

        public boolean fitsUlong()
        Return true if and only if this MPF fits into a native unsigned long.
      • fitsSlong

        public boolean fitsSlong()
        Return true if and only if this MPF fits into a native signed long.
      • fitsUint

        public boolean fitsUint()
        Return true if and only if this MPF fits into a native unsigned int.
      • fitsSint

        public boolean fitsSint()
        Return true if and only if this MPF fits into a native signed int.
      • fitsUshort

        public boolean fitsUshort()
        Return true if and only if this MPF fits into a native unsigned short.
      • fitsSshort

        public boolean fitsSshort()
        Return true if and only if this MPF fits into a native signed short.
      • isZero

        public boolean isZero()
        Return true if and only if this this MPF is zero.
      • urandombAssign

        public MPF urandombAssign​(RandState s,
                                  long nbits)
        Set this MPF to a uniformly distributed random float in the range from 0 included to 1 excluded. The result has nbits significant bits in the mantissa, or less if the precision of this MPF is smaller.
      • urandomb

        public static MPF urandomb​(RandState s,
                                   long nbits)
        Return an MPF whose value is an uniformly distributed random float in the range from 0 included to 1 excluded. The result has nbits significant bits in the mantissa, or less if the default precision is smaller.
      • random2Assign

        public MPF random2Assign​(long maxSize,
                                 long exp)
        Set this MPF to a random integer of at most maxSize limbs, with long strings of zeros and ones in the binary representation. The exponent of the number is in the interval -exp to exp (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 when maxSize is negative.
        Returns:
        this MPF.
      • random2

        public static MPF random2​(long maxSize,
                                  long exp)
        Return an MPF whose value is a random integer of at most maxSize limbs, with long strings of zeros and ones in the binary representation. The exponent of the number is in the interval -exp to exp (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 when maxSize is negative.
      • setValue

        public MPF setValue​(MPF op)
        Set this MPF to op, possibly truncated according to precision.
        Returns:
        this MPF.
      • setValue

        public MPF setValue​(long op)
        Set this MPF to op, possibly truncated according to precision.
        Returns:
        this MPF.
      • setValue

        public MPF setValue​(double op)
        Set this MPF to op, possibly truncated according to precision.
        Returns:
        this MPF.
        Throws:
        java.lang.ArithmeticException - if op is not a finite number. In this case, this is not altered.
      • setValue

        public MPF setValue​(MPZ op)
        Set this MPF to op, possibly truncated according to precision.
        Returns:
        this MPF.
      • setValue

        public MPF setValue​(MPQ op)
        Set this MPF to op, possibly truncated according to precision.
        Returns:
        this MPF.
      • setValue

        public MPF setValue​(java.lang.String str,
                            int base)
        Set this MPF to the number represented by the string str in the specified base, possibly truncated according to precision. See the GMP function mpf_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 either base is not valid or str 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 this MPF to the value represented by the string str 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 - if str 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 this MPF to the big decimal op. Note that, since BigDecimal represents number in thedecimal base while MPF use the binary base, rounding is possible.
        Returns:
        this MPF.
      • compareTo

        public int compareTo​(MPF op)
        Compare this MPF with op. 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 interface java.lang.Comparable<MPF>
      • equals

        public boolean equals​(java.lang.Object obj)
        Compare this MPF with the object op for equality. It returns true if and only if op is an MPF with the same value of this.
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Return a hash code value for this MPF.
        Overrides:
        hashCode in class java.lang.Object
      • longValue

        public long longValue()
        Convert this MPF to a long, truncating any fraction part. If this number is too big to fit a long, the result is undefined.
        Specified by:
        longValue in class java.lang.Number
      • intValue

        public int intValue()
        Convert this MPF to an int.
        Specified by:
        intValue in class java.lang.Number
      • doubleValue

        public double doubleValue()
        Convert this MPF 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 class java.lang.Number
      • floatValue

        public float floatValue()
        Convert this MPF to a float, truncating if necessary.
        Specified by:
        floatValue in class java.lang.Number
      • toString

        public java.lang.String toString​(int base,
                                         long nDigits)
        Convert this MPF to its string representation in the specified base, or null if the base is not valid. See the GMP function mpf_get_str.
        Throws:
        java.lang.IllegalArgumentException - if the base is not valid.
      • toString

        public java.lang.String toString​(int base)
        Convert this MPF to its string representation in the specified base, or null if the base is not valid. See the GMP function mpf_get_str.
      • toString

        public java.lang.String toString()
        Convert this MPF to its decimal string representation.
        Overrides:
        toString in class java.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