package mlmpfr

  1. Overview
  2. Docs

Module MlmpfrSource

OCaml bindings for MPFR.

A mpfr_float is an immutable data structure that contains a mpfr_t number, as well as an optional ternary value, as provided by (and described in) the MPFR library.

A few distinctions are made from the original C library:

  • the mpfr_ prefix is ommited for all functions;
  • mpfr_init* and mpfr_set* functions are not provided in order to implement these bindings with respect to the functional paradigm (i.e. immutability). Consequently, mpfr_clear* functions are not provided too, and so, the garbage collector is in charge of memory management;
  • functions managing the following types are not supported: unsigned long int, uintmax_t, intmax_t, float, long double, __float128, _Decimal64, _Decimal128, mpz_t, mpq_t, and mpf_t. Except for mpfr_sqrt_ui and mpfr_fac_ui which are partially supported on the range of the positive values of an OCaml signed integer. In fact, only the OCaml native types (int, float, and string) are supported, assuming that a float is a double-precision floating-point number and an int is a 64-bits signed integer. Thus, all functions named with *_ui* or *_d* are renamed here with *_int* or *_float*, respectively;
  • bindings to functions mpfr_*printf, mpfr_*random*, mpfr_get_patches, mpfr_buildopt_*, and, macros MPFR_VERSION*, mpfr_round_nearest_away are not implemented.

In the sequel, if not provided, optional parameters prec and rnd are set to MPFR's defaults precision and rounding mode. Functions which take a precision, or a base as a parameter raise exceptions. See Precision_range and Base_range.

Some of the comments below are derived from the MPFR documentation itself. Nevertheless, please refer to the original documentation for further explanations.

Sourceexception Precision_range of int

Raised if precision is not included in [Mlmpfr.mpfr_prec_min; Mlmpfr.mpfr_prec_max].

Sourceexception Base_range of int

Raised if base is not included in [2;64], or 0 (automatic base detection).

Sourceexception Error of string

Raised if mlmpfr fails to perfom some internal mpfr_t copies.

Sourceexception Invalid_integer_input of int

Raised if mlmpfr tries to call a mpfr_*_ui function with a negative integer.

Sourcetype sign =
  1. | Positive
  2. | Negative
Sourcetype mpfr_t

Binding to C MPFR mpfr_t type.

Sourcetype ternary =
  1. | Correct_Rounding
  2. | Greater
  3. | Lower

Associated to an mpfr_t value, a ternary value indicates if it was correctly rounded.

Sourcetype mpfr_float = mpfr_t * ternary option
Sourcetype mpfr_rnd_t =
  1. | To_Nearest
  2. | Toward_Zero
  3. | Toward_Plus_Infinity
  4. | Toward_Minus_Infinity
  5. | Away_From_Zero
  6. | Faithful

Rounding modes.

Sourcetype mpfr_flags_t =
  1. | Underflow
  2. | Overflow
  3. | Nan
  4. | Inexact
  5. | Erange
  6. | Divby0
  7. | All

Flags as described here.

Sourceval mpfr_prec_min : int

Minimum allowed precision.

Sourceval mpfr_prec_max : int

Maximum allowed precision.

Initialization

Sourceval set_default_prec : int -> unit

Mlmpfr.set_default_prec p modifies the default precision to be exactly p bits. The precision of a variable means the number of bits used to store its significand. All subsequent calls to any functions will use this precision by default, but previously initialized variables are unaffected. The default precision is set to 53 bits initially.

Sourceval get_default_prec : unit -> int

Return the current default MPFR precision in bits.

Sourceval get_prec : mpfr_float -> int

Mlmpfr.get_prec x returns the precision of x. The corresponding Mlmpfr.set_prec x prec function is not allowed, use Mlmpfr.make_from_mpfr ~prec:prec x instead.

Assignment

Sourceval make_from_mpfr : ?prec:int -> ?rnd:mpfr_rnd_t -> mpfr_float -> mpfr_float

Return a fresh mpfr_float number of precision ~prec (optional), made from another mpfr_float number, in direction ~rnd (optional).

Sourceval make_from_int : ?prec:int -> ?rnd:mpfr_rnd_t -> int -> mpfr_float

Return a fresh mpfr_float number of precision ~prec (optional), made from an int, in direction ~rnd (optional).

