motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit 163a8e98bc04ea955ee54d5905436ffac34c93a2 (tree)
parent 1c73c08298fc3a19886038d935e45cf74ba152fb
Author: Marc Tiehuis <marctiehuis@gmail.com>
Date:   Mon, 20 May 2019 17:28:17 +1200

std.fmt.parse_float: Fix exponent calculation

This was incorrectly translated as a u64. binary_exponent is an
unadjusted value so can be negative. In becomes unconditionally positive
when adding the bias.

Diffstat:
Mstd/fmt/parse_float.zig | 5+++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/std/fmt/parse_float.zig b/std/fmt/parse_float.zig @@ -103,7 +103,7 @@ fn convertRepr(comptime T: type, n: FloatRepr) T { s.d1 = @truncate(u32, n.mantissa >> 32); s.d2 = 0; - var binary_exponent: u64 = 92; + var binary_exponent: i32 = 92; var exp = n.exponent; while (exp > 0) : (exp -= 1) { @@ -161,7 +161,7 @@ fn convertRepr(comptime T: type, n: FloatRepr) T { } else if (binary_exponent < 1) { break :blk if (n.negative) f64_minus_zero else f64_plus_zero; } else if (s.d2 != 0) { - const binexs2 = u64(binary_exponent) << 52; + const binexs2 = @intCast(u64, binary_exponent) << 52; const rr = (u64(s.d2 & ~mask28) << 24) | ((u64(s.d1) + 128) >> 8) | binexs2; break :blk if (n.negative) rr | (1 << 63) else rr; } else { @@ -415,6 +415,7 @@ test "fmt.parseFloat" { if (T != f16) { expect(approxEq(T, try parseFloat(T, "123142.1"), 123142.1, epsilon)); expect(approxEq(T, try parseFloat(T, "-123142.1124"), T(-123142.1124), epsilon)); + expect(approxEq(T, try parseFloat(T, "0.7062146892655368"), T(0.7062146892655368), epsilon)); } } }