Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

Commit 8e1ff20

Browse files
committed
translate binary floats as their equivalent Zig types
1 parent e1bb6da commit 8e1ff20

File tree

2 files changed

+52
-10
lines changed

2 files changed

+52
-10
lines changed

src/Translator.zig

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,21 +1141,17 @@ fn transType(t: *Translator, scope: *Scope, qt: QualType, source_loc: TokenIndex
11411141
},
11421142
.float => |float_ty| switch (float_ty) {
11431143
.fp16, .float16 => return ZigTag.type.create(t.arena, "f16"),
1144-
.float => return ZigTag.type.create(t.arena, "f32"),
1145-
.double => return ZigTag.type.create(t.arena, "f64"),
1146-
.long_double => return ZigTag.type.create(t.arena, "c_longdouble"),
1144+
.float, .float32 => return ZigTag.type.create(t.arena, "f32"),
1145+
.double, .float64, .float32x => return ZigTag.type.create(t.arena, "f64"),
1146+
.long_double, .float64x => return ZigTag.type.create(t.arena, "c_longdouble"),
11471147
.float128 => return ZigTag.type.create(t.arena, "f128"),
1148-
.bf16,
1149-
.float32,
1150-
.float64,
1151-
.float32x,
1152-
.float64x,
1153-
.float128x,
1148+
.bf16 => return t.fail(error.UnsupportedType, source_loc, "TODO support bfloat16", .{}),
11541149
.dfloat32,
11551150
.dfloat64,
11561151
.dfloat128,
11571152
.dfloat64x,
1158-
=> return t.fail(error.UnsupportedType, source_loc, "TODO support float type: '{s}'", .{try t.getTypeStr(qt)}),
1153+
=> return t.fail(error.UnsupportedType, source_loc, "TODO support decimal float type: '{s}'", .{try t.getTypeStr(qt)}),
1154+
.float128x => unreachable, // Unsupported on all targets
11591155
},
11601156
.pointer => |pointer_ty| {
11611157
const child_qt = pointer_ty.child;

test/cases/translate/float_types.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
_Float16 a;
2+
_Float32 b;
3+
_Float64 c;
4+
_Float128 d;
5+
6+
_Float32x e;
7+
_Float64x f;
8+
// _Float128x g; // unsupported on all targets
9+
10+
__fp16 h;
11+
__bf16 i;
12+
float j;
13+
double k;
14+
long double l;
15+
__float128 m;
16+
17+
_Decimal32 n;
18+
_Decimal64 o;
19+
_Decimal128 p;
20+
_Decimal64x q;
21+
22+
// translate
23+
// target=x86_64-linux
24+
//
25+
// pub export var a: f16 = 0;
26+
// pub export var b: f32 = 0;
27+
// pub export var c: f64 = 0;
28+
// pub export var d: f128 = 0;
29+
// pub export var e: f64 = 0;
30+
// pub export var f: c_longdouble = 0;
31+
// pub export var h: f16 = 0;
32+
//
33+
// pub const i = @compileError("unable to translate variable declaration type");
34+
//
35+
// pub export var j: f32 = 0;
36+
// pub export var k: f64 = 0;
37+
// pub export var l: c_longdouble = 0;
38+
// pub export var m: f128 = 0;
39+
//
40+
// pub const n = @compileError("unable to translate variable declaration type");
41+
//
42+
// pub const o = @compileError("unable to translate variable declaration type");
43+
//
44+
// pub const p = @compileError("unable to translate variable declaration type");
45+
//
46+
// pub const q = @compileError("unable to translate variable declaration type");

0 commit comments

Comments
 (0)