package batteries

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

Module BatIntSource

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.

  • author Gabriel Scherer
  • author David Teller

@documents Int

Sourcetype t = int

An alias for the type of integers.

Sourceval zero : int

The integer 0.

Sourceval one : int

The integer 1.

Sourceval minus_one : int

The integer -1.

Sourceval neg : int -> int

Unary negation.

Sourceval add : int -> int -> int

Addition.

Sourceval (+) : int -> int -> int

Addition.

Sourceval sub : int -> int -> int

Subtraction.

Sourceval (-) : int -> int -> int

Subtraction.

Sourceval mul : int -> int -> int

Multiplication.

Sourceval (*) : int -> int -> int

Multiplication.

Sourceval div : int -> int -> int

Integer division. This division rounds the real quotient of its arguments towards zero, as specified for Pervasives.(/).

Sourceval (/) : int -> int -> int

Integer division. This division rounds the real quotient of its arguments towards zero, as specified for Pervasives.(/).

Sourceval rem : int -> int -> int

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).

Sourceval modulo : int -> int -> int

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.

Sourceval pow : int -> int -> int

pow a b computes ab.

Sourceval (**) : int -> int -> int

a ** b computes ab

Sourceval (<>) : int -> int -> bool
Sourceval (>) : int -> int -> bool
Sourceval (<) : int -> int -> bool
Sourceval (>=) : int -> int -> bool
Sourceval (<=) : int -> int -> bool
Sourceval (=) : int -> int -> bool
Sourceval min_num : int

The smallest representable integer, -230 or -262.

Sourceval max_num : int

The greatest representable integer, which is either 230-1 or 262-1.

Sourceval succ : int -> int

Successor. Int.succ x is Int.add x Int.one.

Sourceval pred : int -> int

Predecessor. Int.pred x is Int.sub x Int.one.

Sourceval abs : int -> int

Return the absolute value of its argument, except when the argument is min_num. In that case, abs min_num = min_num.

Sourceval of_float : float -> int

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].

Sourceval to_float : int -> float

Convert the given integer to a floating-point number.

Sourceval of_string : string -> 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.

  • raises Failure

    if the given string is not a valid representation of an integer, or if the integer represented exceeds the range of integers representable in type int.

Sourceval to_string : int -> string

Return the string representation of its argument, in signed decimal.

Sourceval min : int -> int -> int

The minimum of two integers. Faster than the polymorphic min from the standard library.

Sourceval max : int -> int -> int

The maximum of two integers. Faster than the polymorphic min from the standard library.

Sourceval mid : int -> int -> int

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.

Sourceval popcount : int -> int

Returns the number of 1 bits set in the binary representation of the number. Maybe has problems with negative numbers

Sourceval copysign : int -> int -> int

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
  • since 2.3.0
Sourceval operations : int BatNumber.numeric
Sourceval (--) : t -> t -> t BatEnum.t

Enumerate an interval.

5 -- 10 is the enumeration 5,6,7,8,9,10. 10 -- 5 is the empty enumeration

Sourceval (---) : t -> t -> t BatEnum.t

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.

Sourceval of_int : int -> int
Sourceval to_int : int -> int

Submodules regrouping all infix operations

Boilerplate code

Printing

Sourceval print : 'a BatInnerIO.output -> int -> unit

prints as decimal string

Sourceval print_hex : 'a BatInnerIO.output -> int -> unit

prints as hex string

Compare

Sourceval compare : t -> t -> int

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.

Sourceval equal : t -> t -> bool

Equality function for integers, useful for HashedType.

Sourceval ord : t -> t -> BatOrd.order
Sourcemodule Safe_int : sig ... end

Safe operations on integers.

OCaml

Innovation. Community. Security.