Zig Version
0.14.0-dev.3047+3a4bb47fe
Steps to Reproduce and Observed Behavior
Run the following:
const std = @import("std");
pub fn main() void {
const a: f64 = 0.1;
const b: f64 = 0.2;
std.debug.print("{d:.52}\n", .{a + b});
}
The result is 0.3000000000000000400000000000000000000000000000000000 which doesn't make any sense. It looks like Zig has clipped everything past the first 4.
Expected Behavior
The correct result is 0.3000000000000000444089209850062616169452667236328125, which is the exact value of the float with bit pattern 0x3fd3333333333334. This result can be confirmed in other programming languages, such as JavaScript and Python.
print("{:.52f}".format(0.1 + 0.2))
Zig Version
0.14.0-dev.3047+3a4bb47fe
Steps to Reproduce and Observed Behavior
Run the following:
The result is
0.3000000000000000400000000000000000000000000000000000which doesn't make any sense. It looks like Zig has clipped everything past the first 4.Expected Behavior
The correct result is
0.3000000000000000444089209850062616169452667236328125, which is the exact value of the float with bit pattern0x3fd3333333333334. This result can be confirmed in other programming languages, such as JavaScript and Python.