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

Errors printing float #669

Closed
ofelas opened this Issue Dec 31, 2017 · 2 comments

Comments

Projects
None yet
4 participants
@ofelas

ofelas commented Dec 31, 2017

Demonstrated with the following snippet. Tested with version 0.1.1.4e3d7fc.

const warn = @import("std").debug.warn;

// bin/zig version: 0.1.1.4e3d7fc
// build-exe: a float 3.14
// with --release-safe: a float index out of bounds
//                      Aborted
// with --release-fast: a float Segmentation fault

pub fn main() -> %void {
    var f: f64 = 3.14;
    // the following needs f64() or else error: parameter of type '(float literal)' requires comptime
    // warn("float {}\n", f64(3.14)); // <- uncomment this line and both always work!?!
    warn("a float {.3}\n", f); // same behaviour with and without .3
}

@andrewrk andrewrk added the bug label Dec 31, 2017

@andrewrk andrewrk added this to the 0.2.0 milestone Dec 31, 2017

@zesterer

This comment has been minimized.

zesterer commented Feb 6, 2018

This problem exists for integer literals as well:

printf("{}", 5);

yields

error: parameter of type '(integer literal)' requires comptime

@tiehuis

This comment has been minimized.

Member

tiehuis commented Feb 7, 2018

@zesterer

That isn't the issue presented here. Comptime literals are stored as arbitrary-precision values in the compiler (floats are stored as 128-bit right now). In order to print these, we would have to either bundle compile-time integer support into a runtime or serialize to a string at compile-time which are both fairly untenable as they require a lot of extra machinery/memory that is rather implicit. For this reason we just emit an error (which is a little unhelpful).

I've made a proposal to discuss 'solving' this here: #747.

@andrewrk andrewrk modified the milestones: 0.2.0, 0.3.0 Mar 12, 2018

tiehuis added a commit that referenced this issue Apr 23, 2018

Fix release float printing errors
Fixes #564.
Fixes #669.
Fixes #928.

@andrewrk andrewrk closed this in e5175d4 Apr 29, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment