Module Word.Int_err

Arithmetic raised into Or_error monad

All binary integer operations are only well defined on operands with equal sizes.

Module Int provides a set of integer operations that do not raise exceptions, but return values raised to an Or_error monad.

Example:

Z.(i16 v1 + i16 v2 / int 16 v3),

or just:

Z.(!$v1 + !$v2 / !$v3).

val (!$) : t -> t Core_kernel.Or_error.t

!$v lifts v to an Or_error monad. It is, essentially, the same as Ok v

The following lifter will check that their operand has a corresponding width.

val i1 : t -> t Core_kernel.Or_error.t

i1 x is Ok x iff bitwidth x = 1

val i4 : t -> t Core_kernel.Or_error.t

i4 x is Ok x iff bitwidth x = 4

val i8 : t -> t Core_kernel.Or_error.t

i8 x is Ok x iff bitwidth x = 8

val i16 : t -> t Core_kernel.Or_error.t

i16 x is Ok x iff bitwidth x = 16

val i32 : t -> t Core_kernel.Or_error.t

i32 x is Ok x iff bitwidth x = 32

val i64 : t -> t Core_kernel.Or_error.t

i64 x is Ok x iff bitwidth x = 64

val int : int -> t -> t Core_kernel.Or_error.t

int w v will be Ok if v has width w

val of_word_size : Core_kernel.Word_size.t -> t -> t Core_kernel.Or_error.t

of_word_size w creates a lifter for a specified word size w, i.e. either i64 or i32

include Integer.S with type t = t Core_kernel.Or_error.t
type t = t Core_kernel.Or_error.t
include Integer.Base with type t := t
val zero : t

element neutral to the addition

val one : t

element neutral to the multiplication

val succ : t -> t

succ n successor of n

val pred : t -> t

pred n is a predecessor of n

val abs : t -> t

abs x absolute value of x

val neg : t -> t

neg x = -x

val add : t -> t -> t

add x y is x + y

val sub : t -> t -> t

sub x y is x - y

val mul : t -> t -> t

mul x y is x * y

val div : t -> t -> t

div x y is x / y

val modulo : t -> t -> t

modulo x y is x mod y

val lnot : t -> t

lnot x is a logical negation of x (1-complement)

logand x y is a conjunction of x and y

val logand : t -> t -> t

logand x y is a conjunction of x and y

val logor : t -> t -> t

logor x y is a disjunction of x and y

val logxor : t -> t -> t

logxor x y is exclusive or between x and y

val lshift : t -> t -> t

lshift x y shift x by y bits left

val rshift : t -> t -> t

rshift x y shift x by y bits to the right

val arshift : t -> t -> t

arshift x y shift x by y bits to the right and fill with the sign bit.

A common set of infix operators

val (~-) : t -> t

~-x = neg x

val (+) : t -> t -> t

x + y = add x y

val (-) : t -> t -> t

x - y = sub x y

val (*) : t -> t -> t

x * y = mul x y

val (/) : t -> t -> t

x / y = div x y

val (mod) : t -> t -> t

x mod y = modulo x y

val (land) : t -> t -> t

x land y = logand x y

val (lor) : t -> t -> t

x lor y = logor x y

val (lxor) : t -> t -> t

lxor x y = logxor x y

val (lsl) : t -> t -> t

x lsl y = lshift x y

val (lsr) : t -> t -> t

x lsr y = rshift x y

val (asr) : t -> t -> t

x asr y = arshift x y

val (>>=) : 'a Core_kernel.Or_error.t -> ('a -> 'b Core_kernel.Or_error.t) -> 'b Core_kernel.Or_error.t
val (>>|) : 'a Core_kernel.Or_error.t -> ('a -> 'b) -> 'b Core_kernel.Or_error.t