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

Comparison of num::rational::Ratio is incorrect with overflow #8466

Closed
huonw opened this issue Aug 12, 2013 · 5 comments
Closed

Comparison of num::rational::Ratio is incorrect with overflow #8466

huonw opened this issue Aug 12, 2013 · 5 comments

Comments

@huonw
Copy link
Member

huonw commented Aug 12, 2013

extern crate num;
use num::rational::Ratio;

fn main() {
    let big = Ratio::new(128u8, 1);
    let small = big.recip();
    assert!(big > small);
}

fails the assertion. (It's comparing 128 with 1/128.)

This, or something similar, happens for any type that can overflow (I guess one could argue that fixed size types are "unsupported" for rational numbers, and so this overflow leads to unspecified behaviour).

@huonw
Copy link
Member Author

huonw commented Aug 13, 2013

It appears Haskell's Data.Ratio has the same behaviour wrt overflow/wrap-around.

@lilyball
Copy link
Contributor

Assuming this can't be fixed in any sane way, one option is to trigger task failure on overflow during comparison (e.g. by using .checked_mul() and failing if it returns None, although this would add the CheckedMul bounds).

@huonw
Copy link
Member Author

huonw commented Mar 2, 2014

No change. (Updated the code example)

@rust-highfive
Copy link
Collaborator

This issue has been moved to the RFCs repo: rust-lang/rfcs#333

@nrc nrc reopened this Sep 28, 2014
@rust-highfive
Copy link
Collaborator

This issue has been moved to the RFCs repo: rust-num/num#7

flip1995 pushed a commit to flip1995/rust that referenced this issue Feb 24, 2022
…nishearth

False positive redundant_closure when using ref pattern in closure params

fixes rust-lang#8460
Fixed [redundant_closure] so that closures of which params bound as `ref` or `ref mut ` doesn't trigger the lint.
(e.g. `|ref x| some_expr` doesn't trigger the lint.)
changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants