lt-core/lt-stdlib/int.lt
2024-12-24 12:51:36 +01:00

95 lines
2.6 KiB
Text
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* Two's complement Signed Integers
*/
export {
import "./lt-stdlib/bool.lt";
let int-sign =
λ x: machine.Int64~machine.Word
↦ (bit-and (bit-shr (x des machine.Word) 63) 1) as Bool;
let int-neg =
λ x: machine.Int64~machine.Word
↦ i+ ((bit-neg x) as machine.Int64) 1;
let int-abs =
λ x: machine.Int64~machine.Word
↦ if( int-sign x ) { int-neg x; } else { x; };
let int-lt =
λ{ a: machine.Int64~machine.Word;
b: machine.Int64~machine.Word; }
↦ int-sign (i- a b);
let int-gt =
λ{ a: machine.Int64~machine.Word;
b: machine.Int64~machine.Word; }
↦ int-sign (i- b a);
let int-neq =
λ{ a: machine.Int64~machine.Word;
b: machine.Int64~machine.Word; }
↦ (bit-xor a b) as Bool;
let int-eq =
λ{ a: machine.Int64~machine.Word;
b: machine.Int64~machine.Word; }
↦ bool-neg (int-neq a b);
let int-lte =
λ{ a: machine.Int64~machine.Word;
b: machine.Int64~machine.Word; }
↦ bool-or (int-lt a b) (int-eq a b);
let int-gte =
λ{ a: machine.Int64~machine.Word;
b: machine.Int64~machine.Word; }
↦ bool-or (int-gt a b) (int-eq a b);
let int-min =
λ{ a: machine.Int64~machine.Word;
b: machine.Int64~machine.Word; }
↦ if (int-lt a b) { a; } else { b; };
let int-max =
λ{ a:machine.Int64~machine.Word;
b:machine.Int64~machine.Word; }
↦ if (int-gt a b) { a; } else { b; };
/*
type machine.UInt64 = <UnsignedBinaryInt 64> ~ machine.Word;
impl _2^64 for machine.UInt64 {
let + = machine.UInt64.add;
let - = machine.UInt64.sub;
let * = machine.UInt64.mul;
let / = machine.UInt64.div;
let % = machine.UInt64.rem;
};
type machine.Int64 = <TwosComplementInt 64> ~ machine.Word;
let machine.Int64.add =
λ{ a: machine.Int64;
b: machine.Int64; }
↦ ((u+ ((a des machine.Word) as machine.UInt64)
((b des machine.Word) as machine.UInt64))
des machine.Word) as machine.Int64;
type =~ <PosInt 2^64 BigEndian> ~ <Seq <Digit 2^64>~_2^64~machine.UInt64>;
impl < -2^63-1 +2^63> for <TwosComplementInt 64> {
let + = machine.Int64.add;
let - = machine.Int64.sub;
let * = machine.Int64.mul;
let / = machine.Int64.div;
let % = machine.Int64.rem;
};
*/
/*
let int-onescomplement-neg =
λ x : < -2^63 +2^63> ~ <OnesComplementInt 64> ~ machine.Word
↦ (bit-neg x) as < -2^63 +2^63> ~ <OnesComplementInt 64>;
let int-twoscomplement-neg =
λ x : < -2^63-1 +2^63> ~ <TwosComplementInt 64> ~ machine.Word
↦ (i+ 1 ((bit-neg x) as machine.Int64)) as < -2^63-1 +2^63>;
*/
};