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

floatToInt broken for const negative values of f128 #10592

Closed
Laremere opened this issue Jan 13, 2022 · 0 comments · Fixed by #10593
Closed

floatToInt broken for const negative values of f128 #10592

Laremere opened this issue Jan 13, 2022 · 0 comments · Fixed by #10593
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@Laremere
Copy link

Laremere commented Jan 13, 2022

Zig Version

0.9.0

Steps to Reproduce

test "floatToInt" {
    const a: f128 = -2;
    var b = @floatToInt(i64, a);
    try expectEqual(@as(i64, -2), b);
}

Expected Behavior

The test to pass, as the f64 version does:

test "floatToInt" {
    const a: f64 = -2;
    var b = @floatToInt(i64, a);
    try expectEqual(@as(i64, -2), b);
}

or if the f128 isn't constant:

test "floatToInt" {
    var a: f128 = -2;
    var b = @floatToInt(i64, a);
    try expectEqual(@as(i64, -2), b);
}

Actual Behavior

error: integer value '-18446744073709551615' cannot be stored in type 'i64'
    const b = @floatToInt(i64, a);
@Laremere Laremere added the bug Observed behavior contradicts documented or intended behavior label Jan 13, 2022
@Laremere Laremere changed the title floatToInt broken for negative values of f128 floatToInt broken for const negative values of f128 Jan 13, 2022
tiehuis added a commit to tiehuis/zig that referenced this issue Jan 14, 2022
scorphus pushed a commit to scorphus/zig that referenced this issue Jan 15, 2022
@andrewrk andrewrk added this to the 0.9.1 milestone Feb 3, 2022
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

Successfully merging a pull request may close this issue.

2 participants