hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit faab727a2f72882a1c871b37faa7540052e1614b
parent da8260b9fe82b1cb2d5472370da512d21384a344
Author: Sebastian <sebastian@sebsite.pw>
Date:   Sat, 20 Apr 2024 22:17:59 -0400

math::checked: cast to int/uint

Arithmetic on int/uint is more efficient than i16/u16, and there's no
change in behavior from it here. i32/u32 are also changed to int/uint,
since they may be greater than 32 bits (but will always be at least 32
bits).

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mmath/checked/checked.ha | 8++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/math/checked/checked.ha b/math/checked/checked.ha @@ -274,7 +274,7 @@ export fn subu64(a: u64, b: u64) (u64, bool) = { // Multiplies 'a' and 'b' returning the result and whether overflow occurred. export fn muli8(a: i8, b: i8) (i8, bool) = { - const fullres = a: i16 * b: i16; + const fullres = a: int * b: int; const res = fullres: i8; const overflow = res != fullres; return (res, overflow); @@ -291,7 +291,7 @@ export fn muli8(a: i8, b: i8) (i8, bool) = { // Multiplies 'a' and 'b' returning the result and whether overflow occurred. export fn muli16(a: i16, b: i16) (i16, bool) = { - const fullres = a: i32 * b: i32; + const fullres = a: int * b: int; const res = fullres: i16; const overflow = res != fullres; return (res, overflow); @@ -342,7 +342,7 @@ export fn muli64(a: i64, b: i64) (i64, bool) = { // Multiplies 'a' and 'b' returning the result and whether overflow occurred. export fn mulu8(a: u8, b: u8) (u8, bool) = { - const fullres = a: u16 * b: u16; + const fullres = a: uint * b: uint; const res = fullres: u8; const overflow = res != fullres; return (res, overflow); @@ -359,7 +359,7 @@ export fn mulu8(a: u8, b: u8) (u8, bool) = { // Multiplies 'a' and 'b' returning the result and whether overflow occurred. export fn mulu16(a: u16, b: u16) (u16, bool) = { - const fullres = a: u32 * b: u32; + const fullres = a: uint * b: uint; const res = fullres: u16; const overflow = res != fullres; return (res, overflow);