.TH "Targetint" 3o 2023-09-18 OCamldoc "OCaml library" .SH NAME Targetint \- Target processor-native integers. .SH Module Module Targetint .SH Documentation .sp Module .BI "Targetint" : .B sig end .sp Target processor\-native integers\&. .sp This module provides operations on the type of signed 32\-bit integers (on 32\-bit target platforms) or signed 64\-bit integers (on 64\-bit target platforms)\&. This integer type has exactly the same width as that of a pointer type in the C compiler\&. All arithmetic operations over are taken modulo 2^32 or 2^64 depending on the word size of the target architecture\&. .sp Warning: this module is unstable and part of .ft B Compiler_libs .ft R \&. .sp .sp .sp .I type t .sp The type of target integers\&. .sp .I val zero : .B t .sp The target integer 0\&. .sp .I val one : .B t .sp The target integer 1\&. .sp .I val minus_one : .B t .sp The target integer \-1\&. .sp .I val neg : .B t -> t .sp Unary negation\&. .sp .I val add : .B t -> t -> t .sp Addition\&. .sp .I val sub : .B t -> t -> t .sp Subtraction\&. .sp .I val mul : .B t -> t -> t .sp Multiplication\&. .sp .I val div : .B t -> t -> t .sp Integer division\&. Raise .ft B Division_by_zero .ft R if the second argument is zero\&. This division rounds the real quotient of its arguments towards zero, as specified for .ft B (/) .ft R \&. .sp .I val unsigned_div : .B t -> t -> t .sp Same as .ft B Targetint\&.div .ft R , except that arguments and result are interpreted as unsigned integers\&. .sp .I val rem : .B t -> t -> t .sp Integer remainder\&. If .ft B y .ft R is not zero, the result of .ft B Targetint\&.rem x y .ft R satisfies the following properties: .ft B Targetint\&.zero <= Nativeint\&.rem x y < Targetint\&.abs y .ft R and .ft B x = Targetint\&.add (Targetint\&.mul (Targetint\&.div x y) y) .br \& (Targetint\&.rem x y) .ft R \&. If .ft B y = 0 .ft R , .ft B Targetint\&.rem x y .ft R raises .ft B Division_by_zero .ft R \&. .sp .I val unsigned_rem : .B t -> t -> t .sp Same as .ft B Targetint\&.rem .ft R , except that arguments and result are interpreted as unsigned integers\&. .sp .I val succ : .B t -> t .sp Successor\&. .ft B Targetint\&.succ x .ft R is .ft B Targetint\&.add x Targetint\&.one .ft R \&. .sp .I val pred : .B t -> t .sp Predecessor\&. .ft B Targetint\&.pred x .ft R is .ft B Targetint\&.sub x Targetint\&.one .ft R \&. .sp .I val abs : .B t -> t .sp Return the absolute value of its argument\&. .sp .I val size : .B int .sp The size in bits of a target native integer\&. .sp .I val max_int : .B t .sp The greatest representable target integer, either 2^31 \- 1 on a 32\-bit platform, or 2^63 \- 1 on a 64\-bit platform\&. .sp .I val min_int : .B t .sp The smallest representable target integer, either \-2^31 on a 32\-bit platform, or \-2^63 on a 64\-bit platform\&. .sp .I val logand : .B t -> t -> t .sp Bitwise logical and\&. .sp .I val logor : .B t -> t -> t .sp Bitwise logical or\&. .sp .I val logxor : .B t -> t -> t .sp Bitwise logical exclusive or\&. .sp .I val lognot : .B t -> t .sp Bitwise logical negation\&. .sp .I val shift_left : .B t -> int -> t .sp .ft B Targetint\&.shift_left x y .ft R shifts .ft B x .ft R to the left by .ft B y .ft R bits\&. The result is unspecified if .ft B y < 0 .ft R or .ft B y >= bitsize .ft R , where .ft B bitsize .ft R is .ft B 32 .ft R on a 32\-bit platform and .ft B 64 .ft R on a 64\-bit platform\&. .sp .I val shift_right : .B t -> int -> t .sp .ft B Targetint\&.shift_right x y .ft R shifts .ft B x .ft R to the right by .ft B y .ft R bits\&. This is an arithmetic shift: the sign bit of .ft B x .ft R is replicated and inserted in the vacated bits\&. The result is unspecified if .ft B y < 0 .ft R or .ft B y >= bitsize .ft R \&. .sp .I val shift_right_logical : .B t -> int -> t .sp .ft B Targetint\&.shift_right_logical x y .ft R shifts .ft B x .ft R to the right by .ft B y .ft R bits\&. This is a logical shift: zeroes are inserted in the vacated bits regardless of the sign of .ft B x .ft R \&. The result is unspecified if .ft B y < 0 .ft R or .ft B y >= bitsize .ft R \&. .sp .I val of_int : .B int -> t .sp Convert the given integer (type .ft B int .ft R ) to a target integer (type .ft B t .ft R ), module the target word size\&. .sp .I val of_int_exn : .B int -> t .sp Convert the given integer (type .ft B int .ft R ) to a target integer (type .ft B t .ft R )\&. Raises a fatal error if the conversion is not exact\&. .sp .I val to_int : .B t -> int .sp Convert the given target integer (type .ft B t .ft R ) to an integer (type .ft B int .ft R )\&. The high\-order bit is lost during the conversion\&. .sp .I val of_float : .B float -> t .sp Convert the given floating\-point number to a target integer, discarding the fractional part (truncate towards 0)\&. The result of the conversion is undefined if, after truncation, the number is outside the range [ .ft B Targetint\&.min_int .ft R , .ft B Targetint\&.max_int .ft R ]\&. .sp .I val to_float : .B t -> float .sp Convert the given target integer to a floating\-point number\&. .sp .I val of_int32 : .B int32 -> t .sp Convert the given 32\-bit integer (type .ft B int32 .ft R ) to a target integer\&. .sp .I val to_int32 : .B t -> int32 .sp Convert the given target integer to a 32\-bit integer (type .ft B int32 .ft R )\&. On 64\-bit platforms, the 64\-bit native integer is taken modulo 2^32, i\&.e\&. the top 32 bits are lost\&. On 32\-bit platforms, the conversion is exact\&. .sp .I val of_int64 : .B int64 -> t .sp Convert the given 64\-bit integer (type .ft B int64 .ft R ) to a target integer\&. .sp .I val to_int64 : .B t -> int64 .sp Convert the given target integer to a 64\-bit integer (type .ft B int64 .ft R )\&. .sp .I val of_string : .B string -> t .sp Convert the given string to a target integer\&. The string is read in decimal (by default) or in hexadecimal, octal or binary if the string begins with .ft B 0x .ft R , .ft B 0o .ft R or .ft B 0b .ft R respectively\&. Raise .ft B Failure "int_of_string" .ft R 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 .ft B nativeint .ft R \&. .sp .I val to_string : .B t -> string .sp Return the string representation of its argument, in decimal\&. .sp .I val compare : .B t -> t -> int .sp The comparison function for target integers, with the same specification as .ft B compare .ft R \&. Along with the type .ft B t .ft R , this function .ft B compare .ft R allows the module .ft B Targetint .ft R to be passed as argument to the functors .ft B Set\&.Make .ft R and .ft B Map\&.Make .ft R \&. .sp .I val unsigned_compare : .B t -> t -> int .sp Same as .ft B Targetint\&.compare .ft R , except that arguments are interpreted as unsigned integers\&. .sp .I val equal : .B t -> t -> bool .sp The equal function for target ints\&. .sp .I type repr = | Int32 .B of .B int32 | Int64 .B of .B int64 .sp .sp .I val repr : .B t -> repr .sp The concrete representation of a native integer\&. .sp .I val print : .B Format.formatter -> t -> unit .sp Print a target integer to a formatter\&. .sp