commit da418ee0afa3a3314e408cc6973917f5cc5a53bf (tree)
parent 58ac0082d291fbce4125e86e1d61c9b6e8c3ce4a
Author: Veikka Tuominen <git@vexu.eu>
Date: Sun, 20 Nov 2022 16:10:54 +0200
translate-c: cast unsuffixed floats to f64
Diffstat:
2 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/src/translate_c.zig b/src/translate_c.zig
@@ -5783,11 +5783,9 @@ fn parseCNumLit(c: *Context, m: *MacroCtx) ParseError!Node {
}
}
- if (suffix == .none)
- return transCreateNodeNumber(c, lit_bytes, .float);
-
const type_node = try Tag.type.create(c.arena, switch (suffix) {
.f => "f32",
+ .none => "f64",
.l => "c_longdouble",
else => unreachable,
});
diff --git a/test/translate_c.zig b/test/translate_c.zig
@@ -1216,9 +1216,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
, &[_][]const u8{
"pub const foo = @as(f32, 3.14);",
"pub const bar = @as(c_longdouble, 16.0e-2);",
- "pub const FOO = 0.12345;",
- "pub const BAR = 0.12345;",
- "pub const baz = 1e1;",
+ "pub const FOO = @as(f64, 0.12345);",
+ "pub const BAR = @as(f64, 0.12345);",
+ "pub const baz = @as(f64, 1e1);",
"pub const BAZ = @as(f32, 42e-3);",
"pub const foobar = -@as(c_longdouble, 73.0);",
});
@@ -1230,10 +1230,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\#define BAZ -0x.0a5dp+12
\\#define FOOBAZ 0xfE.P-1l
, &[_][]const u8{
- "pub const FOO = 0xf7p38;",
+ "pub const FOO = @as(f64, 0xf7p38);",
"pub const BAR = -@as(f32, 0x8F.BP5);",
- "pub const FOOBAR = 0x0P+0;",
- "pub const BAZ = -0x0.0a5dp+12;",
+ "pub const FOOBAR = @as(f64, 0x0P+0);",
+ "pub const BAZ = -@as(f64, 0x0.0a5dp+12);",
"pub const FOOBAZ = @as(c_longdouble, 0xfE.0P-1);",
});