package bitvec
Library
Module
Module type
Parameter
Class
Class type
M64
specializes Make(struct let modulus = m64 end)
This specialization tries to minimize calls to the arbitrary precision arithmetic library whenever, it is known that the result will not overflow the OCaml int representation.
val bool : bool -> t
bool x
returns one
if x
and zero
otherwise.
val zero : t
zero
is 0
.
val one : t
one
is 1
.
abs x mod m
absolute value of x
modulo m
.
The absolute value of x
is equal to neg x
if msb x
and to x
otherwise.
div x y mod m
is x / y
modulo m
,
where /
is the truncating towards zero division, that returns ones m
if y = 0
.
sdiv x y mod m
is signed division of x
by y
modulo m
,
The signed division operator is defined in terms of the div
operator as follows:
/ | div x y mod m : if not mx /\ not my | neg (div (neg x) y) mod m if mx /\ not my x sdiv y mod m = < | neg (div x (neg y)) mod m if not mx /\ my | div (neg x) (neg y) mod m if mx /\ my \ where mx = msb x mod m, and my = msb y mod m.
srem x y mod m
is the signed remainder x / y
modulo m
.
This version of the signed remainder where the sign follows the dividend, and is defined via the rem
operation as follows
/ | rem x y mod m : if not mx /\ not my | neg (rem (neg x) y) mod m if mx /\ not my x srem y mod m = < | neg (rem x (neg y)) mod m if not mx /\ my | neg (rem (neg x) (neg y)) mod m if mx /\ my \ where mx = msb x mod m, and my = msb y mod m.
smod x y mod m
is the signed remainder of x / y
modulo m
.
This version of the signed remainder where the sign follows the divisor, and is defined in terms of the rem
operation as follows:
/ | u if u = 0 x smod y mod m = < | v if u <> 0 \ / | u if not mx /\ not my | add (neg u) y mod m if mx /\ not my v = < | add u x mod m if not mx /\ my | neg u mod m if mx /\ my \ where mx = msb x mod m, and my = msb y mod m, and u = rem s t mod m.
nth x n mod m
is true
if n
th bit of x
is set
.
Returns msb x mod m
if n >= m
and lsb x mod m
if n < 0
arshift x y mod m
shifts x
right by y
with msb x
filling.
Returns ones mod m
if y >= m /\ msb x mod m
and zero
if y >= m /\ msb x mod m = 0
gcd x y mod m
returns the greatest common divisor modulo m
gcd x y
is the meet operation of the divisibility lattice, with 0
being the top of the lattice and 1
being the bottom, therefore gcd x 0 = gcd x 0 = x
.
lcm x y mod
returns the least common multiplier modulo m
.
lcm x y
is the meet operation of the divisibility lattice, with 0
being the top of the lattice and 1
being the bottom, therefore lcm x 0 = lcm 0 x = 0
(g,a,b) = gcdext x y mod m
, where
g = gcd x y mod m
,g = (a * x + b * y) mod m
.
The operation is well defined if one or both operands are equal to 0
, in particular:
(x,1,0) = gcdext(x,0)
,(x,0,1) = gcdext(0,x)
.
val (!$) : string -> t
!$x
is of_string x