BatInt
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
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
.
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 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.
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
if n=0
o
if n>0
-o
if n<0
val operations : int BatNumber.numeric
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.
module Infix : BatNumber.Infix with type bat__infix_t = t
module Compare : BatNumber.Compare with type bat__compare_t = t
val print : 'a BatInnerIO.output -> int -> unit
prints as decimal string
val print_hex : 'a BatInnerIO.output -> int -> unit
prints as hex string
The comparison function for integers, with the same specification as Pervasives
.compare. Along with the type t
, this function compare
allows the module Int
to be passed as argument to the functors Set
.Make and Map
.Make.
val ord : t -> t -> BatOrd.order
module Safe_int : sig ... end
Safe operations on integers.