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

problem with floor function #59388

Closed
jblindsay opened this issue Mar 24, 2019 · 5 comments
Closed

problem with floor function #59388

jblindsay opened this issue Mar 24, 2019 · 5 comments
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jblindsay
Copy link

There appears to be an unexpected behaviour with the floor function for f64 (likely f32 as well). When applied to values greater than -1.0 and less than 0.0, it returns 0.0 instead of -1.0. That is, it is rounding up (ceil) rather than down in this one range of values.

assert_eq!(-0.8f64.floor(), -1f64);

@varkor
Copy link
Member

varkor commented Mar 24, 2019

Edit: I entirely misread. See below.

@estebank estebank added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) labels Mar 24, 2019
@ollie27
Copy link
Member

ollie27 commented Mar 24, 2019

-0.8f64.floor() is equivalent to -(0.8f64.floor()) not (-0.8f64).floor().

@oli-obk
Copy link
Contributor

oli-obk commented Mar 24, 2019

Maybe clippy could lint -foo.operation() expressions?

@varkor
Copy link
Member

varkor commented Mar 24, 2019

Whoops. I do think the precedence here is confusing. It's easy to think of the minus sign as being part of the literal. A clippy lint would be helpful.

@oli-obk
Copy link
Contributor

oli-obk commented Mar 24, 2019

Opened rust-lang/rust-clippy#3903

@oli-obk oli-obk closed this as completed Mar 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants