Package gmp

Class Mpfr

All Implemented Interfaces:
Serializable, Cloneable, Comparable<Mpfr>

public class Mpfr extends Object implements Serializable, Comparable<Mpfr>, Cloneable
MPFR multi-precision floating-point numbers.

This class wraps mpfr_t MPFR objects.

The precision of each number is set at construction time and not changed when the number is modified (except by setPrec(int) or set(Mpfr)). Thus, most operators entail rounding. Such operators take as (last) argument a rounding direction that can be RNDN, RNDZ, RNDU, or RNDD).

Most operators return an integer that tells whether the stored result is exact (zero returned), over-approximated (positive number returned), or under-approximated (negative number returned).

In addition, the class has some global (static) exception flags that can be set by methods to denote IEEE 754 exceptions, and then inspected and reset by the user: overflow, underflow, NaN, inexact, and erange (invalid range) flags (these do not cause Java exceptions to be thrown).

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Rounds toward minus infinity.
    static final int
    Rounds to nearest.
    static final int
    Rounds toward plus infinity.
    static final int
    Rounds toward zero.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new number with the default precision.
    Mpfr(double v, int round)
    Constructs a float with the default precision equal to a double (with rounding).
    Mpfr(int prec)
    Constructs a new number with exactly prec bits of precision.
    Mpfr(int v, int round)
    Constructs a float with the default precision equal to an integer (with rounding).
    Constructs a copy of v, with the same precision as v.
    Mpfr(Mpfr v, int round)
    Constructs a copy of v, rounded to the default precision.
    Mpfr(Mpq v, int round)
    Constructs a float with the default precision equal to a fraction (with rounding).
    Mpfr(Mpz v, int round)
    Constructs a float with the default precision equal to an integer (with rounding).
    Mpfr(String s, int round)
    Constructs a float with the default precision equal to the number represented in the decimal String s (with rounding).
    Mpfr(String s, int b, int round)
    Constructs a float with the default precision equal to the number represented in the String s in base b (with rounding).
    Mpfr(BigInteger v, int round)
    Constructs a float with the default precision equal to an integer (with rounding).
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    abs(int round)
    Takes the absolute value of this.
    int
    abs(Mpfr op, int round)
    Sets this to |op|.
    int
    acos(Mpfr op, int round)
    Sets this to the arc-cosine of op.
    int
    acosh(Mpfr op, int round)
    Sets this to the hyperbolic arc-cosine of op.
    int
    add(double op, int round)
    Adds op to this.
    int
    add(int op, int round)
    Adds op to this.
    int
    add(Mpfr op1, double op2, int round)
    Sets this to op1+op2.
    int
    add(Mpfr op, int round)
    Adds op to this.
    int
    add(Mpfr op1, int op2, int round)
    Sets this to op1+op2.
    int
    add(Mpfr op1, Mpfr op2, int round)
    Sets this to op1+op2.
    int
    add(Mpfr op1, Mpq op2, int round)
    Sets this to op1+op2.
    int
    add(Mpfr op1, Mpz op2, int round)
    Sets this to op1+op2.
    int
    add(Mpq op, int round)
    Adds op to this.
    int
    add(Mpz op, int round)
    Adds op to this.
    int
    agm(Mpfr op1, Mpfr op2, int round)
    Sets this to the arithmetic-geometric mean of op1 and op2.
    int
    asin(Mpfr op, int round)
    Sets this to the arc-sine of op.
    int
    asinh(Mpfr op, int round)
    Sets this to the hyperbolic arc-sine of op.
    int
    atan(Mpfr op, int round)
    Sets this to the arc-tangent of op.
    int
    atan2(Mpfr y, Mpfr x, int round)
    Sets this to the arc-tangent2 of y and x.
    int
    atanh(Mpfr op, int round)
    Sets this to the hyperbolic arc-tangent of op.
    boolean
    canRound(int err, int round1, int round2, int prec)
    Whether this can be rounded without loss of precision.
    int
    cbrt(int round)
    Takes the cubic root of this.
    int
    cbrt(Mpfr op, int round)
    Sets this to the cubic root of op.
    int
    ceil(Mpfr op)
    Stores into this, op rounded to the next representable integer.
    int
    checkRange(int t, int round)
    Forces this to be in the current range of acceptable values.
    static void
    Clears the erange (invalid range) flag.
    static void
    Clears the inexact flag.
    static void
    Clears the invalid flag.
    static void
    Clears the overflow flag.
    static void
    Clears the underflow flag.
    Creates a new Mpfr initialized with the value of this.
    int
    cmp(double op)
    Compares this to op.
    int
    cmp(int op)
    Compares this to op.
    int
    cmp(Mpfr op)
    Compares this to op.
    int
    cmp(Mpq op)
    Compares this to op.
    int
    cmp(Mpz op)
    Compares this to op.
    int
    cmp2exp(int op, int e)
    Compares this to op*2^e.
    int
    Compares |this| to |op|.
    int
    Compare the value of this and x.
    int
    constCatalan(int round)
    Sets this to Catalan's constant.
    int
    constEuler(int round)
    Sets this to Euler's constant.
    int
    constLog2(int round)
    Sets this to the constant log(2).
    int
    constPi(int round)
    Sets this to the constant pi.
    int
    copySign(Mpfr op1, Mpfr op2, int round)
    Sets this to op1 (rounded), and then sets the bit-sign of this to that of op2.
    int
    cos(Mpfr op, int round)
    Sets this to the cosine of op.
    int
    cosh(Mpfr op, int round)
    Sets this to the hyperbolic cosine of op.
    int
    cot(Mpfr op, int round)
    Sets this to the cotangent of op.
    int
    coth(Mpfr op, int round)
    Sets this to the hyperbolic cotangent of op.
    int
    csc(Mpfr op, int round)
    Sets this to the cosecant op.
    int
    csch(Mpfr op, int round)
    Sets this to the hyperbolic cosecant op.
    int
    dim(Mpfr op1, Mpfr op2, int round)
    Sets this to max(0, op1-op2).
    int
    div(double op, int round)
    Divides this by op.
    int
    div(double op1, Mpfr op2, int round)
    Sets this to op1/op2.
    int
    div(int op, int round)
    Divides this by op.
    int
    div(int op1, Mpfr op2, int round)
    Sets this to op1/op2.
    int
    div(Mpfr op1, double op2, int round)
    Sets this to op1/op2.
    int
    div(Mpfr op, int round)
    Divides this by op.
    int
    div(Mpfr op1, int op2, int round)
    Sets this to op1/op2.
    int
    div(Mpfr op1, Mpfr op2, int round)
    Sets this to op1/op2.
    int
    div(Mpfr op1, Mpq op2, int round)
    Sets this to op1/op2.
    int
    div(Mpfr op1, Mpz op2, int round)
    Sets this to op1/op2.
    int
    div(Mpq op, int round)
    Divides this by op.
    int
    div(Mpz op, int round)
    Divides this by op.
    int
    div2exp(int op, int round)
    Divides this by 2^op.
    int
    div2exp(Mpfr op1, int op2, int round)
    Sets this to op1/(2^op2).
    int
    divRev(double op, int round)
    Stores op/this into this.
    int
    divRev(int op, int round)
    Stores op/this into this.
    double
    doubleExponentValue(int[] r, int round)
    Converts the integer to a mantissa and exponent.
    double
    doubleValue(int round)
    Returns this as a double (with rounding).
    int
    eint(Mpfr op, int round)
    Sets this to the exponential integral of op.
    boolean
    Whether x is a Mpfr and has the same value as this.
    int
    erf(Mpfr op, int round)
    Sets this to the value of the error function at op.
    int
    erfc(Mpfr op, int round)
    Sets this to the value of the complementary error function at op.
    int
    exp(Mpfr op, int round)
    Sets this to e^op.
    int
    exp10(Mpfr op, int round)
    Sets this to 10^op.
    int
    exp2(Mpfr op, int round)
    Sets this to 2^op.
    int
    expm1(Mpfr op, int round)
    Sets this to exp(op-1).
    int
    fac(int i, int round)
    Sets this to i!.
    boolean
    fitsInt(int round)
    Whether this converted to integer (with rounding) fits in an int.
    int
    floor(Mpfr op)
    Stores into this, op rounded to the previous representable integer.
    int
    fma(Mpfr op1, Mpfr op2, Mpfr op3, int round)
    Sets this to (op1*op2)+op3.
    int
    fmod(Mpfr x, Mpfr y, int round)
    Sets this to x-y*trunc(x/y).
    int
    fms(Mpfr op1, Mpfr op2, Mpfr op3, int round)
    Sets this to (op1*op2)-op3.
    int
    frac(Mpfr op, int round)
    Stores into this, the fractional part of op with the same sign as op, and rounded.
    static void
    Free various caches used internally to compute functions and constants.
    int
    gamma(Mpfr op, int round)
    Sets this to the value of the Gamma function at op.
    static int
    Returns the default precision, in bits.
    static long
    Returns the current largest exponent allowed for a floating-point variable.
    static long
    Returns the largest value allowed in setEmax(long).
    static long
    Returns the smallest value allowed in setEmax(long).
    static long
    Returns the current smallest exponent allowed for a floating-point variable.
    static long
    Returns the largest value allowed in setEmin(long).
    static long
    Returns the smallest value allowed in setEmin(long).
    int
    Returns the exponent of this.
    static String
    Returns the ids of the patches applied to the MPFR library.
    int
    Returns the precision of this, in bits.
    static String
    Returns the MPFR version.
    int
    Returns a hash of the value of this.
    int
    hypot(Mpfr y, Mpfr x, int round)
    Sets this to the Euclidean norm of x and y.
    int
    intValue(int round)
    Returns this as an integer (with rounding).
    boolean
    Whether this == op.
    static boolean
    Returns the erange (invalid range) flag.
    boolean
    Whether this > op.
    boolean
    Whether this >= op.
    static boolean
    Returns the inexact flag.
    boolean
    Returns true if this is an infinity.
    boolean
    Whether this is an integer.
    boolean
    Whether this < op.
    boolean
    Whether this <= op.
    boolean
    Whether this < op or this > op.
    boolean
    Returns true if this is a NaN.
    static boolean
    Returns the invalid flag.
    boolean
    Returns true if this is a regular number (non-infinity or NaN).
    static boolean
    Returns the overflow flag.
    boolean
    Whether this and x have the same address in memory.
    static boolean
    Returns the underflow flag.
    boolean
    Whether this or op is a NaN.
    boolean
    Returns true if this is +0 or -0.
    int
    j0(Mpfr op, int round)
    Sets this to the value of the first kind Bessel function of order 0 at op.
    int
    j1(Mpfr op, int round)
    Sets this to the value of the first kind Bessel function of order 1 at op.
    int
    jn(int n, Mpfr op, int round)
    Sets this to the value of the first kind Bessel function of order n at op.
    int
    lgamma(int[] sign, Mpfr op, int round)
    Sets this to the logarithm of the absolute value of the Gamma function at op.
    int
    li2(Mpfr op, int round)
    Sets this to the real part of the dilogarithm of op.
    int
    lngamma(Mpfr op, int round)
    Sets this to the logarithm of the value of the Gamma function at op.
    int
    log(Mpfr op, int round)
    Sets this to the natural logarithm of op.
    int
    log10(Mpfr op, int round)
    Sets this to the logarithm in base 10 of op.
    int
    log1p(Mpfr op, int round)
    Sets this to log(1+op).
    int
    log2(Mpfr op, int round)
    Sets this to the logarithm in base 2 of op.
    int
    max(Mpfr op1, Mpfr op2, int round)
    Sets this to the maximum of op1 and op2.
    int
    min(Mpfr op1, Mpfr op2, int round)
    Sets this to the minimum of op1 and op2.
    int
    modf(Mpfr f, Mpfr op, int round)
    Sets this to the integral part of op, and f to its fractional part.
    int
    Converts exactly this to the form v*2^e, where v is an integer.
    MpzValue(int round)
    Converts this to an integer (with rounding) and returns it.
    int
    mul(double op, int round)
    Multiplies op by this.
    int
    mul(int op, int round)
    Multiplies op by this.
    int
    mul(Mpfr op1, double op2, int round)
    Sets this to op1*op2.
    int
    mul(Mpfr op, int round)
    Multiplies op by this.
    int
    mul(Mpfr op1, int op2, int round)
    Sets this to op1*op2.
    int
    mul(Mpfr op1, Mpfr op2, int round)
    Sets this to op1*op2.
    int
    mul(Mpfr op1, Mpq op2, int round)
    Sets this to op1*op2.
    int
    mul(Mpfr op1, Mpz op2, int round)
    Sets this to op1*op2.
    int
    mul(Mpq op, int round)
    Multiplies op by this.
    int
    mul(Mpz op, int round)
    Multiplies op by this.
    int
    mul2exp(int op, int round)
    Multiplies this by 2^op.
    int
    mul2exp(Mpfr op1, int op2, int round)
    Sets this to op1*(2^op2).
    int
    neg(int round)
    Negates this.
    int
    neg(Mpfr op, int round)
    Sets this to -op.
    void
    Sets this to the representable float following x.
    void
    Sets this to the representable float preceding x.
    void
    Sets this to the next representable float following x in the direction of y.
    int
    pow(Mpfr op1, int op2, int round)
    Stores op1^op2 into this.
    int
    pow(Mpfr op1, Mpfr op2, int round)
    Stores op1^op2 into this.
    int
    pow(Mpfr op1, Mpz op2, int round)
    Stores op1^op2 into this.
    int
    precRound(int prec, int round)
    Rounds this to prec bits and changes its precision.
    int
    Stores into this a uniformly distributed random number in [0, 1].
    int
    recSqrt(int round)
    Takes the inverted square root of this.
    int
    recSqrt(Mpfr op, int round)
    Sets this to the inverted square root of op.
    int
    remainder(Mpfr x, Mpfr y, int round)
    Sets this to x-y*round(x/y).
    int
    remquo(int[] q, Mpfr x, Mpfr y, int round)
    Sets this to x-y*round(x/y).
    int
    rint(Mpfr op, int round)
    Stores into this, op rounded to the nearest representable integer for the given rounding mode.
    int
    rint_ceil(Mpfr op, int round)
    Stores into this, the integer following op, then rounded.
    int
    rint_floor(Mpfr op, int round)
    Stores into this, the integer preceding op, then rounded.
    int
    rint_round(Mpfr op, int round)
    Stores into this, the integer nearest op, then rounded.
    int
    rint_trunc(Mpfr op, int round)
    Stores into this, op truncated to an integer, then rounded.
    int
    root(int k, int round)
    Takes the k-th root of this.
    int
    root(Mpfr op, int k, int round)
    Sets this to the k-th root of op.
    int
    round(Mpfr op)
    Stores into this, op rounded to the nearest representable integer.
    int
    sec(Mpfr op, int round)
    Sets this to the secant of op.
    int
    sech(Mpfr op, int round)
    Sets this to the hyperbolic secant of op.
    int
    set(double v, int round)
    Sets this to a double (with rounding).
    int
    set(int v, int round)
    Sets this to an integer (with rounding).
    int
    set(int v, int e, int round)
    Sets this to a v*2^e (with rounding).
    void
    set(Mpfr v)
    Copies v into this, changing the precision of this to match that of v.
    int
    set(Mpfr v, int round)
    Copies v into this (with rounding).
    int
    set(Mpq v, int round)
    Sets this to a fraction (with rounding).
    int
    set(Mpz v, int round)
    Sets this to an integer (with rounding).
    void
    set(String s, int round)
    Sets this to the number represented in the decimal String s (with rounding).
    void
    set(String s, int b, int round)
    Sets this to the number represented in the String s in base b (with rounding).
    int
    set(BigInteger v, int round)
    Sets this to an integer (with rounding).
    static void
    setDefaultPrec(int prec)
    Sets the default precision to exactly prec bits.
    static boolean
    setEmax(long exp)
    Sets the current largest exponent allowed for a for a floating-point variable.
    static boolean
    setEmin(long exp)
    Sets the current smallest exponent allowed for a for a floating-point variable.
    static void
    Sets the erange (invalid range) flag.
    boolean
    setExp(int e)
    Sets the exponent of this to e.
    static void
    Sets the inexact flag.
    void
    setInf(int sign)
    Sets this to a signed infinity.
    void
    Sets this to NaN.
    static void
    Sets the invalid flag.
    static void
    Sets the overflow flag.
    void
    setPrec(int prec)
    Changes the precision of this to exactly prec bits.
    int
    setSign(Mpfr op, boolean s, int round)
    Sets this to op (rounded) and then sets the bit-sign of this to s.
    static void
    Sets the underflow flag.
    int
    sgn()
    Returns a positive value if this is positive, negative if this is negative, and null if this is zero or NaN.
    boolean
    Returns true if this has its sign bit set.
    int
    sin(Mpfr op, int round)
    Sets this to the sine of op.
    int
    sinCos(Mpfr c, Mpfr op, int round)
    Sets this to the sine of op, and c to its cosine.
    int
    sinh(Mpfr op, int round)
    Sets this to the hyperbolic sine of op.
    int
    sinhCosh(Mpfr c, Mpfr op, int round)
    Sets this to the hyperbolic sine of op, and c to its hyperbolic cosine.
    int
    sqrt(int round)
    Takes the square root of this.
    int
    sqrt(int op, int round)
    Sets this to the square root of op.
    int
    sqrt(Mpfr op, int round)
    Sets this to the square root of op.
    int
    sub(double op, int round)
    Subtracts op from this.
    int
    sub(double op1, Mpfr op2, int round)
    Sets this to op1-op2.
    int
    sub(int op, int round)
    Subtracts op from this.
    int
    sub(int op1, Mpfr op2, int round)
    Sets this to op1-op2.
    int
    sub(Mpfr op1, double op2, int round)
    Sets this to op1-op2.
    int
    sub(Mpfr op, int round)
    Subtracts op from this.
    int
    sub(Mpfr op1, int op2, int round)
    Sets this to op1-op2.
    int
    sub(Mpfr op1, Mpfr op2, int round)
    Sets this to op1-op2.
    int
    sub(Mpfr op1, Mpq op2, int round)
    Sets this to op1-op2.
    int
    sub(Mpfr op1, Mpz op2, int round)
    Sets this to op1-op2.
    int
    sub(Mpq op, int round)
    Subtracts op from this.
    int
    sub(Mpz op, int round)
    Subtracts op from this.
    int
    subNormalize(int t, int round)
    Rounds this to emulate subnormal arithmetic.
    int
    subRev(double op, int round)
    Stores op-this into this.
    int
    subRev(int op, int round)
    Stores op-this into this.
    int
    sum(Mpfr[] ar, int round)
    Stores into this the sum of an array or Mpfr (correctly rounded).
    int
    tan(Mpfr op, int round)
    Sets this to the tangent of op.
    Returns a String representation of this in base 10 (rounding to nearest).
    toString(int b, int n, int round)
    Returns a String representation (with rounding).
    static String
    toStringRndMode(int round)
    Returns the name of the rounding mode.
    int
    trunc(Mpfr op)
    Stores into this, op truncated to a representable integer.
    int
    y0(Mpfr op, int round)
    Sets this to the value of the second kind Bessel function of order 0 at op.
    int
    y1(Mpfr op, int round)
    Sets this to the value of the second kind Bessel function of order 1 at op.
    int
    yn(int n, Mpfr op, int round)
    Sets this to the value of the second kind Bessel function of order n at op.
    int
    zeta(int op, int round)
    Sets this to the value of the Riemann Zeta function at op.
    int
    zeta(Mpfr op, int round)
    Sets this to the value of the Riemann Zeta function at op.

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • Mpfr

      public Mpfr()
      Constructs a new number with the default precision.

      It is set to NaN.

    • Mpfr

      public Mpfr(int prec)
      Constructs a new number with exactly prec bits of precision.

      It is set to NaN.

    • Mpfr

      public Mpfr(Mpfr v)
      Constructs a copy of v, with the same precision as v.
    • Mpfr

      public Mpfr(Mpfr v, int round)
      Constructs a copy of v, rounded to the default precision.
    • Mpfr

      public Mpfr(int v, int round)
      Constructs a float with the default precision equal to an integer (with rounding).
    • Mpfr

      public Mpfr(BigInteger v, int round)
      Constructs a float with the default precision equal to an integer (with rounding).
    • Mpfr

      public Mpfr(Mpz v, int round)
      Constructs a float with the default precision equal to an integer (with rounding).
    • Mpfr

      public Mpfr(double v, int round)
      Constructs a float with the default precision equal to a double (with rounding).
    • Mpfr

      public Mpfr(Mpq v, int round)
      Constructs a float with the default precision equal to a fraction (with rounding).
    • Mpfr

      public Mpfr(String s, int b, int round)
      Constructs a float with the default precision equal to the number represented in the String s in base b (with rounding).
    • Mpfr

      public Mpfr(String s, int round)
      Constructs a float with the default precision equal to the number represented in the decimal String s (with rounding).
  • Method Details

    • clone

      public Mpfr clone() throws CloneNotSupportedException
      Creates a new Mpfr initialized with the value of this.
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException
    • setDefaultPrec

      public static void setDefaultPrec(int prec)
      Sets the default precision to exactly prec bits.

      This only affects objects created after the call.

      The default is 53 bits initially (i.e., same as double precision IEEE floats).

    • getDefaultPrec

      public static int getDefaultPrec()
      Returns the default precision, in bits.
    • setPrec

      public void setPrec(int prec)
      Changes the precision of this to exactly prec bits.

      The value of this is lost and set to NaN.

    • getPrec

      public int getPrec()
      Returns the precision of this, in bits.
    • set

      public int set(Mpfr v, int round)
      Copies v into this (with rounding).
    • set

      public void set(Mpfr v)
      Copies v into this, changing the precision of this to match that of v.
    • set

      public int set(int v, int round)
      Sets this to an integer (with rounding).
    • set

      public int set(int v, int e, int round)
      Sets this to a v*2^e (with rounding).
    • set

      public int set(BigInteger v, int round)
      Sets this to an integer (with rounding).
    • set

      public int set(Mpz v, int round)
      Sets this to an integer (with rounding).
    • set

      public int set(double v, int round)
      Sets this to a double (with rounding).
    • set

      public int set(Mpq v, int round)
      Sets this to a fraction (with rounding).
    • set

      public void set(String s, int b, int round)
      Sets this to the number represented in the String s in base b (with rounding).
    • set

      public void set(String s, int round)
      Sets this to the number represented in the decimal String s (with rounding).
    • setInf

      public void setInf(int sign)
      Sets this to a signed infinity.
    • setNaN

      public void setNaN()
      Sets this to NaN.
    • intValue

      public int intValue(int round)
      Returns this as an integer (with rounding).
      See Also:
    • doubleValue

      public double doubleValue(int round)
      Returns this as a double (with rounding).
    • doubleExponentValue

      public double doubleExponentValue(int[] r, int round)
      Converts the integer to a mantissa and exponent.

      The mantissa m returned is such that 0.5 <= |m| < 1, rounded to fit double.

      The exponent is stored into r[0].

    • MpzValue

      public Mpz MpzValue(int round)
      Converts this to an integer (with rounding) and returns it.
    • MpzExponentValue

      public int MpzExponentValue(Mpz r)
      Converts exactly this to the form v*2^e, where v is an integer.

      v is stored into r while e is returned.

    • toString

      public String toString(int b, int n, int round)
      Returns a String representation (with rounding).

      b is the base, between 2 and 62.

      n is the number of digits to output, or 0 to denote sufficient precision so that it is possible to recover the original value when parsing using rounding to nearest.

    • toString

      public String toString()
      Returns a String representation of this in base 10 (rounding to nearest).
      Overrides:
      toString in class Object
    • fitsInt

      public boolean fitsInt(int round)
      Whether this converted to integer (with rounding) fits in an int.
    • add

      public int add(Mpfr op1, Mpfr op2, int round)
      Sets this to op1+op2.
    • add

      public int add(Mpfr op1, int op2, int round)
      Sets this to op1+op2.
    • add

      public int add(Mpfr op1, double op2, int round)
      Sets this to op1+op2.
    • add

      public int add(Mpfr op1, Mpz op2, int round)
      Sets this to op1+op2.
    • add

      public int add(Mpfr op1, Mpq op2, int round)
      Sets this to op1+op2.
    • add

      public int add(Mpfr op, int round)
      Adds op to this.
    • add

      public int add(int op, int round)
      Adds op to this.
    • add

      public int add(double op, int round)
      Adds op to this.
    • add

      public int add(Mpz op, int round)
      Adds op to this.
    • add

      public int add(Mpq op, int round)
      Adds op to this.
    • sub

      public int sub(Mpfr op1, Mpfr op2, int round)
      Sets this to op1-op2.
    • sub

      public int sub(Mpfr op1, int op2, int round)
      Sets this to op1-op2.
    • sub

      public int sub(Mpfr op1, double op2, int round)
      Sets this to op1-op2.
    • sub

      public int sub(Mpfr op1, Mpz op2, int round)
      Sets this to op1-op2.
    • sub

      public int sub(Mpfr op1, Mpq op2, int round)
      Sets this to op1-op2.
    • sub

      public int sub(int op1, Mpfr op2, int round)
      Sets this to op1-op2.
    • sub

      public int sub(double op1, Mpfr op2, int round)
      Sets this to op1-op2.
    • sub

      public int sub(Mpfr op, int round)
      Subtracts op from this.
    • sub

      public int sub(int op, int round)
      Subtracts op from this.
    • sub

      public int sub(double op, int round)
      Subtracts op from this.
    • sub

      public int sub(Mpz op, int round)
      Subtracts op from this.
    • sub

      public int sub(Mpq op, int round)
      Subtracts op from this.
    • subRev

      public int subRev(int op, int round)
      Stores op-this into this.
    • subRev

      public int subRev(double op, int round)
      Stores op-this into this.
    • mul

      public int mul(Mpfr op1, Mpfr op2, int round)
      Sets this to op1*op2.
    • mul

      public int mul(Mpfr op1, int op2, int round)
      Sets this to op1*op2.
    • mul

      public int mul(Mpfr op1, double op2, int round)
      Sets this to op1*op2.
    • mul

      public int mul(Mpfr op1, Mpz op2, int round)
      Sets this to op1*op2.
    • mul

      public int mul(Mpfr op1, Mpq op2, int round)
      Sets this to op1*op2.
    • mul

      public int mul(Mpfr op, int round)
      Multiplies op by this.
    • mul

      public int mul(int op, int round)
      Multiplies op by this.
    • mul

      public int mul(double op, int round)
      Multiplies op by this.
    • mul

      public int mul(Mpz op, int round)
      Multiplies op by this.
    • mul

      public int mul(Mpq op, int round)
      Multiplies op by this.
    • div

      public int div(Mpfr op1, Mpfr op2, int round)
      Sets this to op1/op2.
    • div

      public int div(Mpfr op1, int op2, int round)
      Sets this to op1/op2.
    • div

      public int div(Mpfr op1, double op2, int round)
      Sets this to op1/op2.
    • div

      public int div(Mpfr op1, Mpz op2, int round)
      Sets this to op1/op2.
    • div

      public int div(Mpfr op1, Mpq op2, int round)
      Sets this to op1/op2.
    • div

      public int div(int op1, Mpfr op2, int round)
      Sets this to op1/op2.
    • div

      public int div(double op1, Mpfr op2, int round)
      Sets this to op1/op2.
    • div

      public int div(Mpfr op, int round)
      Divides this by op.
    • div

      public int div(int op, int round)
      Divides this by op.
    • div

      public int div(double op, int round)
      Divides this by op.
    • div

      public int div(Mpz op, int round)
      Divides this by op.
    • div

      public int div(Mpq op, int round)
      Divides this by op.
    • divRev

      public int divRev(int op, int round)
      Stores op/this into this.
    • divRev

      public int divRev(double op, int round)
      Stores op/this into this.
    • sqrt

      public int sqrt(Mpfr op, int round)
      Sets this to the square root of op.
    • sqrt

      public int sqrt(int round)
      Takes the square root of this.
    • sqrt

      public int sqrt(int op, int round)
      Sets this to the square root of op.
    • recSqrt

      public int recSqrt(Mpfr op, int round)
      Sets this to the inverted square root of op.
    • recSqrt

      public int recSqrt(int round)
      Takes the inverted square root of this.
    • cbrt

      public int cbrt(Mpfr op, int round)
      Sets this to the cubic root of op.
    • cbrt

      public int cbrt(int round)
      Takes the cubic root of this.
    • root

      public int root(Mpfr op, int k, int round)
      Sets this to the k-th root of op.

      k must be positive.

    • root

      public int root(int k, int round)
      Takes the k-th root of this.

      k must be positive.

    • pow

      public int pow(Mpfr op1, Mpfr op2, int round)
      Stores op1^op2 into this.
    • pow

      public int pow(Mpfr op1, int op2, int round)
      Stores op1^op2 into this.
    • pow

      public int pow(Mpfr op1, Mpz op2, int round)
      Stores op1^op2 into this.
    • neg

      public int neg(Mpfr op, int round)
      Sets this to -op.
    • neg

      public int neg(int round)
      Negates this.
    • abs

      public int abs(Mpfr op, int round)
      Sets this to |op|.
    • abs

      public int abs(int round)
      Takes the absolute value of this.
    • dim

      public int dim(Mpfr op1, Mpfr op2, int round)
      Sets this to max(0, op1-op2).
    • mul2exp

      public int mul2exp(Mpfr op1, int op2, int round)
      Sets this to op1*(2^op2).
    • mul2exp

      public int mul2exp(int op, int round)
      Multiplies this by 2^op.
    • div2exp

      public int div2exp(Mpfr op1, int op2, int round)
      Sets this to op1/(2^op2).
    • div2exp

      public int div2exp(int op, int round)
      Divides this by 2^op.
    • cmp

      public int cmp(Mpfr op)
      Compares this to op.

      Returns a strictly positive, null, or negative number when this is respectively strictly greater, equal, or strictly smalled than op.

      A NaN causes erange to be set and 0 to be returned.

    • cmp

      public int cmp(int op)
      Compares this to op.

      Returns a strictly positive, null, or negative number when this is respectively strictly greater, equal, or strictly smalled than op.

      A NaN causes erange to be set and 0 to be returned.

    • cmp

      public int cmp(double op)
      Compares this to op.

      Returns a strictly positive, null, or negative number when this is respectively strictly greater, equal, or strictly smalled than op.

      A NaN causes erange to be set and 0 to be returned.

    • cmp

      public int cmp(Mpz op)
      Compares this to op.

      Returns a strictly positive, null, or negative number when this is respectively strictly greater, equal, or strictly smalled than op.

      A NaN causes erange to be set and 0 to be returned.

    • cmp

      public int cmp(Mpq op)
      Compares this to op.

      Returns a strictly positive, null, or negative number when this is respectively strictly greater, equal, or strictly smalled than op.

      A NaN causes erange to be set and 0 to be returned.

    • cmp2exp

      public int cmp2exp(int op, int e)
      Compares this to op*2^e.

      Returns a strictly positive, null, or negative number when this is respectively strictly greater, equal, or strictly smalled than op*2^e.

      A NaN causes erange to be set and 0 to be returned.

    • cmpAbs

      public int cmpAbs(Mpfr op)
      Compares |this| to |op|.
    • isNaN

      public boolean isNaN()
      Returns true if this is a NaN.
    • isInf

      public boolean isInf()
      Returns true if this is an infinity.
    • isNumber

      public boolean isNumber()
      Returns true if this is a regular number (non-infinity or NaN).
    • isZero

      public boolean isZero()
      Returns true if this is +0 or -0.
    • sgn

      public int sgn()
      Returns a positive value if this is positive, negative if this is negative, and null if this is zero or NaN.
    • isGreater

      public boolean isGreater(Mpfr op)
      Whether this > op.

      false if any operand is NaN.

    • isGreaterEqual

      public boolean isGreaterEqual(Mpfr op)
      Whether this >= op.

      false if any operand is NaN.

    • isLess

      public boolean isLess(Mpfr op)
      Whether this < op.

      false if any operand is NaN.

    • isLessEqual

      public boolean isLessEqual(Mpfr op)
      Whether this <= op.

      false if any operand is NaN.

    • isLessGreater

      public boolean isLessGreater(Mpfr op)
      Whether this < op or this > op.

      false if any operand is NaN.

    • isEqual

      public boolean isEqual(Mpfr op)
      Whether this == op.

      false if any operand is NaN: we have NaN!=NaN.

    • isUnordered

      public boolean isUnordered(Mpfr op)
      Whether this or op is a NaN.
    • equals

      public boolean equals(Object x)
      Whether x is a Mpfr and has the same value as this.

      This compares representations, and so, NaN is assumed equal to NaN (unlike isEqual(gmp.Mpfr) that follows the IEEE 754 convention).

      Overrides:
      equals in class Object
    • compareTo

      public int compareTo(Mpfr x)
      Compare the value of this and x.
      Specified by:
      compareTo in interface Comparable<Mpfr>
      See Also:
    • hashCode

      public int hashCode()
      Returns a hash of the value of this.
      Overrides:
      hashCode in class Object
    • isPhysicalEqual

      public boolean isPhysicalEqual(Mpfr x)
      Whether this and x have the same address in memory.
    • log

      public int log(Mpfr op, int round)
      Sets this to the natural logarithm of op.
    • log2

      public int log2(Mpfr op, int round)
      Sets this to the logarithm in base 2 of op.
    • log10

      public int log10(Mpfr op, int round)
      Sets this to the logarithm in base 10 of op.
    • exp

      public int exp(Mpfr op, int round)
      Sets this to e^op.
    • exp2

      public int exp2(Mpfr op, int round)
      Sets this to 2^op.
    • exp10

      public int exp10(Mpfr op, int round)
      Sets this to 10^op.
    • cos

      public int cos(Mpfr op, int round)
      Sets this to the cosine of op.
    • sin

      public int sin(Mpfr op, int round)
      Sets this to the sine of op.
    • tan

      public int tan(Mpfr op, int round)
      Sets this to the tangent of op.
    • sec

      public int sec(Mpfr op, int round)
      Sets this to the secant of op.
    • csc

      public int csc(Mpfr op, int round)
      Sets this to the cosecant op.
    • cot

      public int cot(Mpfr op, int round)
      Sets this to the cotangent of op.
    • sinCos

      public int sinCos(Mpfr c, Mpfr op, int round)
      Sets this to the sine of op, and c to its cosine.
    • acos

      public int acos(Mpfr op, int round)
      Sets this to the arc-cosine of op.
    • asin

      public int asin(Mpfr op, int round)
      Sets this to the arc-sine of op.
    • atan

      public int atan(Mpfr op, int round)
      Sets this to the arc-tangent of op.
    • atan2

      public int atan2(Mpfr y, Mpfr x, int round)
      Sets this to the arc-tangent2 of y and x.
    • cosh

      public int cosh(Mpfr op, int round)
      Sets this to the hyperbolic cosine of op.
    • sinh

      public int sinh(Mpfr op, int round)
      Sets this to the hyperbolic sine of op.
    • sinhCosh

      public int sinhCosh(Mpfr c, Mpfr op, int round)
      Sets this to the hyperbolic sine of op, and c to its hyperbolic cosine.
    • sech

      public int sech(Mpfr op, int round)
      Sets this to the hyperbolic secant of op.
    • csch

      public int csch(Mpfr op, int round)
      Sets this to the hyperbolic cosecant op.
    • coth

      public int coth(Mpfr op, int round)
      Sets this to the hyperbolic cotangent of op.
    • acosh

      public int acosh(Mpfr op, int round)
      Sets this to the hyperbolic arc-cosine of op.
    • asinh

      public int asinh(Mpfr op, int round)
      Sets this to the hyperbolic arc-sine of op.
    • atanh

      public int atanh(Mpfr op, int round)
      Sets this to the hyperbolic arc-tangent of op.
    • fac

      public int fac(int i, int round)
      Sets this to i!.

      i must be positive.

    • log1p

      public int log1p(Mpfr op, int round)
      Sets this to log(1+op).
    • expm1

      public int expm1(Mpfr op, int round)
      Sets this to exp(op-1).
    • eint

      public int eint(Mpfr op, int round)
      Sets this to the exponential integral of op.
    • li2

      public int li2(Mpfr op, int round)
      Sets this to the real part of the dilogarithm of op.
    • gamma

      public int gamma(Mpfr op, int round)
      Sets this to the value of the Gamma function at op.
    • lngamma

      public int lngamma(Mpfr op, int round)
      Sets this to the logarithm of the value of the Gamma function at op.
    • lgamma

      public int lgamma(int[] sign, Mpfr op, int round)
      Sets this to the logarithm of the absolute value of the Gamma function at op.

      Also stores the sign of the value into sign[0].

    • zeta

      public int zeta(Mpfr op, int round)
      Sets this to the value of the Riemann Zeta function at op.
    • zeta

      public int zeta(int op, int round)
      Sets this to the value of the Riemann Zeta function at op.

      op must be positive.

    • erf

      public int erf(Mpfr op, int round)
      Sets this to the value of the error function at op.
    • erfc

      public int erfc(Mpfr op, int round)
      Sets this to the value of the complementary error function at op.
    • j0

      public int j0(Mpfr op, int round)
      Sets this to the value of the first kind Bessel function of order 0 at op.
    • j1

      public int j1(Mpfr op, int round)
      Sets this to the value of the first kind Bessel function of order 1 at op.
    • jn

      public int jn(int n, Mpfr op, int round)
      Sets this to the value of the first kind Bessel function of order n at op.
    • y0

      public int y0(Mpfr op, int round)
      Sets this to the value of the second kind Bessel function of order 0 at op.
    • y1

      public int y1(Mpfr op, int round)
      Sets this to the value of the second kind Bessel function of order 1 at op.
    • yn

      public int yn(int n, Mpfr op, int round)
      Sets this to the value of the second kind Bessel function of order n at op.
    • fma

      public int fma(Mpfr op1, Mpfr op2, Mpfr op3, int round)
      Sets this to (op1*op2)+op3.
    • fms

      public int fms(Mpfr op1, Mpfr op2, Mpfr op3, int round)
      Sets this to (op1*op2)-op3.
    • agm

      public int agm(Mpfr op1, Mpfr op2, int round)
      Sets this to the arithmetic-geometric mean of op1 and op2.
    • hypot

      public int hypot(Mpfr y, Mpfr x, int round)
      Sets this to the Euclidean norm of x and y.
    • constLog2

      public int constLog2(int round)
      Sets this to the constant log(2).
    • constPi

      public int constPi(int round)
      Sets this to the constant pi.
    • constEuler

      public int constEuler(int round)
      Sets this to Euler's constant.
    • constCatalan

      public int constCatalan(int round)
      Sets this to Catalan's constant.
    • freeCache

      public static void freeCache()
      Free various caches used internally to compute functions and constants.
    • sum

      public int sum(Mpfr[] ar, int round)
      Stores into this the sum of an array or Mpfr (correctly rounded).
    • rint

      public int rint(Mpfr op, int round)
      Stores into this, op rounded to the nearest representable integer for the given rounding mode.
    • ceil

      public int ceil(Mpfr op)
      Stores into this, op rounded to the next representable integer.
    • floor

      public int floor(Mpfr op)
      Stores into this, op rounded to the previous representable integer.
    • round

      public int round(Mpfr op)
      Stores into this, op rounded to the nearest representable integer.
    • trunc

      public int trunc(Mpfr op)
      Stores into this, op truncated to a representable integer.
    • rint_ceil

      public int rint_ceil(Mpfr op, int round)
      Stores into this, the integer following op, then rounded.
    • rint_floor

      public int rint_floor(Mpfr op, int round)
      Stores into this, the integer preceding op, then rounded.
    • rint_round

      public int rint_round(Mpfr op, int round)
      Stores into this, the integer nearest op, then rounded.
    • rint_trunc

      public int rint_trunc(Mpfr op, int round)
      Stores into this, op truncated to an integer, then rounded.
    • frac

      public int frac(Mpfr op, int round)
      Stores into this, the fractional part of op with the same sign as op, and rounded.
    • modf

      public int modf(Mpfr f, Mpfr op, int round)
      Sets this to the integral part of op, and f to its fractional part.
    • fmod

      public int fmod(Mpfr x, Mpfr y, int round)
      Sets this to x-y*trunc(x/y).
    • remainder

      public int remainder(Mpfr x, Mpfr y, int round)
      Sets this to x-y*round(x/y).
    • remquo

      public int remquo(int[] q, Mpfr x, Mpfr y, int round)
      Sets this to x-y*round(x/y).

      Stores into q[0] the low bits of the (signed) quotient round(x/y).

    • isInteger

      public boolean isInteger()
      Whether this is an integer.
    • precRound

      public int precRound(int prec, int round)
      Rounds this to prec bits and changes its precision.
    • canRound

      public boolean canRound(int err, int round1, int round2, int prec)
      Whether this can be rounded without loss of precision.

      Assuming that this approximates some number x in the direction round1 with error at most 2^(expb-err), where expb is the exponent of b, returns true if x can be correctly rounded to prec bits in the direction round2. Does not modify this.

    • toStringRndMode

      public static String toStringRndMode(int round)
      Returns the name of the rounding mode.
    • nextToward

      public void nextToward(Mpfr op)
      Sets this to the next representable float following x in the direction of y.
    • nextAbove

      public void nextAbove()
      Sets this to the representable float following x.
    • nextBelow

      public void nextBelow()
      Sets this to the representable float preceding x.
    • min

      public int min(Mpfr op1, Mpfr op2, int round)
      Sets this to the minimum of op1 and op2.
    • max

      public int max(Mpfr op1, Mpfr op2, int round)
      Sets this to the maximum of op1 and op2.
    • getExp

      public int getExp()
      Returns the exponent of this.
    • setExp

      public boolean setExp(int e)
      Sets the exponent of this to e.
    • signBit

      public boolean signBit()
      Returns true if this has its sign bit set.
    • setSign

      public int setSign(Mpfr op, boolean s, int round)
      Sets this to op (rounded) and then sets the bit-sign of this to s.
    • copySign

      public int copySign(Mpfr op1, Mpfr op2, int round)
      Sets this to op1 (rounded), and then sets the bit-sign of this to that of op2.
    • getVersion

      public static String getVersion()
      Returns the MPFR version.
    • getPatches

      public static String getPatches()
      Returns the ids of the patches applied to the MPFR library.
    • getEmin

      public static long getEmin()
      Returns the current smallest exponent allowed for a floating-point variable.
    • getEmax

      public static long getEmax()
      Returns the current largest exponent allowed for a floating-point variable.
    • setEmin

      public static boolean setEmin(long exp)
      Sets the current smallest exponent allowed for a for a floating-point variable.

      Returns true if the change was successful.

    • setEmax

      public static boolean setEmax(long exp)
      Sets the current largest exponent allowed for a for a floating-point variable.

      Returns true if the change was successful.

    • getEminMin

      public static long getEminMin()
      Returns the smallest value allowed in setEmin(long).
    • getEminMax

      public static long getEminMax()
      Returns the largest value allowed in setEmin(long).
    • getEmaxMin

      public static long getEmaxMin()
      Returns the smallest value allowed in setEmax(long).
    • getEmaxMax

      public static long getEmaxMax()
      Returns the largest value allowed in setEmax(long).
    • checkRange

      public int checkRange(int t, int round)
      Forces this to be in the current range of acceptable values.
    • subNormalize

      public int subNormalize(int t, int round)
      Rounds this to emulate subnormal arithmetic.
    • clearUnderflow

      public static void clearUnderflow()
      Clears the underflow flag.
    • clearOverflow

      public static void clearOverflow()
      Clears the overflow flag.
    • clearNaNFlag

      public static void clearNaNFlag()
      Clears the invalid flag.
    • clearInexFlag

      public static void clearInexFlag()
      Clears the inexact flag.
    • clearERangeFlag

      public static void clearERangeFlag()
      Clears the erange (invalid range) flag.
    • setUnderflow

      public static void setUnderflow()
      Sets the underflow flag.
    • setOverflow

      public static void setOverflow()
      Sets the overflow flag.
    • setNaNFlag

      public static void setNaNFlag()
      Sets the invalid flag.
    • setInexFlag

      public static void setInexFlag()
      Sets the inexact flag.
    • setERangeFlag

      public static void setERangeFlag()
      Sets the erange (invalid range) flag.
    • isUnderflow

      public static boolean isUnderflow()
      Returns the underflow flag.
    • isOverflow

      public static boolean isOverflow()
      Returns the overflow flag.
    • isNaNFlag

      public static boolean isNaNFlag()
      Returns the invalid flag.
    • isInexFlag

      public static boolean isInexFlag()
      Returns the inexact flag.
    • isERangeFlag

      public static boolean isERangeFlag()
      Returns the erange (invalid range) flag.
    • random

      public int random(RandState r)
      Stores into this a uniformly distributed random number in [0, 1].