man-pages/man3/Stdlib.Float.3o.html
2021-03-31 01:06:50 +01:00

1559 lines
16 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of Stdlib.Float</TITLE>
</HEAD><BODY>
<H1>Stdlib.Float</H1>
Section: OCaml library (3o)<BR>Updated: 2020-01-30<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
Stdlib.Float - no description
<A NAME="lbAC">&nbsp;</A>
<H2>Module</H2>
Module Stdlib.Float
<A NAME="lbAD">&nbsp;</A>
<H2>Documentation</H2>
<P>
Module
<B>Float</B>
<BR>&nbsp;:&nbsp;
<B>(module Stdlib__float)</B>
<P>
<P>
<P>
<P>
<P>
<P>
<P>
<P>
<I>val zero </I>
:
<B>float</B>
<P>
The floating point 0.
<P>
<P>
<B>Since</B>
4.08.0
<P>
<P>
<P>
<I>val one </I>
:
<B>float</B>
<P>
The floating-point 1.
<P>
<P>
<B>Since</B>
4.08.0
<P>
<P>
<P>
<I>val minus_one </I>
:
<B>float</B>
<P>
The floating-point -1.
<P>
<P>
<B>Since</B>
4.08.0
<P>
<P>
<P>
<I>val neg </I>
:
<B>float -&gt; float</B>
<P>
Unary negation.
<P>
<P>
<P>
<I>val add </I>
:
<B>float -&gt; float -&gt; float</B>
<P>
Floating-point addition.
<P>
<P>
<P>
<I>val sub </I>
:
<B>float -&gt; float -&gt; float</B>
<P>
Floating-point subtraction.
<P>
<P>
<P>
<I>val mul </I>
:
<B>float -&gt; float -&gt; float</B>
<P>
Floating-point multiplication.
<P>
<P>
<P>
<I>val div </I>
:
<B>float -&gt; float -&gt; float</B>
<P>
Floating-point division.
<P>
<P>
<P>
<I>val fma </I>
:
<B>float -&gt; float -&gt; float -&gt; float</B>
<P>
<P>
<B>fma x y z</B>
returns
<B>x * y + z</B>
, with a best effort for computing
this expression with a single rounding, using either hardware
instructions (providing full IEEE compliance) or a software
emulation. Note: since software emulation of the fma is costly,
make sure that you are using hardware fma support if performance
matters.
<P>
<P>
<B>Since</B>
4.08.0
<P>
<P>
<P>
<I>val rem </I>
:
<B>float -&gt; float -&gt; float</B>
<P>
<P>
<B>rem a b</B>
returns the remainder of
<B>a</B>
with respect to
<B>b</B>
. The returned
value is
<B>a -. n *. b</B>
, where
<B>n</B>
is the quotient
<B>a /. b</B>
rounded towards
zero to an integer.
<P>
<P>
<P>
<I>val succ </I>
:
<B>float -&gt; float</B>
<P>
<P>
<B>succ x</B>
returns the floating point number right after
<B>x</B>
i.e.,
the smallest floating-point number greater than
<B>x</B>
. See also
<B>Float.next_after</B>
.
<P>
<P>
<B>Since</B>
4.08.0
<P>
<P>
<P>
<I>val pred </I>
:
<B>float -&gt; float</B>
<P>
<P>
<B>pred x</B>
returns the floating-point number right before
<B>x</B>
i.e.,
the greatest floating-point number smaller than
<B>x</B>
. See also
<B>Float.next_after</B>
.
<P>
<P>
<B>Since</B>
4.08.0
<P>
<P>
<P>
<I>val abs </I>
:
<B>float -&gt; float</B>
<P>
<P>
<B>abs f</B>
returns the absolute value of
<B>f</B>
.
<P>
<P>
<P>
<I>val infinity </I>
:
<B>float</B>
<P>
Positive infinity.
<P>
<P>
<P>
<I>val neg_infinity </I>
:
<B>float</B>
<P>
Negative infinity.
<P>
<P>
<P>
<I>val nan </I>
:
<B>float</B>
<P>
A special floating-point value denoting the result of an
undefined operation such as
<B>0.0 /. 0.0</B>
. Stands for
'not a number'. Any floating-point operation with
<B>nan</B>
as
argument returns
<B>nan</B>
as result. As for floating-point comparisons,
<B>=</B>
,
<B>&lt;</B>
,
<B>&lt;=</B>
,
<B>&gt;</B>
and
<B>&gt;=</B>
return
<B>false</B>
and
<B>&lt;&gt;</B>
returns
<B>true</B>
if one or both of their arguments is
<B>nan</B>
.
<P>
<P>
<P>
<I>val pi </I>
:
<B>float</B>
<P>
The constant pi.
<P>
<P>
<P>
<I>val max_float </I>
:
<B>float</B>
<P>
The largest positive finite value of type
<B>float</B>
.
<P>
<P>
<P>
<I>val min_float </I>
:
<B>float</B>
<P>
The smallest positive, non-zero, non-denormalized value of type
<B>float</B>
.
<P>
<P>
<P>
<I>val epsilon </I>
:
<B>float</B>
<P>
The difference between
<B>1.0</B>
and the smallest exactly representable
floating-point number greater than
<B>1.0</B>
.
<P>
<P>
<P>
<I>val is_finite </I>
:
<B>float -&gt; bool</B>
<P>
<P>
<B>is_finite x</B>
is
<B>true</B>
iff
<B>x</B>
is finite i.e., not infinite and
not
<B>Float.nan</B>
.
<P>
<P>
<B>Since</B>
4.08.0
<P>
<P>
<P>
<I>val is_infinite </I>
:
<B>float -&gt; bool</B>
<P>
<P>
<B>is_infinite x</B>
is
<B>true</B>
iff
<B>x</B>
is
<B>Float.infinity</B>
or
<B>Float.neg_infinity</B>
.
<P>
<P>
<B>Since</B>
4.08.0
<P>
<P>
<P>
<I>val is_nan </I>
:
<B>float -&gt; bool</B>
<P>
<P>
<B>is_nan x</B>
is
<B>true</B>
iff
<B>x</B>
is not a number (see
<B>Float.nan</B>
).
<P>
<P>
<B>Since</B>
4.08.0
<P>
<P>
<P>
<I>val is_integer </I>
:
<B>float -&gt; bool</B>
<P>
<P>
<B>is_integer x</B>
is
<B>true</B>
iff
<B>x</B>
is an integer.
<P>
<P>
<B>Since</B>
4.08.0
<P>
<P>
<P>
<I>val of_int </I>
:
<B>int -&gt; float</B>
<P>
Convert an integer to floating-point.
<P>
<P>
<P>
<I>val to_int </I>
:
<B>float -&gt; int</B>
<P>
Truncate the given floating-point number to an integer.
The result is unspecified if the argument is
<B>nan</B>
or falls outside the
range of representable integers.
<P>
<P>
<P>
<I>val of_string </I>
:
<B>string -&gt; float</B>
<P>
Convert the given string to a float. The string is read in decimal
(by default) or in hexadecimal (marked by
<B>0x</B>
or
<B>0X</B>
).
The format of decimal floating-point numbers is
<B>[-] dd.ddd (e|E) [+|-] dd </B>
, where
<B>d</B>
stands for a decimal digit.
The format of hexadecimal floating-point numbers is
<B>[-] 0(x|X) hh.hhh (p|P) [+|-] dd </B>
, where
<B>h</B>
stands for an
hexadecimal digit and
<B>d</B>
for a decimal digit.
In both cases, at least one of the integer and fractional parts must be
given; the exponent part is optional.
The
<B>_</B>
(underscore) character can appear anywhere in the string
and is ignored.
Depending on the execution platforms, other representations of
floating-point numbers can be accepted, but should not be relied upon.
Raise
<B>Failure float_of_string</B>
if the given string is not a valid
representation of a float.
<P>
<P>
<P>
<I>val of_string_opt </I>
:
<B>string -&gt; float option</B>
<P>
Same as
<B>of_string</B>
, but returns
<B>None</B>
instead of raising.
<P>
<P>
<P>
<I>val to_string </I>
:
<B>float -&gt; string</B>
<P>
Return the string representation of a floating-point number.
<P>
<P>
<I>type fpclass </I>
=
<B>fpclass</B>
=
<BR>&nbsp;|&nbsp;FP_normal&nbsp;&nbsp;(*&nbsp;Normal&nbsp;number,&nbsp;none&nbsp;of&nbsp;the&nbsp;below
<BR>&nbsp;*)
<BR>&nbsp;|&nbsp;FP_subnormal&nbsp;&nbsp;(*&nbsp;Number&nbsp;very&nbsp;close&nbsp;to&nbsp;0.0,&nbsp;has&nbsp;reduced&nbsp;precision
<BR>&nbsp;*)
<BR>&nbsp;|&nbsp;FP_zero&nbsp;&nbsp;(*&nbsp;Number&nbsp;is&nbsp;0.0&nbsp;or&nbsp;-0.0
<BR>&nbsp;*)
<BR>&nbsp;|&nbsp;FP_infinite&nbsp;&nbsp;(*&nbsp;Number&nbsp;is&nbsp;positive&nbsp;or&nbsp;negative&nbsp;infinity
<BR>&nbsp;*)
<BR>&nbsp;|&nbsp;FP_nan&nbsp;&nbsp;(*&nbsp;Not&nbsp;a&nbsp;number:&nbsp;result&nbsp;of&nbsp;an&nbsp;undefined&nbsp;operation
<BR>&nbsp;*)
<BR>&nbsp;
<P>
The five classes of floating-point numbers, as determined by
the
<B>Float.classify_float</B>
function.
<P>
<P>
<P>
<I>val classify_float </I>
:
<B>float -&gt; fpclass</B>
<P>
Return the class of the given floating-point number:
normal, subnormal, zero, infinite, or not a number.
<P>
<P>
<P>
<I>val pow </I>
:
<B>float -&gt; float -&gt; float</B>
<P>
Exponentiation.
<P>
<P>
<P>
<I>val sqrt </I>
:
<B>float -&gt; float</B>
<P>
Square root.
<P>
<P>
<P>
<I>val exp </I>
:
<B>float -&gt; float</B>
<P>
Exponential.
<P>
<P>
<P>
<I>val log </I>
:
<B>float -&gt; float</B>
<P>
Natural logarithm.
<P>
<P>
<P>
<I>val log10 </I>
:
<B>float -&gt; float</B>
<P>
Base 10 logarithm.
<P>
<P>
<P>
<I>val expm1 </I>
:
<B>float -&gt; float</B>
<P>
<P>
<B>expm1 x</B>
computes
<B>exp x -. 1.0</B>
, giving numerically-accurate results
even if
<B>x</B>
is close to
<B>0.0</B>
.
<P>
<P>
<P>
<I>val log1p </I>
:
<B>float -&gt; float</B>
<P>
<P>
<B>log1p x</B>
computes
<B>log(1.0 +. x)</B>
(natural logarithm),
giving numerically-accurate results even if
<B>x</B>
is close to
<B>0.0</B>
.
<P>
<P>
<P>
<I>val cos </I>
:
<B>float -&gt; float</B>
<P>
Cosine. Argument is in radians.
<P>
<P>
<P>
<I>val sin </I>
:
<B>float -&gt; float</B>
<P>
Sine. Argument is in radians.
<P>
<P>
<P>
<I>val tan </I>
:
<B>float -&gt; float</B>
<P>
Tangent. Argument is in radians.
<P>
<P>
<P>
<I>val acos </I>
:
<B>float -&gt; float</B>
<P>
Arc cosine. The argument must fall within the range
<B>[-1.0, 1.0]</B>
.
Result is in radians and is between
<B>0.0</B>
and
<B>pi</B>
.
<P>
<P>
<P>
<I>val asin </I>
:
<B>float -&gt; float</B>
<P>
Arc sine. The argument must fall within the range
<B>[-1.0, 1.0]</B>
.
Result is in radians and is between
<B>-pi/2</B>
and
<B>pi/2</B>
.
<P>
<P>
<P>
<I>val atan </I>
:
<B>float -&gt; float</B>
<P>
Arc tangent.
Result is in radians and is between
<B>-pi/2</B>
and
<B>pi/2</B>
.
<P>
<P>
<P>
<I>val atan2 </I>
:
<B>float -&gt; float -&gt; float</B>
<P>
<P>
<B>atan2 y x</B>
returns the arc tangent of
<B>y /. x</B>
. The signs of
<B>x</B>
and
<B>y</B>
are used to determine the quadrant of the result.
Result is in radians and is between
<B>-pi</B>
and
<B>pi</B>
.
<P>
<P>
<P>
<I>val hypot </I>
:
<B>float -&gt; float -&gt; float</B>
<P>
<P>
<B>hypot x y</B>
returns
<B>sqrt(x *. x + y *. y)</B>
, that is, the length
of the hypotenuse of a right-angled triangle with sides of length
<B>x</B>
and
<B>y</B>
, or, equivalently, the distance of the point
<B>(x,y)</B>
to origin. If one of
<B>x</B>
or
<B>y</B>
is infinite, returns
<B>infinity</B>
even if the other is
<B>nan</B>
.
<P>
<P>
<P>
<I>val cosh </I>
:
<B>float -&gt; float</B>
<P>
Hyperbolic cosine. Argument is in radians.
<P>
<P>
<P>
<I>val sinh </I>
:
<B>float -&gt; float</B>
<P>
Hyperbolic sine. Argument is in radians.
<P>
<P>
<P>
<I>val tanh </I>
:
<B>float -&gt; float</B>
<P>
Hyperbolic tangent. Argument is in radians.
<P>
<P>
<P>
<I>val trunc </I>
:
<B>float -&gt; float</B>
<P>
<P>
<B>trunc x</B>
rounds
<B>x</B>
to the nearest integer whose absolute value is
less than or equal to
<B>x</B>
.
<P>
<P>
<B>Since</B>
4.08.0
<P>
<P>
<P>
<I>val round </I>
:
<B>float -&gt; float</B>
<P>
<P>
<B>round x</B>
rounds
<B>x</B>
to the nearest integer with ties (fractional
values of 0.5) rounded away from zero, regardless of the current
rounding direction. If
<B>x</B>
is an integer,
<B>+0.</B>
,
<B>-0.</B>
,
<B>nan</B>
, or
infinite,
<B>x</B>
itself is returned.
<P>
<P>
<B>Since</B>
4.08.0
<P>
<P>
<P>
<I>val ceil </I>
:
<B>float -&gt; float</B>
<P>
Round above to an integer value.
<B>ceil f</B>
returns the least integer value greater than or equal to
<B>f</B>
.
The result is returned as a float.
<P>
<P>
<P>
<I>val floor </I>
:
<B>float -&gt; float</B>
<P>
Round below to an integer value.
<B>floor f</B>
returns the greatest integer value less than or
equal to
<B>f</B>
.
The result is returned as a float.
<P>
<P>
<P>
<I>val next_after </I>
:
<B>float -&gt; float -&gt; float</B>
<P>
<P>
<B>next_after x y</B>
returns the next representable floating-point
value following
<B>x</B>
in the direction of
<B>y</B>
. More precisely, if
<B>y</B>
is greater (resp. less) than
<B>x</B>
, it returns the smallest
(resp. largest) representable number greater (resp. less) than
<B>x</B>
.
If
<B>x</B>
equals
<B>y</B>
, the function returns
<B>y</B>
. If
<B>x</B>
or
<B>y</B>
is
<B>nan</B>
, a
<B>nan</B>
is returned.
Note that
<B>next_after max_float infinity = infinity</B>
and that
<B>next_after 0. infinity</B>
is the smallest denormalized positive number.
If
<B>x</B>
is the smallest denormalized positive number,
<B>next_after x 0. = 0.</B>
<P>
<P>
<P>
<B>Since</B>
4.08.0
<P>
<P>
<P>
<I>val copy_sign </I>
:
<B>float -&gt; float -&gt; float</B>
<P>
<P>
<B>copy_sign x y</B>
returns a float whose absolute value is that of
<B>x</B>
and whose sign is that of
<B>y</B>
. If
<B>x</B>
is
<B>nan</B>
, returns
<B>nan</B>
.
If
<B>y</B>
is
<B>nan</B>
, returns either
<B>x</B>
or
<B>-. x</B>
, but it is not
specified which.
<P>
<P>
<P>
<I>val sign_bit </I>
:
<B>float -&gt; bool</B>
<P>
<P>
<B>sign_bit x</B>
is
<B>true</B>
iff the sign bit of
<B>x</B>
is set.
For example
<B>sign_bit 1.</B>
and
<B>signbit 0.</B>
are
<B>false</B>
while
<B>sign_bit (-1.)</B>
and
<B>sign_bit (-0.)</B>
are
<B>true</B>
.
<P>
<P>
<B>Since</B>
4.08.0
<P>
<P>
<P>
<I>val frexp </I>
:
<B>float -&gt; float * int</B>
<P>
<P>
<B>frexp f</B>
returns the pair of the significant
and the exponent of
<B>f</B>
. When
<B>f</B>
is zero, the
significant
<B>x</B>
and the exponent
<B>n</B>
of
<B>f</B>
are equal to
zero. When
<B>f</B>
is non-zero, they are defined by
<B>f = x *. 2 ** n</B>
and
<B>0.5 &lt;= x &lt; 1.0</B>
.
<P>
<P>
<P>
<I>val ldexp </I>
:
<B>float -&gt; int -&gt; float</B>
<P>
<P>
<B>ldexp x n</B>
returns
<B>x *. 2 ** n</B>
.
<P>
<P>
<P>
<I>val modf </I>
:
<B>float -&gt; float * float</B>
<P>
<P>
<B>modf f</B>
returns the pair of the fractional and integral
part of
<B>f</B>
.
<P>
<P>
<I>type t </I>
=
<B>float</B>
<P>
<P>
An alias for the type of floating-point numbers.
<P>
<P>
<P>
<I>val compare </I>
:
<B>t -&gt; t -&gt; int</B>
<P>
<P>
<B>compare x y</B>
returns
<B>0</B>
if
<B>x</B>
is equal to
<B>y</B>
, a negative integer if
<B>x</B>
is less than
<B>y</B>
, and a positive integer if
<B>x</B>
is greater than
<B>y</B>
.
<B>compare</B>
treats
<B>nan</B>
as equal to itself and less than any other float
value. This treatment of
<B>nan</B>
ensures that
<B>compare</B>
defines a total
ordering relation.
<P>
<P>
<P>
<I>val equal </I>
:
<B>t -&gt; t -&gt; bool</B>
<P>
The equal function for floating-point numbers, compared using
<B>Float.compare</B>
.
<P>
<P>
<P>
<I>val min </I>
:
<B>t -&gt; t -&gt; t</B>
<P>
<P>
<B>min x y</B>
returns the minimum of
<B>x</B>
and
<B>y</B>
. It returns
<B>nan</B>
when
<B>x</B>
or
<B>y</B>
is
<B>nan</B>
. Moreover
<B>min (-0.) (+0.) = -0.</B>
<P>
<P>
<P>
<B>Since</B>
4.08.0
<P>
<P>
<P>
<I>val max </I>
:
<B>float -&gt; float -&gt; float</B>
<P>
<P>
<B>max x y</B>
returns the maximum of
<B>x</B>
and
<B>y</B>
. It returns
<B>nan</B>
when
<B>x</B>
or
<B>y</B>
is
<B>nan</B>
. Moreover
<B>max (-0.) (+0.) = +0.</B>
<P>
<P>
<P>
<B>Since</B>
4.08.0
<P>
<P>
<P>
<I>val min_max </I>
:
<B>float -&gt; float -&gt; float * float</B>
<P>
<P>
<B>min_max x y</B>
is
<B>(min x y, max x y)</B>
, just more efficient.
<P>
<P>
<B>Since</B>
4.08.0
<P>
<P>
<P>
<I>val min_num </I>
:
<B>t -&gt; t -&gt; t</B>
<P>
<P>
<B>min_num x y</B>
returns the minimum of
<B>x</B>
and
<B>y</B>
treating
<B>nan</B>
as
missing values. If both
<B>x</B>
and
<B>y</B>
are
<B>nan</B>
,
<B>nan</B>
is returned.
Moreover
<B>min_num (-0.) (+0.) = -0.</B>
<P>
<P>
<P>
<B>Since</B>
4.08.0
<P>
<P>
<P>
<I>val max_num </I>
:
<B>t -&gt; t -&gt; t</B>
<P>
<P>
<B>max_num x y</B>
returns the maximum of
<B>x</B>
and
<B>y</B>
treating
<B>nan</B>
as
missing values. If both
<B>x</B>
and
<B>y</B>
are
<B>nan</B>
<B>nan</B>
is returned.
Moreover
<B>max_num (-0.) (+0.) = +0.</B>
<P>
<P>
<P>
<B>Since</B>
4.08.0
<P>
<P>
<P>
<I>val min_max_num </I>
:
<B>float -&gt; float -&gt; float * float</B>
<P>
<P>
<B>min_max_num x y</B>
is
<B>(min_num x y, max_num x y)</B>
, just more
efficient. Note that in particular
<B>min_max_num x nan = (x, x)</B>
and
<B>min_max_num nan y = (y, y)</B>
.
<P>
<P>
<B>Since</B>
4.08.0
<P>
<P>
<P>
<I>val hash </I>
:
<B>t -&gt; int</B>
<P>
The hash function for floating-point numbers.
<P>
<P>
<I>module Array : </I>
<B>sig end</B>
<P>
<P>
<P>
<P>
<I>module ArrayLabels : </I>
<B>sig end</B>
<P>
<P>
<P>
<P>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
<DT id="2"><A HREF="#lbAC">Module</A><DD>
<DT id="3"><A HREF="#lbAD">Documentation</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:57 GMT, March 31, 2021
</BODY>
</HTML>