Sourceval make_from_float : ?prec:int -> ?rnd:mpfr_rnd_t -> float -> mpfr_float

Return a fresh mpfr_float number of precision ~prec (optional), made from a float, in direction ~rnd (optional).

Sourceval make_from_str : ?prec:int -> ?rnd:mpfr_rnd_t -> ?base:int -> string -> mpfr_float

Mlmpfr.make_from_str s ~base:b ~prec:p ~rnd:r returns a fresh mpfr_float of precision p from the string value s in base b, rounded in direction r (p, b, and r are optional).

Sourceval make_nan : ?prec:int -> unit -> mpfr_float

Return a NaN with precision ~prec if provided, otherwise default precision is used.

Sourceval make_inf : ?prec:int -> sign -> mpfr_float

Return a infinity with precision ~prec if provided, otherwise default precision is used.

Sourceval make_zero : ?prec:int -> sign -> mpfr_float

Return a zero with precision ~prec if provided, otherwise default precision is used.

Conversion

If not provided, default values for rnd and prec are the defaults MPFR precision and rounding mode internal settings (use Mlmpfr.set_default_rounding_mode or Mlmpfr.set_default_prec to modify them).

Sourceval get_float : ?rnd:mpfr_rnd_t -> mpfr_float -> float

Conversion to a float.

Sourceval get_int : ?rnd:mpfr_rnd_t -> mpfr_float -> int

Conversion to an int.

Sourceval get_float_2exp : ?rnd:mpfr_rnd_t -> mpfr_float -> float * int

Mlmpfr.get_float_2exp x returns (n, exp) such that 0.5 <= |n| < 1 and n times 2 raised to exp equals x rounded to float precision.

Sourceval get_mpfr_2exp : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float * int

Mlmpfr.get_mpfr_2exp x returns (n, exp) such that 0.5 <= |n| < 1 and n times 2 raised to exp equals x rounded to ~prec precision.

Sourceval get_str : ?rnd:mpfr_rnd_t -> ?base:int -> ?size:int -> mpfr_float -> string * string

Mlmpfr.get_str ~rnd:r ~base:b ~size:s x converts x to a tuple (frac, exp), where frac is a fraction (a string of digits in base b) with rounding to direction r, and exp is an exponent. s is the number of significand digits output in frac. If s is zero, the number of digits of the significand is chosen large enough so that re-reading the printed value with the same precision, assuming both output and input use rounding to nearest, will recover the original value of x. Decimal is the default base and default size is zero.

Sourceval get_str_ndigits : int -> int -> int

Mlmpfr.get_str_ndigits b p returns the minimal integer m such that any number of p bits, when output with m digits in radix b with rounding to nearest, can be recovered exactly when read again, still with rounding to nearest.

Sourceval get_formatted_str : ?rnd:mpfr_rnd_t -> ?base:int -> ?size:int -> ?ktz:bool -> mpfr_float -> string

Mlmpfr.get_formatted_str is identical to Mlmpfr.get_str except that it returns a full-formatted string (equivalent to mpfr_printf("%Re", x)). Set ktz to false to remove trailing zeroes.

Sourceval fits_int_p : ?rnd:mpfr_rnd_t -> mpfr_float -> bool

Return true if the mpfr_float would fit in a int, when rounded to an integer in the direction ~rnd.

Arithmetic

If not provided, default values for rnd and prec are the defaults MPFR precision and rounding mode internal settings (use Mlmpfr.set_default_rounding_mode or Mlmpfr.set_default_prec to modify them).

Sourceval add : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float

Addition of two mpfr_float.

Sourceval add_int : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> int -> mpfr_float

Addition of a mpfr_float and an int.

Sourceval add_float : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> float -> mpfr_float

Addition of a mpfr_float and a float.

Sourceval sub : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float

Subtraction of two mpfr_float.

Sourceval sub_int : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> int -> mpfr_float

Subtraction of a mpfr_float and an int.

Sourceval int_sub : ?rnd:mpfr_rnd_t -> ?prec:int -> int -> mpfr_float -> mpfr_float

Subtraction of an int and a mpfr_float.

Sourceval sub_float : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> float -> mpfr_float

Addition of a mpfr_float and a float.

Sourceval float_sub : ?rnd:mpfr_rnd_t -> ?prec:int -> float -> mpfr_float -> mpfr_float

