From 18de9a146bb69b901df2a56fb10600a231d143d1 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Sat, 11 Feb 2023 00:41:44 +0100 Subject: [PATCH] Fix copysign and make floatparse more strict. --- lib/std/core/floatparse.c3 | 4 ++++ lib/std/core/types.c3 | 2 +- lib/std/math/math.c3 | 4 ++-- src/version.h | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/std/core/floatparse.c3 b/lib/std/core/floatparse.c3 index da0bb3427..00f22e027 100644 --- a/lib/std/core/floatparse.c3 +++ b/lib/std/core/floatparse.c3 @@ -124,6 +124,10 @@ macro double! decfloat(char[] chars, int $bits, int $emin, int sign) if (catch e10) return NumberConversion.MALFORMED_FLOAT!; lrp += e10; } + else if (index != last_char) + { + return NumberConversion.MALFORMED_FLOAT!; + } // Handle zero specially to avoid nasty special cases later if (!x[0]) return sign * 0.0; diff --git a/lib/std/core/types.c3 b/lib/std/core/types.c3 index cb96c3fc7..0f866f9b9 100644 --- a/lib/std/core/types.c3 +++ b/lib/std/core/types.c3 @@ -158,7 +158,7 @@ macro bool is_vector($Type) return $Type.kindof == TypeKind.VECTOR; } -macro bool @convertable(#a, $TypeB) +macro bool @convertable(#a, $TypeB) @builtin { return $checks($TypeB x = #a); } diff --git a/lib/std/math/math.c3 b/lib/std/math/math.c3 index 1bda8f50b..88d708901 100644 --- a/lib/std/math/math.c3 +++ b/lib/std/math/math.c3 @@ -186,9 +186,9 @@ macro clamp(x, lower, upper) => $$max(($typeof(x))lower, $$min(x, ($typeof(x))up /** * @require values::@is_promotable_to_floatlike(mag) `The input must be a number value or float vector` - * @require values::@is_same_vector_type(mag, sgn) `The input types must match` + * @require @convertable(sgn, $typeof(values::promote_int(mag))) **/ -macro copysign(mag, sgn) => $$copysign(mag, sgn); +macro copysign(mag, sgn) => $$copysign(values::promote_int(mag), ($typeof(values::promote_int(mag)))sgn); /** * @require values::@is_promotable_to_floatlike(x) `The input must be a number value or float vector` diff --git a/src/version.h b/src/version.h index 4001db580..154d86221 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.4.56" \ No newline at end of file +#define COMPILER_VERSION "0.4.57" \ No newline at end of file