mirror of
https://github.com/ziglang/zig.git
synced 2026-02-20 16:24:51 +00:00
stage1: Off-by-one error in int to float conversion
The base is 2^64 and not 2^64-1. Closes #6683
This commit is contained in:
parent
7b150dd05e
commit
ab585c680b
@ -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;;) {
|
||||
|
||||
@ -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" {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user