diff --git a/lib/std/math/math.c3 b/lib/std/math/math.c3 index 7b16d71ea..aba6d64c8 100644 --- a/lib/std/math/math.c3 +++ b/lib/std/math/math.c3 @@ -1113,6 +1113,33 @@ macro overflow_mul_helper(x, y) @local return res; } +<* + @param [&out] out : "Where the result of the addition is stored" + @return "Whether the addition resulted in an integer overflow" + @require values::@is_same_type(a, b) : "a and b must be the same type" + @require values::@is_int(a) &&& values::@is_int(b) : "a and b must both be integers" + @require $defined(*out) &&& values::@is_same_type(*out, a) : "out must be a pointer of the same type as a and b" +*> +macro bool overflow_add(a, b, out) => $$overflow_add(a, b, out); + +<* + @param [&out] out : "Where the result of the subtraction is stored" + @return "Whether the subtraction resulted in an integer overflow" + @require values::@is_same_type(a, b) : "a and b must be the same type" + @require values::@is_int(a) &&& values::@is_int(b) : "a and b must both be integers" + @require $defined(*out) &&& values::@is_same_type(*out, a) : "out must be a pointer of the same type as a and b" +*> +macro bool overflow_sub(a, b, out) => $$overflow_sub(a, b, out); + +<* + @param [&out] out : "Where the result of the multiplication is stored" + @return "Whether the multiplication resulted in an integer overflow" + @require values::@is_same_type(a, b) : "a and b must be the same type" + @require values::@is_int(a) &&& values::@is_int(b) : "a and b must both be integers" + @require $defined(*out) &&& values::@is_same_type(*out, a) : "out must be a pointer of the same type as a and b" +*> +macro bool overflow_mul(a, b, out) => $$overflow_mul(a, b, out); + <* @require types::is_vector($Type) || ($Type.kindof == ARRAY &&& types::is_numerical($typefrom($Type.inner))) *>