Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unary minus support for float values #634

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/aro/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 = .{};
Expand Down
2 changes: 1 addition & 1 deletion src/aro/Value.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions test/cases/float values.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_Static_assert(-1.0 - 1.0 == -2.0, "");
_Static_assert(-2.0f == -2.0, "");
Loading