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

"integer part of floating point value out of bounds" panic during f16 -> i32 conversion on macOS #22247

Open
linusg opened this issue Dec 15, 2024 · 2 comments
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@linusg
Copy link
Contributor

linusg commented Dec 15, 2024

Zig Version

0.14.0-dev.2474+ee47094a3

Steps to Reproduce and Observed Behavior

const std = @import("std");

pub fn main() void {
    var f: f16 = 32785;
    _ = &f;
    const i: i32 = @intFromFloat(f);
    std.debug.print("{}\n", .{i});
}
$ zig run test.zig
thread 23687446 panic: integer part of floating point value out of bounds
/Users/linus/Dev/kiesel/test.zig:6:20: 0x1047e0f7b in main (a)
    const i: i32 = @intFromFloat(f);
                   ^
/Users/linus/zig/0.14.0-dev.2474+ee47094a3/files/lib/std/start.zig:647:22: 0x1047e0983 in main (a)
            root.main();
                     ^

Expected Behavior

Works fine on Linux:

$ zig run test.zig
32800

Also works fine up to 32784 which rounds to 32768 (see https://float.exposed/32784).

@linusg linusg added the bug Observed behavior contradicts documented or intended behavior label Dec 15, 2024
@alexrp
Copy link
Member

alexrp commented Dec 15, 2024

x86_64 or aarch64?

@linusg
Copy link
Contributor Author

linusg commented Dec 16, 2024

M4 Pro, macOS 15.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

2 participants