bigint: Add prototypes for immediate add+sub.

This commit is contained in:
Jeroen van Rijn
2021-08-11 20:59:50 +02:00
parent d57e1be89f
commit c5cbd3260a
2 changed files with 40 additions and 14 deletions
+28 -2
View File
@@ -21,7 +21,7 @@ import "core:intrinsics"
/* /*
High-level addition. Handles sign. High-level addition. Handles sign.
*/ */
add :: proc(dest, a, b: ^Int) -> (err: Error) { add_two_ints :: proc(dest, a, b: ^Int) -> (err: Error) {
dest := dest; x := a; y := b; dest := dest; x := a; y := b;
_panic_if_uninitialized(a); _panic_if_uninitialized(b); _panic_if_uninitialized(dest); _panic_if_uninitialized(a); _panic_if_uninitialized(b); _panic_if_uninitialized(dest);
@@ -46,10 +46,23 @@ add :: proc(dest, a, b: ^Int) -> (err: Error) {
return _sub(dest, x, y); return _sub(dest, x, y);
} }
/*
Adds the unsigned `DIGIT` immediate to an `Int`,
such that the `DIGIT` doesn't have to be turned into an `Int` first.
dest = a + digit;
*/
add_digit :: proc(dest, a: ^int, digit: DIGIT) -> (err: Error) {
return .Unimplemented;
}
add :: proc{add_two_ints, add_digit};
/* /*
High-level subtraction, dest = number - decrease. Handles signs. High-level subtraction, dest = number - decrease. Handles signs.
*/ */
sub :: proc(dest, number, decrease: ^Int) -> (err: Error) { sub_two_ints :: proc(dest, number, decrease: ^Int) -> (err: Error) {
dest := dest; x := number; y := decrease; dest := dest; x := number; y := decrease;
_panic_if_uninitialized(number); _panic_if_uninitialized(decrease); _panic_if_uninitialized(dest); _panic_if_uninitialized(number); _panic_if_uninitialized(decrease); _panic_if_uninitialized(dest);
@@ -83,6 +96,19 @@ sub :: proc(dest, number, decrease: ^Int) -> (err: Error) {
return _sub(dest, x, y); return _sub(dest, x, y);
} }
/*
Adds the unsigned `DIGIT` immediate to an `Int`,
such that the `DIGIT` doesn't have to be turned into an `Int` first.
dest = number - decrease;
*/
sub_digit :: proc(dest, number: ^int, decrease: DIGIT) -> (err: Error) {
return .Unimplemented;
}
sub :: proc{sub_two_ints, sub_digit};
/* /*
========================== ==========================
Low-level routines Low-level routines