Package it.unich.jgmp

Class MPF

All Implemented Interfaces:
Serializable, Comparable<MPF>

public class MPF extends Number implements 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:
  • Nested Class Summary

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

    Fields
    Modifier and Type
    Field
    Description
    private MpfT
    The pointer to the native mpf_t object.
    private static final long
    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(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(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.
     
    Builds an MPF whose value is the same as op.
  • Method Summary

    Modifier and Type
    Method
    Description
    abs()
    Return an MPF whose value is the absolute value of this.
    Set this MPF to its absolute value.
    Set this MPF to the absolute value of op.
    add(MPF op)
    Return an MPF whose value is (this + op).
    Set this MPF to (this + op)
    addAssign(MPF op1, MPF op2)
    Set this MPF to (op1 + op2).
    addUi(long op)
    Return an MPF whose value is (this + op).
    addUiAssign(long op)
    Set this MPF to (this + op)
    addUiAssign(MPF op1, long op2)
    Set this MPF to (op1 + op2).
    Return an MPF whose value is this rounded to the next higher integer.
    Set this MPF to its value rounded to the next higher integer.
    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
    Compare this MPF with op.
    div(MPF op)
    Return an MPF whose value is (this / op).
    div2Exp(long b)
    Return an MPF whose value is (this * 2b).
    div2ExpAssign(long b)
    Set this MPF to (this / 2b).
    div2ExpAssign(MPF op, long b)
    Set this MPF to (op / 2b).
    Set this MPF to (this / op)
    divAssign(MPF op1, MPF op2)
    Set this MPF to (op1 / op2).
    divUi(long op)
    Return an MPF whose value is (this / op).
    divUiAssign(long op)
    Set this MPF to (this / op)
    divUiAssign(MPF op1, long op2)
    Set this MPF to (op1 / op2).
    double
    Convert this MPF to a double, truncating if necessary.
    boolean
    Compare this MPF with the object op for equality.
    boolean
    Return true if and only if this MPF fits into a native signed int.
    boolean
    Return true if and only if this MPF fits into a native signed long.
    boolean
    Return true if and only if this MPF fits into a native signed short.
    boolean
    Return true if and only if this MPF fits into a native unsigned int.
    boolean
    Return true if and only if this MPF fits into a native unsigned long.
    boolean
    Return true if and only if this MPF fits into a native unsigned short.
    float
    Convert this MPF to a float, truncating if necessary.
    Return an MPF whose value is this rounded to the next lower integer.
    Set this MPF to its value rounded to the next lower integer.
    Set this MPF to the value of op rounded to the next lower integer.
    Convert this to a BigDecimal.
    double
    Convert this MPF to a double, truncating if necessary.
    org.javatuples.Pair<Double,Long>
    Convert this MPF to a pair made of mantissa and exponent, truncating if necessary.
    static long
    Return the default precision actually used.
    Return the native pointer to the GMP object.
    long
    Return the current precision of this MPF, in bits.
    long
    Convert this MPF to a long, truncating any fraction part.
    org.javatuples.Pair<String,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
    Convert this MPF to an unsigned long, truncating any fraction part.
    int
    Return a hash code value for this MPF.
    static MPF
    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
    Return an MPF whose value is op, possibly truncated to the default precision.
    static org.javatuples.Pair<Integer,MPF>
    initSet(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
    Convert this MPF to an int.
    boolean
    Return whether this MPF is an integer.
    boolean
    Return true if and only if this this MPF is zero.
    long
    Convert this MPF to a long, truncating any fraction part.
    mul(MPF op)
    Return an MPF whose value is (this * op).
    mul2Exp(long b)
    Return an MPF whose value is (this * 2b).
    mul2ExpAssign(long b)
    Set this MPF to (this * 2b).
    mul2ExpAssign(MPF op, long b)
    Set this MPF to (op * 2b).
    Set this MPF to (this * op)
    mulAssign(MPF op1, MPF op2)
    Set this MPF to (op1 * op2).
    mulUi(long op)
    Return an MPF whose value is (this * op).
    mulUiAssign(long op)
    Set this MPF to (this * op)
    mulUiAssign(MPF op1, long op2)
    Set this MPF to (op1 * op2).
    neg()
    Return an MPF whose value is (- this).
    Set this MPF to its opposite.
    Set this MPF to (- op).
    powUi(long exp)
    Return an MPF whose value is (thisexp).
    powUiAssign(long exp)
    Set this MPF to (thisexp).
    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.
    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
     
    private void
     
    Return the relative difference between this and this, i.e., (abs(this-op)/this).
    Set this MPF to the relative difference between this and op, i.e., (abs(this-op)/this).
    reldiffAssign(MPF op1, MPF op2)
    Set this MPF to the relative difference between op1 and op2, i.e., (abs(op1-op2)/op1).
    set(double op)
    Set this MPF to op, possibly truncated according to precision.
    set(long op)
    Set this MPF to op, possibly truncated according to precision.
    set(MPF op)
    Set this MPF to op, possibly truncated according to precision.
    set(MPQ op)
    Set this MPF to op, possibly truncated according to precision.
    set(MPZ op)
    Set this MPF to op, possibly truncated according to precision.
    int
    set(String str, int base)
    Set this MPF to the number represented by the string str in the specified base, possibly truncated according to precision.
    Set this MPF to the big decimal op.
    static void
    setDefaultPrec(long prec)
    Set the default precision to be at least prec bits.
    setPrec(long prec)
    Set the precision of this MPF to be at least prec bits.
    setUi(long op)
    Set this MPF to op, possibly truncated according to precision.
    setValue(double op)
    Set this MPF to op, possibly truncated according to precision.
    setValue(long op)
    Set this MPF to op, possibly truncated according to precision.
    Set this MPF to op, possibly truncated according to precision.
    Set this MPF to op, possibly truncated according to precision.
    Set this MPF to op, possibly truncated according to precision.
    Set this MPF to the value represented by the string str in decimal base, possibly truncated according to precision.
    setValue(String str, int base)
    Set this MPF to the number represented by the string str in the specified base, possibly truncated according to precision.
    Set this MPF to the big decimal op.
    int
    sgn()
    Return +1 if (this > 0), 0 if (this = 0) and -1 if (this < 0).
    Return an MPF whose value is the square root of this.
    Set this MPF to its square root.
    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.
    sqrtUiAssign(long op)
    Set this MPF to the the square root of op.
    sub(MPF op)
    Return an MPF whose value is (this - op).
    Set this MPF to (this - op)
    subAssign(MPF op1, MPF op2)
    Set this MPF to (op1 - op2).
    subUi(long op)
    Return an MPF whose value is (this - op).
    subUiAssign(long op)
    Set this MPF to (this - op)
    subUiAssign(MPF op1, long op2)
    Set this MPF to (op1 - op2).
    swap(MPF op)
    Swap the value of this MPF with the value of op.
    Convert this MPF to its decimal string representation.
    toString(int base)
    Convert this MPF to its string representation in the specified base, or null if the base is not valid.
    toString(int base, long nDigits)
    Convert this MPF to its string representation in the specified base, or null if the base is not valid.
    Return an MPF whose value is this rounded towards zero.
    Set this MPF to its value rounded towards zero.
    Set this MPF to the value of op rounded towards zero.
    uiDiv(long op)
    Return an MPF whose value is (op / this).
    uiDivAssign(long op)
    Set this MPF to (op / this)
    uiDivAssign(long op1, MPF op2)
    Set this MPF to (op1 / op2).
    uiSub(long op)
    Return an MPF whose value is (op - this).
    uiSubAssign(long op)
    Set this MPF to (op - this)
    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.
    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
     

    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 Details

    • serialVersionUID

      private static final long serialVersionUID
      Version for serializability.
      See Also:
    • mpfNative

      private transient MpfT mpfNative
      The pointer to the native mpf_t object.
  • Constructor Details

    • 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:
      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(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:
      NumberFormatException - if either base is not valid or str is not a valid string in the specified base.
    • MPF

      public MPF(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:
      NumberFormatException - if str is not a valid number representation in decimal base.
    • MPF

      public MPF(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 Details

    • 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:
      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(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(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:
      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:
      ArithmeticException - if op is not a finite number.
    • initSet

      public static org.javatuples.Pair<Integer,MPF> initSet(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<Double,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<String,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 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:
      ArithmeticException - if op2 is zero.
    • divAssign

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

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

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

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

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

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

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

      public MPF uiDiv(long op)
      Return an MPF whose value is (op / this).
      Throws:
      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:
      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:
      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(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:
      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(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:
      ArithmeticException - if str is not a valid number representation in decimal base.
      See Also:
    • setValue

      public MPF setValue(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 Comparable<MPF>
    • equals

      public boolean equals(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 Object
    • hashCode

      public int hashCode()
      Return a hash code value for this MPF.
      Overrides:
      hashCode in class 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 Number
    • intValue

      public int intValue()
      Convert this MPF to an int.
      Specified by:
      intValue in class 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 Number
    • floatValue

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

      public 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:
      IllegalArgumentException - if the base is not valid.
    • toString

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

      private void writeObject(ObjectOutputStream out) throws IOException
      Throws:
      IOException
    • readObject

      private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
      Throws:
      IOException
      ClassNotFoundException
    • readObjectNoData

      private void readObjectNoData() throws ObjectStreamException
      Throws:
      ObjectStreamException