From 42bdd90226c38450ef29a086d89df5718f7a32da Mon Sep 17 00:00:00 2001 From: Evan Haas Date: Mon, 26 Feb 2024 14:58:15 -0800 Subject: [PATCH 1/2] Parser: make unary minus work with float values --- src/aro/Parser.zig | 2 +- test/cases/float values.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 test/cases/float values.c diff --git a/src/aro/Parser.zig b/src/aro/Parser.zig index 39f15b8a..7276d177 100644 --- a/src/aro/Parser.zig +++ b/src/aro/Parser.zig @@ -6934,7 +6934,7 @@ fn unExpr(p: *Parser) Error!Result { try p.errStr(.invalid_argument_un, tok, try p.typeStr(operand.ty)); try operand.usualUnaryConversion(p, tok); - if (operand.val.is(.int, p.comp)) { + if (operand.val.is(.int, p.comp) or operand.val.is(.float, p.comp)) { _ = try operand.val.sub(Value.zero, operand.val, operand.ty, p.comp); } else { operand.val = .{}; diff --git a/test/cases/float values.c b/test/cases/float values.c new file mode 100644 index 00000000..3d16702c --- /dev/null +++ b/test/cases/float values.c @@ -0,0 +1,2 @@ +_Static_assert(-1.0 - 1.0 == -2.0, ""); +_Static_assert(-2.0f == -2.0, ""); From 4319e95e5bdac1d2cb7ef5ac3de9c991a27b51b7 Mon Sep 17 00:00:00 2001 From: Evan Haas Date: Mon, 26 Feb 2024 15:01:51 -0800 Subject: [PATCH 2/2] Value: fix doc comment for floatCast --- src/aro/Value.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aro/Value.zig b/src/aro/Value.zig index 2c31d216..05eb9f4c 100644 --- a/src/aro/Value.zig +++ b/src/aro/Value.zig @@ -226,7 +226,7 @@ pub fn intCast(v: *Value, dest_ty: Type, comp: *Compilation) !void { v.* = try intern(comp, .{ .int = .{ .big_int = result_bigint.toConst() } }); } -/// Converts the stored value from an integer to a float. +/// Converts the stored value to a float of the specified type /// `.none` value remains unchanged. pub fn floatCast(v: *Value, dest_ty: Type, comp: *Compilation) !void { if (v.opt_ref == .none) return;