zig icon indicating copy to clipboard operation
zig copied to clipboard

Misleading error message for `@floatToInt`

Open IntegratedQuantum opened this issue 3 years ago • 0 comments

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 avatar Sep 13 '22 09:09 IntegratedQuantum