translate-c: cast unsuffixed floats to f64

This commit is contained in:
Veikka Tuominen 2022-11-20 16:10:54 +02:00
parent 476b946802
commit 44f8714dfb
2 changed files with 7 additions and 9 deletions

View File

@ -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,
});

View File

@ -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);",
});