Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format decimal 0.0 with no precision as just 0 #4520

Merged
merged 1 commit into from
Feb 23, 2020

Conversation

frmdstryr
Copy link
Contributor

Currently it prints 00 when no precision is given, This makes it just 0. See https://godbolt.org/z/4jDgNv

const std = @import("std");
pub fn main() void {
    const zero: f32 = 0.0;
    const one: f32 = 1.0;
    std.debug.warn("One is: {d}\n", .{one});
    std.debug.warn("Zero is: {d}\n", .{zero}); // Should be a single 0
}

Outputs

One is: 1
Zero is: 00

@daurnimator daurnimator added the standard library This issue involves writing Zig code for the standard library. label Feb 22, 2020
@adontz
Copy link

adontz commented Feb 22, 2020

@andrewrk Did you consider "David M. Gay, Correctly Rounded Binary-Decimaland Decimal-Binary Conversions"?
paper: https://ampl.com/REFS/rounding.pdf
implementation: http://www.netlib.org/fp/ dtoa

@frmdstryr frmdstryr changed the title Format decmial 0.0 with no precision as just 0 Format decimal 0.0 with no precision as just 0 Feb 23, 2020
@LemonBoy
Copy link
Contributor

Did you consider "David M. Gay, Correctly Rounded Binary-Decimaland Decimal-Binary Conversions"?

The dtoa routine uses the Errol3 algorithm that's an improvement over the original one devised by Gay. The state of the art at the moment is the Ryū algorithm and it's supposed to be adopted by the stdlib (#1299) sometimes soon.

@andrewrk andrewrk merged commit 5976482 into ziglang:master Feb 23, 2020
@frmdstryr frmdstryr deleted the format-decimal-zero branch February 23, 2020 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants