authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-20 16:10:54+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-09 14:34:05-07:00
logda418ee0afa3a3314e408cc6973917f5cc5a53bf
treecf6e2854b44c85b69c501e1a53e107ecaf736227
parent58ac0082d291fbce4125e86e1d61c9b6e8c3ce4a

translate-c: cast unsuffixed floats to f64


2 files changed, 7 insertions(+), 9 deletions(-)

src/translate_c.zig+1-3
......@@ -5783,11 +5783,9 @@ fn parseCNumLit(c: *Context, m: *MacroCtx) ParseError!Node {
57835783 }
57845784 }
57855785
5786 if (suffix == .none)
5787 return transCreateNodeNumber(c, lit_bytes, .float);
5788
57895786 const type_node = try Tag.type.create(c.arena, switch (suffix) {
57905787 .f => "f32",
5788 .none => "f64",
57915789 .l => "c_longdouble",
57925790 else => unreachable,
57935791 });
test/translate_c.zig+6-6
......@@ -1216,9 +1216,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
12161216 , &[_][]const u8{
12171217 "pub const foo = @as(f32, 3.14);",
12181218 "pub const bar = @as(c_longdouble, 16.0e-2);",
1219 "pub const FOO = 0.12345;",
1220 "pub const BAR = 0.12345;",
1221 "pub const baz = 1e1;",
1219 "pub const FOO = @as(f64, 0.12345);",
1220 "pub const BAR = @as(f64, 0.12345);",
1221 "pub const baz = @as(f64, 1e1);",
12221222 "pub const BAZ = @as(f32, 42e-3);",
12231223 "pub const foobar = -@as(c_longdouble, 73.0);",
12241224 });
......@@ -1230,10 +1230,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
12301230 \\#define BAZ -0x.0a5dp+12
12311231 \\#define FOOBAZ 0xfE.P-1l
12321232 , &[_][]const u8{
1233 "pub const FOO = 0xf7p38;",
1233 "pub const FOO = @as(f64, 0xf7p38);",
12341234 "pub const BAR = -@as(f32, 0x8F.BP5);",
1235 "pub const FOOBAR = 0x0P+0;",
1236 "pub const BAZ = -0x0.0a5dp+12;",
1235 "pub const FOOBAR = @as(f64, 0x0P+0);",
1236 "pub const BAZ = -@as(f64, 0x0.0a5dp+12);",
12371237 "pub const FOOBAZ = @as(c_longdouble, 0xfE.0P-1);",
12381238 });
12391239