Subtraction of a float and an mpfr_float.

Sourceval mul : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float

Multiplication of two mpfr_float.

Sourceval mul_int : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> int -> mpfr_float

Multiplication of a mpfr_float and an int.

Sourceval mul_float : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> float -> mpfr_float

Multiplication of an int and a mpfr_float.

Sourceval div : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float

Division of two mpfr_float.

Sourceval div_int : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> int -> mpfr_float

Division of a mpfr_float by an int.

Sourceval int_div : ?rnd:mpfr_rnd_t -> ?prec:int -> int -> mpfr_float -> mpfr_float

Division of an int by a mpfr_float.

Sourceval div_float : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> float -> mpfr_float

Division of an int by a mpfr_float.

Sourceval float_div : ?rnd:mpfr_rnd_t -> ?prec:int -> float -> mpfr_float -> mpfr_float

Division of a float by a mpfr_float.

Sourceval sqrt : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the square root of a mpfr_float number.

Sourceval sqrt_int : ?rnd:mpfr_rnd_t -> ?prec:int -> int -> mpfr_float

Return the square root of an int. Return nan if negative.

Sourceval rec_sqrt : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the reciprocal square root of an mpfr_float number.

Sourceval cbrt : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Returns the cubic root of an mpfr_float number.

Sourceval rootn_int : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> int -> mpfr_float

Mlmpfr.rootn_int x k returns the k-th root of x.

Sourceval neg : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Compute the negation of an mpfr_float number.

Sourceval abs : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Compute the absolute value of an mpfr_float number.

Sourceval dim : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float

Mlmpfr.dim x y returs the positive difference of x and y, i.e., x - y if x > y, +0 if x <= y, and NaN if x or y is NaN.

Sourceval mul_2int : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> int -> mpfr_float

Mlmpfr.mul_2int x y returns x times 2 raised to y.

Sourceval div_2int : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> int -> mpfr_float

Mlmpfr.div_2int x y returns x divided by 2 raised to y.

Sourceval fac_int : ?rnd:mpfr_rnd_t -> ?prec:int -> int -> mpfr_float

Return the factorial of an int. Return NaN if input is negative.

Sourceval fma : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float -> mpfr_float

Return the fused multiply and add of mpfr_float numbers. Mlmpfr.fma x y z retuns xy+z.

Sourceval fms : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float -> mpfr_float

Return the fused multiply and sub of mpfr_float numbers. Mlmpfr.fms x y z retuns xy-z.

Sourceval fmma : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float -> mpfr_float -> mpfr_float

Mlmpfr.fmma x y z t retuns xy+zt. In case the computation of xy overflows or underflows (or that of zt), the result is computed as if the two intermediate products were computed with rounding toward zero.

Sourceval fmms : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float -> mpfr_float -> mpfr_float

Mlmpfr.fmms x y z t retuns xy-zt. See Mlmpfr.fmma for further comments

Sourceval hypot : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float

Return the Euclidean norm of a mpfr_float number.

Sourceval sum : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float list -> mpfr_float

Return the sum of all the elements of the list.

Sourceval dot : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float list -> mpfr_float list -> mpfr_float

Return the dot product of the lists (commun size of the list is determined by the size of the smallest one).

Comparison

Operators =, <>, >, <, >=, and <= are supported. They are based on mpfr_cmp.

Sourceval cmp : mpfr_float -> mpfr_float -> int

Mlmpfr.cmp a b returns a positive value if a > b, zero if a = b, and a negative value if a < b. If one of the operands is NaN, set the Erange flag and return zero.

Sourceval cmp_int : mpfr_float -> int -> int

Mlmpfr.cmp_int a b compares a and b. Similar as above.

Sourceval cmp_float : mpfr_float -> float -> int

Mlmpfr.cmp_float a b compares a and b. Similar as above.

Sourceval cmp_int_2exp : mpfr_float -> int -> int -> int

Mlmpfr.cmp_int_2exp a b e compares a and b multiplied by two to the power e. Similar as above.

Sourceval cmpabs : mpfr_float -> mpfr_float -> int

Mlmpfr.cmpabs a b returns a positive value if |a| > |b|, zero if |a| = |b|, and a negative value if |a| < |b|.

Sourceval cmpabs_int : mpfr_float -> int -> int

