package batteries
Install
Dune Dependency
Authors
Maintainers
Sources
md5=ea26b5c72e6731e59d856626049cca4d
sha512=55975b62c26f6db77433a3ac31f97af609fc6789bb62ac38b267249c78fd44ff37fe81901f1cf560857b9493a6046dd37b0d1c0234c66bd59e52843aac3ce6cb
doc/batteries.unthreaded/BatInt/index.html
Module BatInt
Source
Operations on integers.
This module provides operations on the type int
of integers. Values of this type may be either 31 bits on 32-bit processors or 63 bits on 64-bit processors. All arithmetic operations over int
are taken modulo 2number of bits.
This module implements Number.Numeric
, Number.Bounded
, Number.Discrete
.
@documents Int
An alias for the type of integers.
The integer 0
.
The integer 1
.
The integer -1
.
Unary negation.
Addition.
Addition.
Subtraction.
Subtraction.
Multiplication.
Multiplication.
Integer division. This division rounds the real quotient of its arguments towards zero, as specified for Pervasives.(/)
.
Integer division. This division rounds the real quotient of its arguments towards zero, as specified for Pervasives.(/)
.
Integer remainder. If y
is not zero, the result of Int.rem x y
satisfies the following property: x = Int.add (Int.mul (Int.div x y) y) (Int.rem x y)
.
modulo a b
computes the remainder of the integer division of a
by b
. This is defined only if b <> 0
.
The result of modulo a b
is a number m
between 0
and abs ( b - 1 )
if a >= 0
or between ~- ( abs ( b - 1 ) )
if a < 0
and such that a * k + (abs b) = m
, for some k
.
pow a b
computes ab.
a ** b
computes ab
The smallest representable integer, -230 or -262.
The greatest representable integer, which is either 230-1 or 262-1.
Successor. Int.succ x
is Int.add x Int.one
.
Predecessor. Int.pred x
is Int.sub x Int.one
.
Return the absolute value of its argument, except when the argument is min_num
. In that case, abs min_num = min_num
.
Convert the given floating-point number to integer integer, discarding the fractional part (truncate towards 0). The result of the conversion is undefined if, after truncation, the number is outside the range [Int.min_int
, Int.max_int
].
Convert the given integer to a floating-point number.
Convert the given string to an integer The string is read in decimal (by default) or in hexadecimal, octal or binary if the string begins with 0x
, 0o
or 0b
respectively.
Return the string representation of its argument, in signed decimal.
The minimum of two integers. Faster than the polymorphic min
from the standard library.
The maximum of two integers. Faster than the polymorphic min
from the standard library.
Midpoint function; mid a b
returns floor((a+b)/2)
, but done correctly to compensate for numeric overflows. The result is an integer that lies between a
and b
and is as equidistant from both as possible.
Returns the number of 1 bits set in the binary representation of the number. Maybe has problems with negative numbers
copysign n o
multiplies o
by the "sign" of n
, i.e. it returns either:
0
ifn=0
o
ifn>0
-o
ifn<0
Enumerate an interval.
5 -- 10
is the enumeration 5,6,7,8,9,10. 10 -- 5
is the empty enumeration
Enumerate an interval.
5 --- 10
is the enumeration 5,6,7,8,9,10. 10 --- 5
is the enumeration 10,9,8,7,6,5.
Submodules regrouping all infix operations
Boilerplate code
Printing
prints as decimal string
prints as hex string