package containers

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module CCIntSource

Basic Int functions

Integers

Sourceval fdiv : int -> int -> int

Floor division. fdiv x y is the real quotient x / y rounded down to an integer. We have fdiv x y <= div x y <= cdiv x y and cdiv x y - fdiv x y <= 1.

  • since 5.5
Sourceval cdiv : int -> int -> int

Ceil division. cdiv x y is the real quotient x / y rounded up to an integer. We have fdiv x y <= div x y <= cdiv x y and cdiv x y - fdiv x y <= 1.

  • since 5.5
Sourceval ediv : int -> int -> int

Euclidean division. ediv x y is the real quotient x / y rounded down to an integer if y > 0 and rounded up to an integer if y < 0. The remainder erem x y = x - ediv x y * y is always non-negative. Moreover, ediv x (-y) = - ediv x y.

  • since 5.5
Sourceval erem : int -> int -> int

Euclidean remainder. If y is not zero, we have x = ediv x y * y + erem x y and 0 <= erem x y <= abs y - 1. The result of erem x y is always non-negative, unlike the result of rem x y, which has the sign of x.

  • since 5.5

Predicates and comparisons

Bit counting

Sourceval unsigned_bitsize : int -> int

unsigned_bitsize n is the minimal number of bits needed to represent n as an unsigned binary number. It is the smallest integer i between 0 and Sys.int_size inclusive such that 0 <= n < 2{^i} (unsigned).

  • since 5.5
Sourceval signed_bitsize : int -> int

signed_bitsize n is the minimal number of bits needed to represent n as a signed, two's complement binary number. It is the smallest integer i between 1 and Sys.int_size inclusive such that -2{^i-1} <= n < 2{^i-1} (signed).

  • since 5.5
Sourceval leading_zeros : int -> int

leading_zeros n is the number of leading (most significant) 0 bits in the binary representation of n. It is an integer between 0 and Sys.int_size inclusive. If n is negative, leading_zeros n = 0 since the most significant bit of n is 1. leading_zeros n = {!Sys.int_size} if and only if n = zero. Note that leading_zeros n + unsigned_bitsize n = {!Sys.int_size}.

  • since 5.5
Sourceval leading_sign_bits : int -> int

leading_sign_bits n is the number of leading (most significant) sign bits in the binary representation of n, excluding the sign bit itself. It is an integer between 0 and {!Sys.int_size} - 1 inclusive. For positive n, it is the number of leading zero bits minus one. For negative n, it is the number of leading one bits minus one. Note that leading_sign_bits n + signed_bitsize n = {!Sys.int_size}.

  • since 5.5
Sourceval trailing_zeros : int -> int

trailing_zeros n is the number of trailing (least significant) 0 bits in the binary representation of n. It is an integer between 0 and Sys.int_size inclusive. It is the largest integer i <= {!Sys.int_size} such that 2{^i} divides n evenly. For example, trailing_zeros n = 0 if and only if n is odd, and trailing_zeros n = {!Sys.int_size} if and only if n = zero.

  • since 5.5

Converting

Sourceval seeded_hash : int -> int -> int

A seeded hash function for ints, with the same output value as Hashtbl.seeded_hash. This function allows this module to be passed as argument to the functor Hashtbl.MakeSeeded.

  • since 5.1
Sourcetype t = int
Sourceval zero : t

zero is the integer 0.

  • since 3.0
Sourceval one : t

one is the integer 1.

  • since 3.0
Sourceval minus_one : t

minus_one is the integer -1.

  • since 3.0
Sourceval add : t -> t -> t

add x y is x + y.

  • since 3.0
Sourceval sub : t -> t -> t

sub x y is x - y.

  • since 3.0
Sourceval mul : t -> t -> t

mul x y is x * y.

  • since 3.0
Sourceval div : t -> t -> t

div x y is x / y

  • since 3.0
Sourceval succ : t -> t

succ x is x + 1.

  • since 3.0
Sourceval pred : t -> t

pred x is x - 1.

  • since 3.0
Sourceval abs : t -> t

abs x is the absolute value of x. It is x if x is positive and neg x otherwise.

  • since 3.0
Sourceval max_int : t

max_int is the maximum integer.

  • since 3.0
Sourceval min_int : t

min_int is the minimum integer.

  • since 3.0
Sourceval compare : t -> t -> int

compare x y is the comparison function for integers with the same specification as Stdlib.compare.

Sourceval equal : t -> t -> bool

equal x y is true iff x and y are equal. Equality function for integers.

Sourceval hash : t -> int

hash x computes the hash of x.

Sourceval sign : t -> int

sign x return 0 if x = 0, -1 if x < 0 and 1 if x > 0. Same as compare x 0.

Sourceval neg : t -> t

neg x is - x. Unary negation.

  • since 0.5
