jon.recoil.org

Module Stdlib_upstream_compatible.Int32_uSource

Unboxed 32-bit integers. This file primarily duplicates functionality from the Int32 module, but for int32#.

This module provides operations on the type int32# of unboxed signed 32-bit integers. Unlike the built-in int type, the type int32# is guaranteed to be exactly 32-bits wide on all platforms. All arithmetic operations over int32# are wrapping, not truncating.

Sourcetype t = int32#

An alias for the type of unboxed 32-bit integers.

Sourceval to_int32 : t -> int32 @@ portable

Box a int32#

Sourceval of_int32 : int32 -> t @@ portable

Unbox a boxed int32

Sourceval neg : t -> t @@ portable

Unary negation.

Sourceval add : t -> t -> t @@ portable

Addition.

Sourceval sub : t -> t -> t @@ portable

Subtraction.

Sourceval mul : t -> t -> t @@ portable

Multiplication.

Sourceval div : t -> t -> t @@ portable

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

Sourceval unsigned_div : t -> t -> t @@ portable

Same as div, except that arguments and result are interpreted as unsigned unboxed 32-bit integers.

Sourceval rem : t -> t -> t @@ portable

Integer remainder. If y is not zero, the result of Int32_u.rem x y satisfies the following property: x = Int32_u.add (Int32_u.mul (Int32_u.div x y) y) (Int32_u.rem x y). If y = 0, Int32_u.rem x y raises Division_by_zero.

Sourceval unsigned_rem : t -> t -> t @@ portable

Same as rem, except that arguments and result are interpreted as unsigned unboxed 32-bit integers.

Sourceval succ : t -> t @@ portable

Successor. Int32_u.succ x is Int32_u.add x Int32_u.one.

Sourceval pred : t -> t @@ portable

Predecessor. Int32_u.pred x is Int32_u.sub x Int32_u.one.

Sourceval abs : t -> t @@ portable

Return the absolute value of its argument.

Sourceval logand : t -> t -> t @@ portable

Bitwise logical and.

Sourceval logor : t -> t -> t @@ portable

Bitwise logical or.

Sourceval logxor : t -> t -> t @@ portable

Bitwise logical exclusive or.

Sourceval lognot : t -> t @@ portable

Bitwise logical negation.

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

Int32_u.shift_left x y shifts x to the left by y bits. The result is unspecified if y < 0 or y >= 32.

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

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

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

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

Sourceval of_int : int -> t @@ portable

Convert the given integer (type int) to an unboxed 32-bit integer (type int32#). On 64-bit platforms, the argument is taken modulo 232.

Sourceval to_int : t -> int @@ portable

Convert the given unboxed 32-bit integer (type int32#) to an integer (type int). On 32-bit platforms, the 32-bit integer is taken modulo 231, i.e. the high-order bit is lost during the conversion. On 64-bit platforms, the conversion is exact.

Sourceval unsigned_to_int : t -> int option @@ portable

Same as to_int, but interprets the argument as an unsigned integer. Returns None if the unsigned value of the argument cannot fit into an int.

Sourceval of_float : float -> t @@ portable

Convert the given floating-point number to an unboxed 32-bit integer, discarding the fractional part (truncate towards 0). If the truncated floating-point number is outside the range [Int32_u.min_int, Int32_u.max_int], no exception is raised, and an unspecified, platform-dependent integer is returned.

Sourceval to_float : t -> float @@ portable

Convert the given unboxed 32-bit integer to a floating-point number.

Sourceval of_string : string -> t @@ portable

Convert the given string to an unboxed 32-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*Int32_u.max_int+1]. If the input exceeds Int32_u.max_int it is converted to the signed integer Int32.min_int + input - Int32_u.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 int32.

Sourceval to_string : t -> string @@ portable

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

Sourceval bits_of_float : float -> t @@ portable

Return the internal representation of the given float according to the IEEE 754 floating-point 'single format' bit layout. Bit 31 of the result represents the sign of the float; bits 30 to 23 represent the (biased) exponent; bits 22 to 0 represent the mantissa.

Sourceval float_of_bits : t -> float @@ portable

Return the floating-point number whose internal representation, according to the IEEE 754 floating-point 'single format' bit layout, is the given int32#.

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

The comparison function for unboxed 32-bit integers, with the same specification as Stdlib.compare.

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

Same as compare, except that arguments are interpreted as unsigned unboxed 32-bit integers.

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

The equal function for unboxed 32-bit ints.

Sourceval min : t -> t -> t @@ portable

Return the smaller of the two arguments.

Sourceval max : t -> t -> t @@ portable

Return the greater of the two arguments.