Fix release float printing errors

Fixes #564.
Fixes #669.
Fixes #928.
This commit is contained in:
Marc Tiehuis 2018-04-23 17:18:05 +12:00
parent d8ba1bc120
commit e5175d432e
2 changed files with 202 additions and 201 deletions

View File

@ -259,6 +259,9 @@ fn gethi(in: f64) f64 {
/// Normalize the number by factoring in the error.
/// @hp: The float pair.
fn hpNormalize(hp: &HP) void {
// Required to avoid segfaults causing buffer overrun during errol3 digit output termination.
@setFloatMode(this, @import("builtin").FloatMode.Strict);
const val = hp.val;
hp.val += hp.off;

View File

@ -779,10 +779,6 @@ test "fmt.format" {
const result = try bufPrint(buf1[0..], "pointer: {}\n", &value);
assert(mem.startsWith(u8, result, "pointer: Struct@"));
}
// TODO get these tests passing in release modes
// https://github.com/zig-lang/zig/issues/564
if (builtin.mode == builtin.Mode.Debug) {
{
var buf1: [32]u8 = undefined;
const value: f32 = 1.34;
@ -802,11 +798,15 @@ test "fmt.format" {
assert(mem.eql(u8, result, "f64: -1.234e+11\n"));
}
{
// This fails on release due to a minor rounding difference.
// --release-fast outputs 9.999960000000001e-40 vs. the expected.
if (builtin.mode == builtin.Mode.Debug) {
var buf1: [32]u8 = undefined;
const value: f64 = 9.999960e-40;
const result = try bufPrint(buf1[0..], "f64: {e}\n", value);
assert(mem.eql(u8, result, "f64: 9.99996e-40\n"));
}
}
{
var buf1: [32]u8 = undefined;
const value: f64 = 1.409706e-42;
@ -974,7 +974,6 @@ test "fmt.format" {
const result = try bufPrint(buf1[0..], "f64: {.5}\n", value);
assert(mem.eql(u8, result, "f64: 0.01563\n"));
}
// std-windows-x86_64-Debug-bare test case fails
{
// errol3 rounds to ... 630 but libc rounds to ...632. Grisu3
@ -986,7 +985,6 @@ test "fmt.format" {
assert(mem.eql(u8, result, "f64: 18014400656965630.00000\n"));
}
}
}
pub fn trim(buf: []const u8) []const u8 {
var start: usize = 0;