Mlmpfr.cmpabs_int a b compares a and b. Similar as above.

Sourceval nan_p : mpfr_float -> bool

Its a NaN.

Sourceval inf_p : mpfr_float -> bool

Its an infinity.

Sourceval number_p : mpfr_float -> bool

Its a ordinary number (i.e., neither NaN nor an infinity).

Sourceval zero_p : mpfr_float -> bool

It's a zero.

Sourceval regular_p : mpfr_float -> bool

Its a regular number (i.e., neither NaN, nor an infinity nor zero).

Sourceval sgn : mpfr_float -> sign

Return the sign of a mpfr_float number.

Sourceval greater_p : mpfr_float -> mpfr_float -> bool

Operator > in MPFR syntax style.

Sourceval greaterequal_p : mpfr_float -> mpfr_float -> bool

Operator >=in MPFR syntax style.

Sourceval less_p : mpfr_float -> mpfr_float -> bool

Operator < in MPFR syntax style.

Sourceval lessequal_p : mpfr_float -> mpfr_float -> bool

Operator <= in MPFR syntax style.

Sourceval equal_p : mpfr_float -> mpfr_float -> bool

Operator = in MPFR syntax style.

Sourceval lessgreater_p : mpfr_float -> mpfr_float -> bool

Operator <> in MPFR syntax style.

Sourceval unordered_p : mpfr_float -> mpfr_float -> bool

Return true if the operands are comparable (i.e. one of them is a NaN), false otherwise.

Sourceval total_order_p : mpfr_float -> mpfr_float -> bool

This function implements the totalOrder predicate from IEEE 754-2008.

Transcendental

If not provided, default values for rnd and prec are the defaults MPFR precision and rounding mode internal settings (use Mlmpfr.set_default_rounding_mode or Mlmpfr.set_default_prec to modify them).

Sourceval log : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the natural logarithm of a mpfr_float.

Sourceval log_int : ?rnd:mpfr_rnd_t -> ?prec:int -> int -> mpfr_float

Return the natural logarithm of an int.

Sourceval log2 : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the log2 of a mpfr_float.

Sourceval log10 : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the log10 of a mpfr_float.

Sourceval log1p : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the logarithm of one plus a mpfr_float.

Sourceval exp : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the exponential of a mpfr_float.

Sourceval exp2 : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the 2 power of a mpfr_float.

Sourceval exp10 : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the 10 power of a mpfr_float.

Sourceval expm1 : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the exponential of a mpfr_float followed by a subtraction by one.

Sourceval pow : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float

Mlmpfr.pow x y returns x raised to y.

Sourceval pow_int : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> int -> mpfr_float

Mlmpfr.pow_int x y returns x raised to y.

TODO: int_pow_int

TODO: int_pow

Sourceval cos : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the cosine of a mpfr_float.

Sourceval sin : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the sine of a mpfr_float.

Sourceval tan : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the tangent of a mpfr_float.

Sourceval cosu : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> int -> mpfr_float

Mlmpfr.cosu x u returns the cosine of a x multiplied by Pi and divided by u.

Sourceval sinu : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> int -> mpfr_float

Mlmpfr.sinu x u returns the cosine of a x multiplied by Pi and divided by u.

Sourceval tanu : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> int -> mpfr_float

Mlmpfr.tanu x u returns the cosine of a x multiplied by Pi and divided by u.

Sourceval cospi : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the cosine of a mpfr_float multiplied by Pi.

Sourceval sinpi : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the sine of a mpfr_float multiplied by Pi.

Sourceval tanpi : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the tangent of a mpfr_float multiplied by Pi.

Sourceval sin_cos : ?rnd:mpfr_rnd_t -> ?sprec:int -> ?cprec:int -> mpfr_float -> mpfr_float * mpfr_float

Return simultaneously the sine and cosine of an mpfr_float number.

Sourceval sec : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the secant of a mpfr_float.

Sourceval csc : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the cosecant of a mpfr_float.

Sourceval cot : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the cotangent of a mpfr_float.

Sourceval acos : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the arc-cosine of a mpfr_float.

Sourceval asin : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the arc-sine of a mpfr_float.

Sourceval atan : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the arc-tangent of a mpfr_float.

Sourceval acosu : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> int -> mpfr_float

