Module Mpfr
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, 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, andstring) are supported, assuming that afloatis a double-precision floating-point number and anintis 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.
exceptionPrecision_range of intRaised if precision is not included in [
Mpfr.mpfr_prec_min;Mpfr.mpfr_prec_max].
exceptionBase_range of intRaised if base is not included in [
2;64], or0(automatic base detection).
type sign=|Positive|Negativetype mpfr_tBinding to C MPFR mpfr_t type.
type ternary=|Correct_Rounding|Greater|LowerAssociated to an
mpfr_tvalue, aternaryvalue indicates if it was correctly rounded.
type mpfr_float= mpfr_t * ternary optiontype mpfr_rnd_t=|To_Nearest|Toward_Zero|Toward_Plus_Infinity|Toward_Minus_Infinity|Away_From_Zero|FaithfulRounding modes.
type mpfr_flags_t=|Underflow|Overflow|Nan|Inexact|Erange|Divby0|AllFlags as described here.
Initialization
val set_default_prec : int -> unitMpfr.set_default_prec pmodifies the default precision to be exactlypbits. 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.
val get_prec : mpfr_float -> intMpfr.get_prec xreturns the precision ofx. The correspondingMpfr.set_prec x precfunction is not allowed, useMpfr.make_from_mpfr ~prec:prec xinstead.
val make_from_mpfr : ?prec:int -> ?rnd:mpfr_rnd_t -> mpfr_float -> mpfr_floatReturn a fresh
mpfr_floatnumber of precision~prec(optional), made from anothermpfr_floatnumber, in direction~rnd(optional).
val make_from_int : ?prec:int -> ?rnd:mpfr_rnd_t -> int -> mpfr_floatReturn a fresh
mpfr_floatnumber of precision~prec(optional), made from anint, in direction~rnd(optional).
val make_from_float : ?prec:int -> ?rnd:mpfr_rnd_t -> float -> mpfr_floatReturn a fresh
mpfr_floatnumber of precision~prec(optional), made from afloat, in direction~rnd(optional).
val make_from_str : ?prec:int -> ?rnd:mpfr_rnd_t -> ?base:int -> string -> mpfr_floatMpfr.make_from_str s ~base:b ~prec:p ~rnd:rreturns a freshmpfr_floatof precisionpfrom the string valuesin baseb, rounded in directionr(p,b, andrare optional).
val make_nan : ?prec:int -> unit -> mpfr_floatReturn a NaN with precision
~precif provided, otherwise default precision is used.
val make_inf : ?prec:int -> sign -> mpfr_floatReturn a infinity with precision
~precif provided, otherwise default precision is used.
val make_zero : ?prec:int -> sign -> mpfr_floatReturn a zero with precision
~precif provided, otherwise default precision is used.
Conversion
val get_float : ?rnd:mpfr_rnd_t -> mpfr_float -> floatConversion to a
float.
val get_int : ?rnd:mpfr_rnd_t -> mpfr_float -> intConversion to an
int.
val get_float_2exp : ?rnd:mpfr_rnd_t -> mpfr_float -> float * intMpfr.get_float_2exp xreturns(n, exp)such that0.5 <= |n| < 1andntimes 2 raised toexpequalsxrounded to float precision.
val get_mpfr_2exp : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float * intMpfr.get_mpfr_2exp xreturns(n, exp)such that0.5 <= |n| < 1andntimes 2 raised toexpequalsxrounded to~precprecision.
val get_str : ?rnd:mpfr_rnd_t -> ?base:int -> ?size:int -> mpfr_float -> string * stringMpfr.get_str ~rnd:r ~base:b ~size:s xconvertsxto a tuple(frac, exp), wherefracis a fraction (a string of digits in baseb) with rounding to directionr, andexpis an exponent.sis the number of significand digits output infrac. Ifsis 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 ofx. Decimal is the default base and default size is zero.
val get_formatted_str : ?rnd:mpfr_rnd_t -> ?base:int -> ?size:int -> mpfr_float -> stringMpfr.get_formatted_stris identical toMpfr.get_strexcept that it returns a full-formatted string (equivalent to mpfr_printf("%.Re", x)).
val fits_int_p : ?rnd:mpfr_rnd_t -> mpfr_float -> boolReturn true if the
mpfr_floatwould fit in aint, when rounded to an integer in the direction~rnd.
Basic Arithmetic
val add : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_floatAddition of two
mpfr_float.
val add_int : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> int -> mpfr_floatAddition of a
mpfr_floatand anint.
val add_float : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> float -> mpfr_floatAddition of a
mpfr_floatand afloat.
val sub : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_floatSubtraction of two
mpfr_float.
val sub_int : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> int -> mpfr_floatSubtraction of a
mpfr_floatand anint.
val int_sub : ?rnd:mpfr_rnd_t -> ?prec:int -> int -> mpfr_float -> mpfr_floatSubtraction of an
intand ampfr_float.
val sub_float : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> float -> mpfr_floatAddition of a
mpfr_floatand afloat.
val float_sub : ?rnd:mpfr_rnd_t -> ?prec:int -> float -> mpfr_float -> mpfr_floatSubtraction of a
floatand anmpfr_float.
val mul : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_floatMultiplication of two
mpfr_float.
val mul_int : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> int -> mpfr_floatMultiplication of a
mpfr_floatand anint.
val mul_float : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> float -> mpfr_floatMultiplication of an
intand ampfr_float.
val div : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_floatDivision of two
mpfr_float.
val div_int : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> int -> mpfr_floatDivision of a
mpfr_floatby anint.
val int_div : ?rnd:mpfr_rnd_t -> ?prec:int -> int -> mpfr_float -> mpfr_floatDivision of an
intby ampfr_float.
val div_float : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> float -> mpfr_floatDivision of an
intby ampfr_float.
val float_div : ?rnd:mpfr_rnd_t -> ?prec:int -> float -> mpfr_float -> mpfr_floatDivision of a
floatby ampfr_float.
val sqrt : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the square root of a
mpfr_floatnumber.
val sqrt_int : ?rnd:mpfr_rnd_t -> ?prec:int -> int -> mpfr_floatReturn the square root of an
int. Returnnanif negative.
val rec_sqrt : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the reciprocal square root of an
mpfr_floatnumber.
val cbrt : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturns the cubic root of an
mpfr_floatnumber.
val rootn_int : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> int -> mpfr_floatMpfr.rootn_int x kreturns thek-th root ofx.
val pow : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_floatMpfr.pow x yreturnsxraised toy.
val pow_int : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> int -> mpfr_floatMpfr.pow_int x yreturnsxraised toy.
val neg : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatCompute the negation of an
mpfr_floatnumber.
val abs : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatCompute the absolute value of an
mpfr_floatnumber.
val dim : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_floatMpfr.dim x yreturs the positive difference ofxandy, i.e.,x - yifx > y,+0ifx <= y, and NaN ifxoryis NaN.
val mul_2int : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> int -> mpfr_floatMpfr.mul_2int x yreturnsxtimes 2 raised toy.
val div_2int : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> int -> mpfr_floatMpfr.div_2int x yreturnsxdivided by 2 raised toy.
Comparison
val cmp : mpfr_float -> mpfr_float -> intMpfr.cmp a breturns a positive value ifa>b, zero ifa=b, and a negative value ifa<b. If one of the operands is NaN, set theErangeflag and return zero.
val cmp_int : mpfr_float -> int -> intMpfr.cmp_int a bcomparesaandb. Similar as above.
val cmp_float : mpfr_float -> float -> intMpfr.cmp_float a bcomparesaandb. Similar as above.
val cmp_int_2exp : mpfr_float -> int -> int -> intMpfr.cmp_int_2exp a b ecomparesaandbmultiplied by two to the powere. Similar as above.
val cmpabs : mpfr_float -> mpfr_float -> intMpfr.cmpabs a breturns a positive value if|a|>|b|, zero if|a|=|b|, and a negative value if|a|<|b|.
val nan_p : mpfr_float -> boolIts a NaN.
val inf_p : mpfr_float -> boolIts an infinity.
val number_p : mpfr_float -> boolIts a ordinary number (i.e., neither NaN nor an infinity).
val zero_p : mpfr_float -> boolIts a zero.
val regular_p : mpfr_float -> boolIts a regular number (i.e., neither NaN, nor an infinity nor zero).
val sgn : mpfr_float -> signReturn the sign of a
mpfr_floatnumber.
val greater_p : mpfr_float -> mpfr_float -> boolOperator
>in MPFR syntax style.
val greaterequal_p : mpfr_float -> mpfr_float -> boolOperator
>=in MPFR syntax style.
val less_p : mpfr_float -> mpfr_float -> boolOperator
<in MPFR syntax style.
val lessequal_p : mpfr_float -> mpfr_float -> boolOperator
<=in MPFR syntax style.
val equal_p : mpfr_float -> mpfr_float -> boolOperator
=in MPFR syntax style.
val lessgreater_p : mpfr_float -> mpfr_float -> boolOperator
<>in MPFR syntax style.
val unordered_p : mpfr_float -> mpfr_float -> boolReturn true if the operands are comparable (i.e. one of them is a NaN), false otherwise.
Special
val log : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the natural logarithm of a
mpfr_float.
val log_int : ?rnd:mpfr_rnd_t -> ?prec:int -> int -> mpfr_floatReturn the natural logarithm of an
int.
val log2 : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the log2 of a
mpfr_float.
val log10 : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the log10 of a
mpfr_float.
val exp : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the exponential of a
mpfr_float.
val exp2 : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the 2 power of a
mpfr_float.
val exp10 : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the 10 power of a
mpfr_float.
val cos : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the cosine of a
mpfr_float.
val sin : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the sine of a
mpfr_float.
val tan : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the tangent of a
mpfr_float.
val sin_cos : ?rnd:mpfr_rnd_t -> ?sprec:int -> ?cprec:int -> mpfr_float -> mpfr_float * mpfr_floatReturn simultaneously the sine and cosine of an
mpfr_floatnumber.
val sec : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the secant of a
mpfr_float.
val csc : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the cosecant of a
mpfr_float.
val cot : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the cotangent of a
mpfr_float.
val acos : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the arc-cosine of a
mpfr_float.
val asin : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the arc-sine of a
mpfr_float.
val atan : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the arc-tangent of a
mpfr_float.
val atan2 : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_floatMpfr.atan2 x yreturns the arc-tangent2 of axandy.
val cosh : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the hyperbolic cosine of a
mpfr_float.
val sinh : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the hyperbolic sine of a
mpfr_float.
val tanh : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the hyperbolic tangent of a
mpfr_float.
val sinh_cosh : ?rnd:mpfr_rnd_t -> ?sprec:int -> ?cprec:int -> mpfr_float -> mpfr_float * mpfr_floatReturn simultaneously the sine and cosine of an
mpfr_floatnumber.
val sech : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the hyperbolic secant of a
mpfr_float.
val csch : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the hyperboloc cosecant of a
mpfr_float.
val coth : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the hyperbolic cotangent of a
mpfr_float.
val acosh : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the inverse hyperbolic cosine of a
mpfr_float.
val asinh : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the inverse hyperbolic sine of a
mpfr_float.
val atanh : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the inverse hyperbolic tangent of a
mpfr_float.
val fac_int : ?rnd:mpfr_rnd_t -> ?prec:int -> int -> mpfr_floatReturn the factorial of an
int. Return NaN if input is negative.
val log1p : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the logarithm of one plus a
mpfr_float.
val expm1 : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the exponential of a
mpfr_floatfollowed by a subtraction by one.
val eint : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the exponential integral of a
mpfr_float.
val li2 : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the real part of the dilogarithm of a
mpfr_float.
val gamma : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the Gamma function on a
mpfr_float.
val gamma_inc : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_floatMpfr.gamma_inc x yreturns the incomplete Gamma function onxandy.
val lngamma : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the logarithm of the Gamma function on a
mpfr_float.
val lgamma : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float * signReturn the logarithm of the absolute value of the Gamma function and the sign of the Gamma function on a
mpfr_float.
val digamma : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the Digamma (sometimes also called Psi) function on a
mpfr_float.
val beta : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_floatMpfr.beta op1 op2returns the Beta function at argumentsop1andop2.
val zeta : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the Riemann Zeta function on a
mpfr_float.
val erf : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the error function on a
mpfr_float.
val erfc : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the complementary error function on a
mpfr_float.
val j0 : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the value of the first kind Bessel function of order 0 on a
mpfr_float.
val j1 : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the value of the first kind Bessel function of order 1 on a
mpfr_float.
val jn : ?rnd:mpfr_rnd_t -> ?prec:int -> int -> mpfr_float -> mpfr_floatMpfr.jn n xreturns the value of the first kind Bessel function of ordernonx. Return NaN ifnis negative.
val y0 : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the value of the second kind Bessel function of order 0 on a
mpfr_float.
val y1 : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the value of the second kind Bessel function of order 1 on a
mpfr_float.
val yn : ?rnd:mpfr_rnd_t -> ?prec:int -> int -> mpfr_float -> mpfr_floatMpfr.jn n xreturns the value of the second kind Bessel function of ordernonx. Return NaN ifnis negative.
val fma : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float -> mpfr_floatReturn the fused multiply and add of
mpfr_floatnumbers.Mpfr.fma x y zretunsxy+z.
val fms : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float -> mpfr_floatReturn the fused multiply and sub of
mpfr_floatnumbers.Mpfr.fms x y zretunsxy-z.
val fmma : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float -> mpfr_float -> mpfr_floatMpfr.fmma x y z tretunsxy+zt. In case the computation ofxyoverflows or underflows (or that ofzt), the result is computed as if the two intermediate products were computed with rounding toward zero.
val fmms : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float -> mpfr_float -> mpfr_floatMpfr.fmms x y z tretunsxy-zt. SeeMpfr.fmmafor further comments
val agm : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_floatReturn the arithmetic-geometric mean of a
mpfr_floatnumber.
val hypot : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_floatReturn the Euclidean norm of a
mpfr_floatnumber.
val ai : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the value of the Airy function Ai on a
mpfr_floatnumber.
val const_log2 : ?rnd:mpfr_rnd_t -> int -> mpfr_floatReturn the logarithm of 2.
val const_pi : ?rnd:mpfr_rnd_t -> int -> mpfr_floatReturn the value of Pi.
val const_euler : ?rnd:mpfr_rnd_t -> int -> mpfr_floatReturn the value of Euler's constant 0.577...
val const_catalan : ?rnd:mpfr_rnd_t -> int -> mpfr_floatReturn the value of Catalan's constant 0.915...
val sum : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float list -> mpfr_floatReturn the sum of all the elements of the list.
Input and Output
val out_str : Stdlib.out_channel -> int -> int -> mpfr_float -> mpfr_rnd_t -> unitMpfr.out_str stdout b s x Mpfr.To_Nearestoutputsx, in baseb, tostdout, in the directionMpfr.To_Nearest. The size of the printed output issdigits long. It usesPrintf.fprintfandMpfr.get_formatted_string.
val inp_str : Stdlib.in_channel -> int -> int -> mpfr_rnd_t -> mpfr_floatMpfr.inp_str stdin b p Mpfr.To_Nearestreturns ampfr_floatnumber of precisionpfrom a string in basebread onstdin. It usesPervasives.input_lineandMpfr.make_from_str.
val fpif_export : Stdlib.out_channel -> mpfr_float -> unitMpfr.fpif_export chan opexports the numberopto the streamchanin 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.
val fpif_import : Stdlib.in_channel -> mpfr_floatMpfr.fpif_import chanimports ampfr_floatnumber from the streamchanin a floating-point interchange format (seeMpfr.mpfr_fpif_export). Note that the precision ofopis 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 thanMpfr.mpfr_prec_max, the function fails (its ternary value is non-zero) andopis undefined. If the function fails for another reason,opis set to NaN. Ternary value is 0 iff the import was successful.
Integer and Remainder Related
val rint : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatRetrun the input rounded to an integer, i.e. the nearest representable integer in the direction
~rnd.
val ceil : ?prec:int -> mpfr_float -> mpfr_floatRetrun the input rounded to an integer, i.e. the next higher or equal representable integer.
val floor : ?prec:int -> mpfr_float -> mpfr_floatRetrun the input rounded to an integer, i.e. the next lower or equal representable integer.
val round : ?prec:int -> mpfr_float -> mpfr_floatRetrun 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).
val roundeven : ?prec:int -> mpfr_float -> mpfr_floatRetrun the input rounded to an integer, i.e. the nearest representable integer (rounding halfway cases athe even-rounding rule).
val trunc : ?prec:int -> mpfr_float -> mpfr_floatRetrun the input rounded to an integer, i.e. the nearest representable integer toward zero.
val rint_ceil : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatRetrun 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
val rint_floor : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatRetrun 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
val rint_round : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatRetrun 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
val rint_roundeven : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatRetrun 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
val rint_trunc : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatRetrun 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
val frac : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_floatReturn the fractional part of an
mpfr_float(with the same sign).
val modf : ?rnd:mpfr_rnd_t -> ?iprec:int -> ?fprec:int -> mpfr_float -> mpfr_float * mpfr_floatReturn simultaneously the integral part and the fractional part of an
mpfr_float.
val fmod : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_floatMpfr.fmod x yreturns the valuex - ny, wherenis the integer quotient ofx / y(rounded toward zero).
val fmodquo : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float * intMpfr.fmodquo x yreturns the tuple(x - ny, q). SeeMpfr.remquofor the meanings ofnandq.
val remainder : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_floatMpfr.remainder x yreturns the valuex - ny, wherenis the integer quotient ofx / y(rounded to the nearest integer, ties rounded to even).
val remquo : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_float * intMpfr.remquo x yreturns the tuple (x - ny,q), wherenis the integer quotient ofx / y(rounded to the nearest integer, ties rounded to even), andqare the low significant bits from the quotientnwith the sign ofxdivided byy(except if those low bits are all zero, in which case zero is returned).
val integer_p : mpfr_float -> boolReturn true iff the input
mpfr_floatis an integer.
Rounding Related
val set_default_rounding_mode : mpfr_rnd_t -> unitSet the default rounding mode. The default rounding mode is to nearest initially.
val get_default_rounding_mode : unit -> mpfr_rnd_tGet the default rounding mode.
val prec_round : ?rnd:mpfr_rnd_t -> mpfr_float -> int -> mpfr_floatMpfr.prec_round ~rnd:r x proundsxaccording torwith precisionp.
val can_round : mpfr_float -> int -> mpfr_rnd_t -> mpfr_rnd_t -> int -> boolAssuming
bis an approximation of an unknownmpfr_numberxin the directionr1with error at most two to the power E(b)-errwhere E(b) is the exponent ofb, returntrueifMpfr.can_round x err r1 r2 pis able to round correctlyxto precisionpwith the directionr2, andfalseotherwise (including for NaN and Inf).
val min_prec : mpfr_float -> intReturn the minimal number of bits required to store the significand of an
mpfr_float, and 0 for special values, including 0.
val print_rnd_mode : mpfr_rnd_t -> stringReturn 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.
val print_ternary : ternary -> stringReturn ternary value as a string ("Correct", "Lower", and "Greater" for
Correct_Rounding,Lower, andGreater, respectively).
Miscellaneous
val nexttoward : mpfr_float -> mpfr_float -> mpfr_floatMpfr.nexttoward x yreturns NaN ifxoryis NaN, returns a copy ofxifxandyare equal. Otherwise, ifxis different fromy, return the next floating-point number ofx(with the precision ofxand the current exponent range) in the direction ofy(the infinite values are seen as the smallest and largest floating-point numbers). If the result is zero, it keeps the sign ofx. No underflow or overflow is generated.
val nextabove : mpfr_float -> mpfr_floatEquivalent to
Mpfr.nexttowardwhereyis plus infinity.
val nextbelow : mpfr_float -> mpfr_floatEquivalent to
Mpfr.nexttowardwhereyis minus infinity.
val min : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_floatReturn 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.
val max : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_floatReturn 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.
val get_exp : mpfr_float -> intReturn the exponent of a
mpfr_float.
val set_exp : mpfr_float -> int -> mpfr_floatReturn a fresh
mpfr_floatfrom input with new precision.
val signbit : mpfr_float -> signReturn the sign of a
mpfr_float.
val setsign : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> sign -> mpfr_floatMpfr.setsign x s ~rnd:rreturns a fresh copy ofxwith the signs, with precisionpin directionr.
val copysign : ?rnd:mpfr_rnd_t -> ?prec:int -> mpfr_float -> mpfr_float -> mpfr_floatMpfr.copysign x y ~rnd:rreturns a fresh copy ofxwith the sign ofy, with precisionpin directionr.
Exception Related
val check_range : ?rnd:mpfr_rnd_t -> mpfr_float -> mpfr_floatMpfr.check_range ~rnd:r xassumes thatxis the correctly-rounded value of some real valueyin the directionrand some extended exponent range. Note that this function doesn't modifyxas mpfr does (it returns a copy, or fails withError).
val subnormalize : ?rnd:mpfr_rnd_t -> mpfr_float -> mpfr_floatMpfr.subnormalize ~rnd:r xroundsxemulating subnormal number arithmetic: ifxis outside the subnormal exponent range, it just return a copy ofx; otherwise, it returns a roudning ofxto precision EXP(x)-emin+1 according to rounding moder. Note that this function doesn't modifyxas mpfr does (it returns a copy, or fails withError).
val flags_clear : mpfr_flags_t list -> unitMpfr.flags_clear fclears (lowers) the group of flags specified by maskf.
val flags_set : mpfr_flags_t list -> unitMpfr.flags_clear fsets (raises) the group of flags specified by maskf.
val flags_test : mpfr_flags_t list -> mpfr_flags_t listReturn the flags specified by mask.
val flags_save : unit -> mpfr_flags_t listReturn all the flags. It is equivalent to
Mpfr.flags_test [Mpfr.All].
val flags_restore : mpfr_flags_t list -> mpfr_flags_t list -> unitMpfr.flags_restore f1 f2restores the flags specified by maskf2to their state represented in flagsf1.