610 lines
5.6 KiB
HTML
610 lines
5.6 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of Int</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>Int</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"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
Int - Integer values.
|
|
<A NAME="lbAC"> </A>
|
|
<H2>Module</H2>
|
|
|
|
Module Int
|
|
<A NAME="lbAD"> </A>
|
|
<H2>Documentation</H2>
|
|
|
|
<P>
|
|
Module
|
|
<B>Int</B>
|
|
|
|
<BR> :
|
|
<B>sig end</B>
|
|
|
|
<P>
|
|
<P>
|
|
Integer values.
|
|
<P>
|
|
Integers are
|
|
<B>Sys.int_size</B>
|
|
|
|
bits wide and use two's complement
|
|
representation. All operations are taken modulo
|
|
2^
|
|
<B>Sys.int_size</B>
|
|
|
|
. They do not fail on overflow.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H3>Integers</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<I>type t </I>
|
|
|
|
=
|
|
<B>int</B>
|
|
|
|
<P>
|
|
<P>
|
|
The type for integer values.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val zero </I>
|
|
|
|
:
|
|
<B>int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>zero</B>
|
|
|
|
is the integer
|
|
<B>0</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val one </I>
|
|
|
|
:
|
|
<B>int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>one</B>
|
|
|
|
is the integer
|
|
<B>1</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val minus_one </I>
|
|
|
|
:
|
|
<B>int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>minus_one</B>
|
|
|
|
is the integer
|
|
<B>-1</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val neg </I>
|
|
|
|
:
|
|
<B>int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>neg x</B>
|
|
|
|
is
|
|
<B>~-x</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val add </I>
|
|
|
|
:
|
|
<B>int -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>add x y</B>
|
|
|
|
is the addition
|
|
<B>x + y</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val sub </I>
|
|
|
|
:
|
|
<B>int -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>sub x y</B>
|
|
|
|
is the subtraction
|
|
<B>x - y</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val mul </I>
|
|
|
|
:
|
|
<B>int -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>mul x y</B>
|
|
|
|
is the multiplication
|
|
<B>x * y</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val div </I>
|
|
|
|
:
|
|
<B>int -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>div x y</B>
|
|
|
|
is the division
|
|
<B>x / y</B>
|
|
|
|
. See
|
|
<B>(/)</B>
|
|
|
|
for details.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val rem </I>
|
|
|
|
:
|
|
<B>int -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>rem x y</B>
|
|
|
|
is the remainder
|
|
<B>x mod y</B>
|
|
|
|
. See
|
|
<B>(mod)</B>
|
|
|
|
for details.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val succ </I>
|
|
|
|
:
|
|
<B>int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>succ x</B>
|
|
|
|
is
|
|
<B>add x 1</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val pred </I>
|
|
|
|
:
|
|
<B>int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>pred x</B>
|
|
|
|
is
|
|
<B>sub x 1</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val abs </I>
|
|
|
|
:
|
|
<B>int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>abs x</B>
|
|
|
|
is the absolute value of
|
|
<B>x</B>
|
|
|
|
. That is
|
|
<B>x</B>
|
|
|
|
if
|
|
<B>x</B>
|
|
|
|
is positive
|
|
and
|
|
<B>neg x</B>
|
|
|
|
if
|
|
<B>x</B>
|
|
|
|
is negative. Warning. This may be negative if
|
|
the argument is
|
|
<B>Int.min_int</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val max_int </I>
|
|
|
|
:
|
|
<B>int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>max_int</B>
|
|
|
|
is the greatest representable integer,
|
|
<B>2{^[Sys.int_size - 1]} - 1</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val min_int </I>
|
|
|
|
:
|
|
<B>int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>min_int</B>
|
|
|
|
is the smallest representable integer,
|
|
<B>-2{^[Sys.int_size - 1]}</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val logand </I>
|
|
|
|
:
|
|
<B>int -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>logand x y</B>
|
|
|
|
is the bitwise logical and of
|
|
<B>x</B>
|
|
|
|
and
|
|
<B>y</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val logor </I>
|
|
|
|
:
|
|
<B>int -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>logor x y</B>
|
|
|
|
is the bitwise logical or of
|
|
<B>x</B>
|
|
|
|
and
|
|
<B>y</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val logxor </I>
|
|
|
|
:
|
|
<B>int -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>logxor x y</B>
|
|
|
|
is the bitwise logical exclusive or of
|
|
<B>x</B>
|
|
|
|
and
|
|
<B>y</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val lognot </I>
|
|
|
|
:
|
|
<B>int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>lognot x</B>
|
|
|
|
is the bitwise logical negation of
|
|
<B>x</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val shift_left </I>
|
|
|
|
:
|
|
<B>int -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>shift_left x n</B>
|
|
|
|
shifts
|
|
<B>x</B>
|
|
|
|
to the left by
|
|
<B>n</B>
|
|
|
|
bits. The result
|
|
is unspecified if
|
|
<B>n < 0</B>
|
|
|
|
or
|
|
<B>n > </B>
|
|
|
|
<B>Sys.int_size</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val shift_right </I>
|
|
|
|
:
|
|
<B>int -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>shift_right x n</B>
|
|
|
|
shifts
|
|
<B>x</B>
|
|
|
|
to the right by
|
|
<B>n</B>
|
|
|
|
bits. This is an
|
|
arithmetic shift: the sign bit of
|
|
<B>x</B>
|
|
|
|
is replicated and inserted
|
|
in the vacated bits. The result is unspecified if
|
|
<B>n < 0</B>
|
|
|
|
or
|
|
<B>n > </B>
|
|
|
|
<B>Sys.int_size</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val shift_right_logical </I>
|
|
|
|
:
|
|
<B>int -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>shift_right x n</B>
|
|
|
|
shifts
|
|
<B>x</B>
|
|
|
|
to the right by
|
|
<B>n</B>
|
|
|
|
bits. This is a
|
|
logical shift: zeroes are inserted in the vacated bits regardless
|
|
of the sign of
|
|
<B>x</B>
|
|
|
|
. The result is unspecified if
|
|
<B>n < 0</B>
|
|
|
|
or
|
|
<B>n > </B>
|
|
|
|
<B>Sys.int_size</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H3>Predicates and comparisons</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val equal </I>
|
|
|
|
:
|
|
<B>int -> int -> bool</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>equal x y</B>
|
|
|
|
is
|
|
<B>true</B>
|
|
|
|
iff
|
|
<B>x = y</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val compare </I>
|
|
|
|
:
|
|
<B>int -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>compare x y</B>
|
|
|
|
is
|
|
<B>compare</B>
|
|
|
|
<B>x y</B>
|
|
|
|
but more efficient.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAG"> </A>
|
|
<H3>Converting</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val to_float </I>
|
|
|
|
:
|
|
<B>int -> float</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>to_float x</B>
|
|
|
|
is
|
|
<B>x</B>
|
|
|
|
as a floating point number.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val of_float </I>
|
|
|
|
:
|
|
<B>float -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>of_float x</B>
|
|
|
|
truncates
|
|
<B>x</B>
|
|
|
|
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 to_string </I>
|
|
|
|
:
|
|
<B>int -> string</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>to_string x</B>
|
|
|
|
is the written representation of
|
|
<B>x</B>
|
|
|
|
in decimal.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </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>
|
|
<DT id="4"><A HREF="#lbAE">Integers</A><DD>
|
|
<DT id="5"><A HREF="#lbAF">Predicates and comparisons</A><DD>
|
|
<DT id="6"><A HREF="#lbAG">Converting</A><DD>
|
|
</DL>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:46 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|