Mlmpfr.acosu x u returns a mpfr_float set to a multiplied by u and divided by 2 Pi, where a is the arc-cosine of x

Sourceval asinu : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> int -> mpfr_float

Mlmpfr.acosu x u returns a mpfr_float set to a multiplied by u and divided by 2 Pi, where a is the arc-sine of x

Sourceval atanu : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> int -> mpfr_float

Mlmpfr.acosu x u returns a mpfr_float set to a multiplied by u and divided by 2 Pi, where a is the arc-tangent of x

Sourceval acospi : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the arc-cosine of a mpfr_float divided by Pi.

Sourceval asinpi : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the arc-sine of a mpfr_float divided by Pi.

Sourceval atanpi : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the arc-tangent of a mpfr_float divided by Pi.

Sourceval atan2 : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float

Mlmpfr.atan2 x y returns the arc-tangent2 of x and y.

Sourceval atan2u : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> int -> mpfr_float

Mlmpfr.atan2u x y u returns the arc-tangent2 of x and y, multiplied by u and divided by 2 Pi.

Sourceval atan2pi : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float

Mlmpfr.atan2pi x y is the same as Mlmpfr.atan2u x y u with u = 2.

Sourceval cosh : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the hyperbolic cosine of a mpfr_float.

Sourceval sinh : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the hyperbolic sine of a mpfr_float.

Sourceval tanh : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the hyperbolic tangent of a mpfr_float.

Sourceval sinh_cosh : ?rnd:mpfr_rnd_t -> ?sprec:int -> ?cprec:int -> mpfr_float -> mpfr_float * mpfr_float

Return simultaneously the sine and cosine of an mpfr_float number.

Sourceval sech : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the hyperbolic secant of a mpfr_float.

Sourceval csch : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the hyperboloc cosecant of a mpfr_float.

Sourceval coth : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the hyperbolic cotangent of a mpfr_float.

Sourceval acosh : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the inverse hyperbolic cosine of a mpfr_float.

Sourceval asinh : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the inverse hyperbolic sine of a mpfr_float.

Sourceval atanh : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the inverse hyperbolic tangent of a mpfr_float.

Sourceval eint : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the exponential integral of a mpfr_float.

Sourceval li2 : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the real part of the dilogarithm of a mpfr_float.

Sourceval gamma : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the Gamma function on a mpfr_float.

Sourceval gamma_inc : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float

Mlmpfr.gamma_inc x y returns the incomplete Gamma function on x and y.

Sourceval lngamma : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the logarithm of the Gamma function on a mpfr_float.

Sourceval lgamma : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float * sign

Return the logarithm of the absolute value of the Gamma function and the sign of the Gamma function on a mpfr_float.

Sourceval digamma : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the Digamma (sometimes also called Psi) function on a mpfr_float.

Sourceval beta : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float

Mlmpfr.beta op1 op2 returns the Beta function at arguments op1 and op2.

Sourceval zeta : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the Riemann Zeta function on a mpfr_float.

Sourceval erf : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the error function on a mpfr_float.

Sourceval erfc : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the complementary error function on a mpfr_float.

Sourceval j0 : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the value of the first kind Bessel function of order 0 on a mpfr_float.

Sourceval j1 : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the value of the first kind Bessel function of order 1 on a mpfr_float.

Sourceval jn : ?rnd:mpfr_rnd_t -> ?prec:int -> int -> mpfr_float -> mpfr_float

Mlmpfr.jn n x returns the value of the first kind Bessel function of order n on x. Return NaN if n is negative.

Sourceval y0 : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the value of the second kind Bessel function of order 0 on a mpfr_float.

Sourceval y1 : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the value of the second kind Bessel function of order 1 on a mpfr_float.

Sourceval yn : ?rnd:mpfr_rnd_t -> ?prec:int -> int -> mpfr_float -> mpfr_float

Mlmpfr.jn n x returns the value of the second kind Bessel function of order n on x. Return NaN if n is negative.

Sourceval agm : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float

Return the arithmetic-geometric mean of a mpfr_float number.

Sourceval ai : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the value of the Airy function Ai on a mpfr_float number.

Sourceval const_log2 : ?rnd:mpfr_rnd_t -> int -> mpfr_float

Return the logarithm of 2.

Sourceval const_pi : ?rnd:mpfr_rnd_t -> int -> mpfr_float

