authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-10-15 10:16:20+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-10-15 21:25:59+03:00
logab585c680b3222b01c1520ac33d1233ba1ba5036
tree672ef073ad223e860a998f72bc2a047d287b1ca9
parent7b150dd05ed3e647897e6f3b0beb08e10e73c92e

stage1: Off-by-one error in int to float conversion

The base is 2^64 and not 2^64-1. Closes #6683

2 files changed, 20 insertions(+), 0 deletions(-)

src/stage1/bigfloat.cpp+4
......@@ -46,6 +46,10 @@ void bigfloat_init_bigint(BigFloat *dest, const BigInt *op) {
4646
4747 float128_t base;
4848 ui64_to_f128M(UINT64_MAX, &base);
49 float128_t one_f128;
50 ui32_to_f128M(1, &one_f128);
51 f128M_add(&base, &one_f128, &base);
52
4953 const uint64_t *digits = bigint_ptr(op);
5054
5155 for (size_t i = op->digit_count - 1;;) {
test/stage1/behavior/cast.zig+16
......@@ -375,6 +375,22 @@ test "comptime_int @intToFloat" {
375375 expect(@TypeOf(result) == f32);
376376 expect(result == 1234.0);
377377 }
378 {
379 const result = @intToFloat(f64, 1234);
380 expect(@TypeOf(result) == f64);
381 expect(result == 1234.0);
382 }
383 {
384 const result = @intToFloat(f128, 1234);
385 expect(@TypeOf(result) == f128);
386 expect(result == 1234.0);
387 }
388 // big comptime_int (> 64 bits) to f128 conversion
389 {
390 const result = @intToFloat(f128, 0x1_0000_0000_0000_0000);
391 expect(@TypeOf(result) == f128);
392 expect(result == 0x1_0000_0000_0000_0000.0);
393 }
378394}
379395
380396test "@intCast i32 to u7" {