19 lines
987 B
Text
19 lines
987 B
Text
|
|
|||
|
|
|||
|
/* Two's complement Signed Integers
|
|||
|
*/
|
|||
|
|
|||
|
export {
|
|||
|
let int-sign = λx:ℤ~machine.Int64 ↦ bit-and (bit-shr x 63) 1;
|
|||
|
let int-neg = λx:ℤ~machine.Int64 ↦ i+ (bit-neg x) 1;
|
|||
|
let int-abs = λx:ℤ~machine.Int64 ↦ if( int-sign x ) { int-neg x; } else { x; };
|
|||
|
let int-lt = λ{ a:ℤ~machine.Int64; b:ℤ~machine.Int64; } ↦ int-sign (i- a b);
|
|||
|
let int-gt = λ{ a:ℤ~machine.Int64; b:ℤ~machine.Int64; } ↦ int-sign (i- b a);
|
|||
|
let int-eq = λ{ a:ℤ~machine.Int64; b:ℤ~machine.Int64; } ↦ if (bit-xor a b) { 0; } else { 1; };
|
|||
|
let int-lte = λ{ a:ℤ~machine.Int64; b:ℤ~machine.Int64; } ↦ bit-or (int-lt a b) (int-eq a b);
|
|||
|
let int-gte = λ{ a:ℤ~machine.Int64; b:ℤ~machine.Int64; } ↦ bit-or (int-gt a b) (int-eq a b);
|
|||
|
let int-min = λ{ a:ℤ~machine.Int64; b:ℤ~machine.Int64; } ↦ if( int-lt a b ) { a; } else { b; };
|
|||
|
let int-max = λ{ a:ℤ~machine.Int64; b:ℤ~machine.Int64; } ↦ if( int-gt a b ) { a; } else { b; };
|
|||
|
};
|
|||
|
|