Return the value of Pi.

Sourceval const_euler : ?rnd:mpfr_rnd_t -> int -> mpfr_float

Return the value of Euler's constant 0.577...

Sourceval const_catalan : ?rnd:mpfr_rnd_t -> int -> mpfr_float

Return the value of Catalan's constant 0.915...

Input and Output

The two following functions are deprecated. Use Mlmpfr.get_formatted_str and Mlmpfr.make_from_str.

Sourceval out_str : out_channel -> int -> int -> mpfr_float -> mpfr_rnd_t -> unit

Mlmpfr.out_str stdout b s x Mlmpfr.To_Nearest outputs x, in base b, to stdout, in the direction Mlmpfr.To_Nearest. The size of the printed output is s digits long. It uses Printf.fprintf and Mlmpfr.get_formatted_string.

Sourceval inp_str : in_channel -> int -> int -> mpfr_rnd_t -> mpfr_float

Mlmpfr.inp_str stdin b p Mlmpfr.To_Nearest returns a mpfr_float number of precision p from a string in base b read on stdin. It uses Pervasives.input_line and Mlmpfr.make_from_str.

Sourceval fpif_export : out_channel -> mpfr_float -> unit

Mlmpfr.fpif_export chan op exports the number op to the stream chan in a floating-point interchange format. In particular one can export on a 32-bit computer and import on a 64-bit computer, or export on a little-endian computer and import on a big-endian computer. The precision of op and the sign bit of a NaN are stored too.

Sourceval fpif_import : in_channel -> mpfr_float

Mlmpfr.fpif_import chan imports a mpfr_float number from the stream chan in a floating-point interchange format (see Mlmpfr.mpfr_fpif_export). Note that the precision of op is set to the one read from the stream, and the sign bit is always retrieved (even for NaN). If the stored precision is zero or greater than Mlmpfr.mpfr_prec_max, the function fails (its ternary value is non-zero) and op is undefined. If the function fails for another reason, op is set to NaN. Ternary value is 0 iff the import was successful.

If not provided, default values for rnd and prec are the defaults MPFR precision and rounding mode internal settings (use Mlmpfr.set_default_rounding_mode or Mlmpfr.set_default_prec to modify them).

Sourceval rint : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Retrun the input rounded to an integer, i.e. the nearest representable integer in the direction ~rnd.

Sourceval ceil : ?prec:int -> mpfr_float -> mpfr_float

Retrun the input rounded to an integer, i.e. the next higher or equal representable integer.

Sourceval floor : ?prec:int -> mpfr_float -> mpfr_float

Retrun the input rounded to an integer, i.e. the next lower or equal representable integer.

Sourceval round : ?prec:int -> mpfr_float -> mpfr_float

Retrun the input rounded to an integer, i.e. the nearest representable integer (rounding halfway cases away from zero as in the roundTiesToAway mode of IEEE 754-2008).

Sourceval roundeven : ?prec:int -> mpfr_float -> mpfr_float

Retrun the input rounded to an integer, i.e. the nearest representable integer (rounding halfway cases athe even-rounding rule).

Sourceval trunc : ?prec:int -> mpfr_float -> mpfr_float

Retrun the input rounded to an integer, i.e. the nearest representable integer toward zero.

Sourceval rint_ceil : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Retrun the input rounded to an integer, i.e. the next higher or equal representable integer. If the result is not representable, it is rounded in the direction ~rnd

Sourceval rint_floor : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Retrun the input rounded to an integer, i.e. the next lower or equal representable integer. If the result is not representable, it is rounded in the direction ~rnd

Sourceval rint_round : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Retrun the input rounded to an integer, i.e. the nearest representable integer (rounding halfway cases away from zero). If the result is not representable, it is rounded in the direction ~rnd

Sourceval rint_roundeven : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Retrun the input rounded to an integer, i.e. the nearest representable integer (rounding halfway cases to the nearest even integer). If the result is not representable, it is rounded in the direction ~rnd

Sourceval rint_trunc : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Retrun the input rounded to an integer, i.e. the next integer toward zero. If the result is not representable, it is rounded in the direction ~rnd

Sourceval frac : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float

Return the fractional part of an mpfr_float (with the same sign).

