Skip to content

Commit da418ee

Browse files
Vexuandrewrk
authored andcommitted
translate-c: cast unsuffixed floats to f64
1 parent 58ac008 commit da418ee

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/translate_c.zig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)