diff --git a/src/aro/Value.zig b/src/aro/Value.zig index 3203c64f..542d06f5 100644 --- a/src/aro/Value.zig +++ b/src/aro/Value.zig @@ -188,6 +188,19 @@ pub fn floatToInt(v: *Value, dest_ty: Type, comp: *Compilation) !FloatToIntChang /// `.none` value remains unchanged. pub fn intToFloat(v: *Value, dest_ty: Type, comp: *Compilation) !void { if (v.opt_ref == .none) return; + + if (dest_ty.isComplex()) { + const bits = dest_ty.bitSizeof(comp).?; + const cf: Interner.Key.Complex = switch (bits) { + 64 => .{ .cf32 = .{ v.toFloat(f32, comp), 0 } }, + 128 => .{ .cf64 = .{ v.toFloat(f64, comp), 0 } }, + 160 => .{ .cf80 = .{ v.toFloat(f80, comp), 0 } }, + 256 => .{ .cf128 = .{ v.toFloat(f128, comp), 0 } }, + else => unreachable, + }; + v.* = try intern(comp, .{ .complex = cf }); + return; + } const bits = dest_ty.bitSizeof(comp).?; return switch (comp.interner.get(v.ref()).int) { inline .u64, .i64 => |data| { diff --git a/test/cases/complex values.c b/test/cases/complex values.c index 21af733c..bb535fad 100644 --- a/test/cases/complex values.c +++ b/test/cases/complex values.c @@ -31,6 +31,8 @@ _Complex double a = (_Complex double) {1.0, 2.0,}; _Complex double b = (_Complex double) {1.0, 2.0,,,,,,}; _Complex double c = (_Complex double) {1.0, 2.0,3.0}; +_Static_assert(3 + 4.0il == 3 + 4.0il, ""); +_Static_assert(5ll + 4.0il == 5ll + 4.0il, ""); #define EXPECTED_ERRORS "complex values.c:31:49: error: expected expression" \ "complex values.c:32:49: warning: excess elements in scalar initializer [-Wexcess-initializers]" \