Sourceval modf : ?rnd:mpfr_rnd_t -> ?iprec:int -> ?fprec:int -> mpfr_float -> mpfr_float * mpfr_float

Return simultaneously the integral part and the fractional part of an mpfr_float.

Sourceval fmod : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float

Mlmpfr.fmod x y returns the value x - ny, where n is the integer quotient of x / y (rounded toward zero).

Sourceval fmodquo : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float * int

Mlmpfr.fmodquo x y returns the tuple (x - ny, q). See Mlmpfr.remquo for the meanings of n and q.

Sourceval remainder : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float

Mlmpfr.remainder x y returns the value x - ny, where n is the integer quotient of x / y (rounded to the nearest integer, ties rounded to even).

Sourceval remquo : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float * int

Mlmpfr.remquo x y returns the tuple (x - ny, q), where n is the integer quotient of x / y (rounded to the nearest integer, ties rounded to even), and q are the low significant bits from the quotient n with the sign of x divided by y (except if those low bits are all zero, in which case zero is returned).

Sourceval integer_p : mpfr_float -> bool

Return true iff the input mpfr_float is an integer.

Sourceval set_default_rounding_mode : mpfr_rnd_t -> unit

Set the default rounding mode. The default rounding mode is to nearest initially.

Sourceval get_default_rounding_mode : unit -> mpfr_rnd_t

Get the default rounding mode.

Sourceval prec_round : ?rnd:mpfr_rnd_t -> mpfr_float -> int -> mpfr_float

Mlmpfr.prec_round ~rnd:r x p rounds x according to r with precision p.

Sourceval can_round : mpfr_float -> int -> mpfr_rnd_t -> mpfr_rnd_t -> int -> bool

Assuming b is an approximation of an unknown mpfr_number x in the direction r1 with error at most two to the power E(b)-err where E(b) is the exponent of b, return true if Mlmpfr.can_round x err r1 r2 p is able to round correctly x to precision p with the direction r2, and false otherwise (including for NaN and Inf).

Sourceval min_prec : mpfr_float -> int

Return the minimal number of bits required to store the significand of an mpfr_float, and 0 for special values, including 0.

Sourceval print_rnd_mode : mpfr_rnd_t -> string

Return a MPFR-like string ("MPFR_RNDD", "MPFR_RNDU", "MPFR_RNDN", "MPFR_RNDZ", "MPFR_RNDA") corresponding to the (Toward_Minus_Infinity, Toward_Plus_Infinity, To_Nearest, Toward_Zero, Away_From_Zero) rounding modes.

Sourceval print_ternary : ternary -> string

Return ternary value as a string ("Correct", "Lower", and "Greater" for Correct_Rounding, Lower, and Greater, respectively).

Miscellaneous

Sourceval nexttoward : mpfr_float -> mpfr_float -> mpfr_float

Mlmpfr.nexttoward x y returns NaN if x or y is NaN, returns a copy of x if x and y are equal. Otherwise, if x is different from y, return the next floating-point number of x (with the precision of x and the current exponent range) in the direction of y (the infinite values are seen as the smallest and largest floating-point numbers). If the result is zero, it keeps the sign of x. No underflow or overflow is generated.

Sourceval nextabove : mpfr_float -> mpfr_float

Equivalent to Mlmpfr.nexttoward where y is plus infinity.

Sourceval nextbelow : mpfr_float -> mpfr_float

Equivalent to Mlmpfr.nexttoward where y is minus infinity.

Sourceval min : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float

Return the minimum of two mpfr_float. If operands are both NaN, then return NaN. If one operand is NaN, then return the other value. If operands are zeros of different signs, then return -0.

Sourceval max : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float

Return the maximum of two mpfr_float. If operands are both NaN, then return NaN. If one operand is NaN, then return the other value. If operands are zeros of different signs, then return +0.

Sourceval get_exp : mpfr_float -> int

Return the exponent of a mpfr_float.

Sourceval set_exp : mpfr_float -> int -> mpfr_float

Return a fresh mpfr_float from input with new precision.

Sourceval signbit : mpfr_float -> sign

Return the sign of a mpfr_float.

Sourceval setsign : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> sign -> mpfr_float

Mlmpfr.setsign x s ~rnd:r returns a fresh copy of x with the sign s, with precision p in direction r.

Sourceval copysign : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float