Sourceval pow : t -> t -> t

pow base exponent returns base raised to the power of exponent. pow x y = x^y for positive integers x and y. Raises Invalid_argument if x = y = 0 or y < 0.

  • since 0.11
Sourceval floor_div : t -> t -> t

floor_div x n is integer division rounding towards negative infinity. It satisfies x = m * floor_div x n + rem x n.

  • since 1.2
Sourceval rem : t -> t -> t

rem x n is the remainder of dividing x by n, with the same sign as n.

  • since 1.2
Sourcetype 'a printer = Format.formatter -> 'a -> unit
Sourcetype 'a random_gen = Random.State.t -> 'a
Sourcetype 'a iter = ('a -> unit) -> unit
Sourceval random : int -> t random_gen
Sourceval random_small : t random_gen
Sourceval random_range : int -> int -> t random_gen
Sourceval pp : t printer

pp ppf x prints the integer x on ppf.

Sourceval to_float : t -> float

to_float is the same as float_of_int

  • since 3.0
Sourceval to_string : t -> string

to_string x returns the string representation of the integer x, in signed decimal.

  • since 0.13
Sourceval of_string : string -> t option

of_string s converts the given string s into an integer. Safe version of of_string_exn.

  • since 0.13
Sourceval of_string_exn : string -> t

of_string_exn s converts the given string s to an integer. Alias to int_of_string.

  • since 3.0
Sourceval of_float : float -> t

of_float x converts the given floating-point number x to an integer. Alias to int_of_float.

  • since 3.0
Sourceval pp_binary : t printer

pp_binary ppf x prints x on ppf. Print as "0b00101010".

  • since 0.20
Sourceval to_string_binary : t -> string

to_string_binary x returns the string representation of the integer x, in binary.

  • since 0.20
Sourceval min : t -> t -> t

min x y returns the minimum of the two integers x and y.

  • since 0.17
Sourceval max : t -> t -> t

max x y returns the maximum of the two integers x and y.

  • since 0.17
Sourceval range_by : step:t -> t -> t -> t iter

range_by ~step i j iterates on integers from i to j included, where the difference between successive elements is step. Use a negative step for a decreasing list.

  • since 1.2
Sourceval range : t -> t -> t iter

range i j iterates on integers from i to j included . It works both for decreasing and increasing ranges.

  • since 1.2
Sourceval range' : t -> t -> t iter

range' i j is like range but the second bound j is excluded. For instance range' 0 5 = Iter.of_list [0;1;2;3;4].

  • since 1.2
Sourceval popcount : t -> int

Number of bits set to 1

  • since 3.0
Sourceval logand : t -> t -> t

logand is the same as (land).

  • since 3.0
Sourceval logor : t -> t -> t

logand is the same as (lor).

  • since 3.0
Sourceval logxor : t -> t -> t

logxor is the same as (lxor).

  • since 3.0
Sourceval lognot : t -> t

logand is the same as lnot.

  • since 3.0
Sourceval shift_left : t -> int -> t

shift_left is the same as (lsl).

  • since 3.0
Sourceval shift_right : t -> int -> t

shift_right is the same as (asr).

  • since 3.0
Sourceval shift_right_logical : t -> int -> t

shift_right_logical is the same as (lsr).

  • since 3.0

Infix Operators

  • since 0.17
Sourcemodule Infix : sig ... end
include module type of Infix
Sourceval (=) : t -> t -> bool
  • since 0.17
Sourceval (<>) : t -> t -> bool
  • since 0.17
Sourceval (<) : t -> t -> bool
  • since 0.17
Sourceval (>) : t -> t -> bool
  • since 0.17
Sourceval (<=) : t -> t -> bool
  • since 0.17
Sourceval (>=) : t -> t -> bool
  • since 0.17
Sourceval (--) : t -> t -> t iter

Alias to range.

  • since 1.2
Sourceval (--^) : t -> t -> t iter

Alias to range'.

  • since 1.2
Sourceval (+) : t -> t -> t
  • since 2.1
Sourceval (-) : t -> t -> t
  • since 2.1
Sourceval (~-) : t -> t
  • since 2.1
Sourceval (*) : t -> t -> t
  • since 2.1
Sourceval (/) : t -> t -> t
  • since 2.1
Sourceval (**) : t -> t -> t
  • since 2.4
Sourceval (mod) : t -> t -> t
  • since 2.1
Sourceval (land) : t -> t -> t
  • since 2.1
Sourceval (lor) : t -> t -> t
  • since 2.1
Sourceval (lxor) : t -> t -> t
  • since 2.1
Sourceval lnot : t -> t
  • since 2.1
Sourceval (lsl) : t -> int -> t
  • since 2.1
Sourceval (lsr) : t -> int -> t
  • since 2.1
Sourceval (asr) : t -> int -> t
  • since 2.1