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

Misleading error message for @floatToInt #12829

Open
IntegratedQuantum opened this issue Sep 13, 2022 · 0 comments
Open

Misleading error message for @floatToInt #12829

IntegratedQuantum opened this issue Sep 13, 2022 · 0 comments
Labels
error message This issue points out an error message that is unhelpful and should be improved.
Milestone

Comments

@IntegratedQuantum
Copy link
Contributor

Zig Version

0.10.0-dev.3880+e2bb92b2e

Steps to Reproduce

Call @floatToInt for a nan value, like this:

const std = @import("std");

pub fn main() void {
	var float: f32 = 0;
	float /= 0.0;
    std.log.err("{}", .{float});
    std.log.err("{}", .{@floatToInt(u32, float)});
}

Expected Behavior

The error message should either explicitely list the nan/infinity case:
panic: integer part of floating point value out of bounds or not finite
Or there should be seperate error message for nan values:
panic: cannot cast nan value to int

I'd personally prefer the second one, because it gives me more data that I can use for debugging, but the first one would also be fine.

Actual Behavior

panic: integer part of floating point value out of bounds

To me this error message implies that the float has an integer part and therefor is finite.

@IntegratedQuantum IntegratedQuantum added the bug Observed behavior contradicts documented or intended behavior label Sep 13, 2022
@Vexu Vexu added error message This issue points out an error message that is unhelpful and should be improved. and removed bug Observed behavior contradicts documented or intended behavior labels Sep 13, 2022
@Vexu Vexu added this to the 0.11.0 milestone Sep 13, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Apr 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error message This issue points out an error message that is unhelpful and should be improved.
Projects
None yet
Development

No branches or pull requests

3 participants