Mlmpfr.copysign x y ~rnd:r returns a fresh copy of x with the sign of y, with precision p in direction r.

Sourceval get_version : unit -> string

Return the MPFR version.

Sourceval get_emin : unit -> int

Return the (current) smallest exponent allowed for a mpfr_float.

Sourceval get_emax : unit -> int

Return the (current) largest exponent allowed for a mpfr_float.

Sourceval set_emin : int -> unit

Set the smallest exponent allowed for a mpfr_float.

Sourceval set_emax : int -> unit

Set the largest exponent allowed for a mpfr_float.

Sourceval get_emin_min : unit -> int

Return the minimum of the exponents allowed for Mlmpfr.set_emin.

Sourceval get_emin_max : unit -> int

Return the maximum of the exponents allowed for Mlmpfr.set_emin.

Sourceval get_emax_min : unit -> int

Return the minimum of the exponents allowed for Mlmpfr.set_emax.

Sourceval get_emax_max : unit -> int

Return the maximum of the exponents allowed for Mlmpfr.set_emax.

Sourceval check_range : ?rnd:mpfr_rnd_t -> mpfr_float -> mpfr_float

Mlmpfr.check_range ~rnd:r x assumes that x is the correctly-rounded value of some real value y in the direction r and some extended exponent range. Note that this function doesn't modify x as mpfr does (it returns a copy, or fails with Error).

Sourceval subnormalize : ?rnd:mpfr_rnd_t -> mpfr_float -> mpfr_float

Mlmpfr.subnormalize ~rnd:r x rounds x emulating subnormal number arithmetic: if x is outside the subnormal exponent range, it just return a copy of x; otherwise, it returns a roudning of x to precision EXP(x)-emin+1 according to rounding mode r. Note that this function doesn't modify x as mpfr does (it returns a copy, or fails with Error).

Sourceval clear_underflow : unit -> unit

Clear the underflow flag.

Sourceval clear_overflow : unit -> unit

Clear the overflow flag.

Sourceval clear_divby0 : unit -> unit

Clear the divide-by-zero flag.

Sourceval clear_nanflag : unit -> unit

Clear the invalid flag.

Sourceval clear_inexflag : unit -> unit

Clear the inexact flag.

Sourceval clear_erangeflag : unit -> unit

Clear the erange flag.

Sourceval clear_flags : unit -> unit

Clear all global flags.

Sourceval set_underflow : unit -> unit

Set the underflow flag.

Sourceval set_overflow : unit -> unit

Set the overflow flag.

Sourceval set_divby0 : unit -> unit

Set the divide-by-zero flag.

Sourceval set_nanflag : unit -> unit

Set the invalid flag.

Sourceval set_inexflag : unit -> unit

Set the inexact flag.

Sourceval set_erangeflag : unit -> unit

Set the erange flag.

Sourceval underflow_p : unit -> bool

Is underflow flag set?

Sourceval overflow_p : unit -> bool

Is overflow flag set?

Sourceval divby0_p : unit -> bool

Is divide-by-zero flag set?

Sourceval nanflag_p : unit -> bool

Is invalid flag set?

Sourceval inexflag_p : unit -> bool

Is inexact flag set?

Sourceval erangeflag_p : unit -> bool

Is erange flag set?

The Mlmpfr.flags_* functions below that take or return an argument mask (i.e., a list of mpfr_flags_t flags) can operate on any subset of the exception flags.

Sourceval flags_clear : mpfr_flags_t list -> unit

Mlmpfr.flags_clear f clears (lowers) the group of flags specified by mask f.

Sourceval flags_set : mpfr_flags_t list -> unit

Mlmpfr.flags_clear f sets (raises) the group of flags specified by mask f.

Sourceval flags_test : mpfr_flags_t list -> mpfr_flags_t list

Return the flags specified by mask.

Sourceval flags_save : unit -> mpfr_flags_t list

Return all the flags. It is equivalent to Mlmpfr.flags_test [Mlmpfr.All].

Sourceval flags_restore : mpfr_flags_t list -> mpfr_flags_t list -> unit

Mlmpfr.flags_restore f1 f2 restores the flags specified by mask f2 to their state represented in flags f1.

Memory Handling

Sourceval free_cache : unit -> unit

Free all caches and pools used by MPFR internally.

OCaml

Innovation. Community. Security.