diff --git a/src/stage1/bigfloat.cpp b/src/stage1/bigfloat.cpp index a2a3a3b69cbbfbc91b80d85db97d1d7b256058c3..58b0aff54af01bc6dbc1ab8bac778c883aba2edc 100644 --- a/src/stage1/bigfloat.cpp +++ b/src/stage1/bigfloat.cpp @@ -46,6 +46,10 @@ void bigfloat_init_bigint(BigFloat *dest, const BigInt *op) { float128_t base; ui64_to_f128M(UINT64_MAX, &base); + float128_t one_f128; + ui32_to_f128M(1, &one_f128); + f128M_add(&base, &one_f128, &base); + const uint64_t *digits = bigint_ptr(op); for (size_t i = op->digit_count - 1;;) { diff --git a/test/stage1/behavior/cast.zig b/test/stage1/behavior/cast.zig index ce0d16d1a0a29c6797605e9d615d9c67c94ae311..0eb00512b94b76b898cb9028845b7befd502f346 100644 --- a/test/stage1/behavior/cast.zig +++ b/test/stage1/behavior/cast.zig @@ -375,6 +375,22 @@ test "comptime_int @intToFloat" { expect(@TypeOf(result) == f32); expect(result == 1234.0); } + { + const result = @intToFloat(f64, 1234); + expect(@TypeOf(result) == f64); + expect(result == 1234.0); + } + { + const result = @intToFloat(f128, 1234); + expect(@TypeOf(result) == f128); + expect(result == 1234.0); + } + // big comptime_int (> 64 bits) to f128 conversion + { + const result = @intToFloat(f128, 0x1_0000_0000_0000_0000); + expect(@TypeOf(result) == f128); + expect(result == 0x1_0000_0000_0000_0000.0); + } } test "@intCast i32 to u7" {