authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-03 21:50:00-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-03 21:50:00-07:00
log3ed9ef3e6bed3fef6d6cad07920d08b28e20ec3e
tree2b203324fd0d8466271a7b467e45e9bd4f996423
parentb6930825b0e59bc355370eb68f5b74868d8aa1d7

Sema: fix bigIntToFloat

The implementation had the `@mulAdd` parameters mixed up.

3 files changed, 3 insertions(+), 16 deletions(-)

src/Sema.zig+2-2
...@@ -19730,8 +19730,8 @@ fn bitCast(...@@ -19730,8 +19730,8 @@ fn bitCast(
19730 try sema.resolveTypeLayout(block, inst_src, old_ty);19730 try sema.resolveTypeLayout(block, inst_src, old_ty);
1973119731
19732 const target = sema.mod.getTarget();19732 const target = sema.mod.getTarget();
19733 var dest_bits = dest_ty.bitSize(target);19733 const dest_bits = dest_ty.bitSize(target);
19734 var old_bits = old_ty.bitSize(target);19734 const old_bits = old_ty.bitSize(target);
1973519735
19736 if (old_bits != dest_bits) {19736 if (old_bits != dest_bits) {
19737 return sema.fail(block, inst_src, "@bitCast size mismatch: destination type '{}' has {d} bits but source type '{}' has {d} bits", .{19737 return sema.fail(block, inst_src, "@bitCast size mismatch: destination type '{}' has {d} bits but source type '{}' has {d} bits", .{
src/value.zig+1-1
...@@ -1476,7 +1476,7 @@ pub const Value = extern union {...@@ -1476,7 +1476,7 @@ pub const Value = extern union {
1476 while (i != 0) {1476 while (i != 0) {
1477 i -= 1;1477 i -= 1;
1478 const limb: f128 = @intToFloat(f128, limbs[i]);1478 const limb: f128 = @intToFloat(f128, limbs[i]);
1479 result = @mulAdd(f128, base, limb, result);1479 result = @mulAdd(f128, base, result, limb);
1480 }1480 }
1481 if (positive) {1481 if (positive) {
1482 return result;1482 return result;
test/behavior/floatop.zig-13
...@@ -667,24 +667,11 @@ fn fnWithFloatMode() f32 {...@@ -667,24 +667,11 @@ fn fnWithFloatMode() f32 {
667}667}
668668
669test "float literal at compile time not lossy" {669test "float literal at compile time not lossy" {
670 if (builtin.zig_backend != .stage1) {
671 // https://github.com/ziglang/zig/issues/11169
672 return error.SkipZigTest;
673 }
674
675 try expect(16777216.0 + 1.0 == 16777217.0);670 try expect(16777216.0 + 1.0 == 16777217.0);
676 try expect(9007199254740992.0 + 1.0 == 9007199254740993.0);671 try expect(9007199254740992.0 + 1.0 == 9007199254740993.0);
677}672}
678673
679test "f128 at compile time is lossy" {674test "f128 at compile time is lossy" {
680 if (builtin.zig_backend != .stage1) {
681 // this one is happening because we represent comptime-known f128 integers with
682 // Value.Tag.bigint and only convert to f128 representation if it stops being an
683 // integer. Is this something we want? need to have a lang spec discussion on this
684 // topic.
685 return error.SkipZigTest; // TODO
686 }
687
688 try expect(@as(f128, 10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0);675 try expect(@as(f128, 10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0);
689}676}
690677