jon.recoil.org

Module Stdlib_stable.Int16Source

Signed 16-bit integer values.

These integers are

bits wide and use two's complement representation. All operations are taken modulo 216. They do not fail on overflow.

16-bit Integers

Sourcetype t = int16

The type for 16-bit integer values.

Sourceval size : int @@ portable

The number of bits in an integer of type int16.

Sourceval zero : int16 @@ portable

The 16-bit integer 0.

Sourceval one : int16 @@ portable

The 16-bit integer 1.

Sourceval minus_one : int16 @@ portable

The 16-bit integer -1.

Sourceval neg : int16 -> int16 @@ portable

Unary negation.

Sourceval add : int16 -> int16 -> int16 @@ portable

Addition.

Sourceval sub : int16 -> int16 -> int16 @@ portable

Subtraction.

Sourceval mul : int16 -> int16 -> int16 @@ portable

Multiplication.

Sourceval div : int16 -> int16 -> int16 @@ portable

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

Sourceval unsigned_div : int16 -> int16 -> int16 @@ portable

Same as div, except that arguments and result are interpreted as unsigned integers.

Sourceval rem : int16 -> int16 -> int16 @@ portable

Integer remainder. If y is not zero, rem x y = sub x (mul (div x y) y). If y is zero, rem x y raises Division_by_zero.

Sourceval unsigned_rem : int16 -> int16 -> int16 @@ portable

Same as rem, except that arguments and result are interpreted as unsigned integers.

Sourceval succ : int16 -> int16 @@ portable

succ x is add x 1.

Sourceval pred : int16 -> int16 @@ portable

pred x is sub x 1.

Sourceval abs : int16 -> int16 @@ portable

abs x is the absolute value of x. That is x if x is positive and neg x if x is negative. Warning. This may be negative if the argument is min_int.

Sourceval max_int : int16 @@ portable

max_int is the greatest representable integer, 2{^[size - 1]} - 1.

Sourceval min_int : int16 @@ portable

min_int is the smallest representable integer, -2{^[size - 1]}.

Sourceval logand : int16 -> int16 -> int16 @@ portable

Bitwise logical and.

Sourceval logor : int16 -> int16 -> int16 @@ portable

Bitwise logical or.

Sourceval logxor : int16 -> int16 -> int16 @@ portable

Bitwise logical exclusive or.

Sourceval lognot : int16 -> int16 @@ portable

Bitwise logical negation.

Sourceval shift_left : int16 -> int -> int16 @@ portable

shift_left x n shifts x to the left by n bits. The result is unspecified if n < 0 or n >= size.

Sourceval shift_right : int16 -> int -> int16 @@ portable

shift_right x n shifts x to the right by n bits. This is an arithmetic shift: the sign bit of x is replicated and inserted in the vacated bits. The result is unspecified if n < 0 or n >=size.

Sourceval shift_right_logical : int16 -> int -> int16 @@ portable

shift_right x n shifts x to the right by n bits. This is a logical shift: zeroes are inserted in the vacated bits regardless of the sign of x. The result is unspecified if n < 0 or n >=size.

Predicates and comparisons

Sourceval equal : int16 -> int16 -> bool @@ portable

equal x y is true if and only if x = y.

Sourceval compare : int16 -> int16 -> int @@ portable

compare x y is Stdlib.compare x y but more efficient.

Sourceval unsigned_compare : int16 -> int16 -> int @@ portable

Same as compare, except that arguments are interpreted as unsigned integers.

Sourceval min : int16 -> int16 -> int16 @@ portable

Return the lesser of the two arguments.

Sourceval max : int16 -> int16 -> int16 @@ portable

Return the greater of the two arguments.

Converting

Sourceval to_int : int16 -> int @@ portable

to_int x is x as an int.

Sourceval of_int : int -> int16 @@ portable

of_int x truncates the representation of x to fit in int16.

Sourceval unsigned_to_int : int16 -> int @@ portable

Same as to_int, but interprets the argument as an unsigned integer.

Sourceval to_float : int16 -> float @@ portable

to_float x is x as a floating point number.

Sourceval of_float : float -> int16 @@ portable

of_float x truncates x to an integer. The result is unspecified if the argument is nan or falls outside the range of representable integers.

Sourceval to_string : int16 -> string @@ portable

to_string x is the written representation of x in decimal.

Sourceval of_string : string -> int16 @@ portable

Convert the given string to a 16-bit integer. The string is read in decimal (by default, or if the string begins with 0u) or in hexadecimal, octal or binary if the string begins with 0x, 0o or 0b respectively.

The 0u prefix reads the input as an unsigned integer in the range [0, 2*Int16.max_int+1]. If the input exceeds Int16.max_int it is converted to the signed integer Int16.min_int + input - Int16.max_int - 1.

The _ (underscore) character can appear anywhere in the string and is ignored.

  • 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 int16.

Sourceval seeded_hash : int -> int16 -> int @@ portable

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.

Sourceval hash : int16 -> int @@ portable

An unseeded hash function for ints, with the same output value as Hashtbl.hash. This function allows this module to be passed as argument to the functor Hashtbl.Make.