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

Add basic support for rational and complex numbers #5733

Closed
wants to merge 4 commits into from

Conversation

huonw
Copy link
Member

@huonw huonw commented Apr 5, 2013

This adds two generic data types, Ratio and Cmplx (and some aliases for useful instances, e.g. Ratio<int> and Cmplx<f64>), and basic arithmetic support, as well as .to_str (for both) and .from_str (for rational).

The complex number implementation doesn't solve #1284 other than getting something into the libraries, specifically it doesn't even try to address C interop. If the complex part of this gets merged, maybe it's worth closing that issue and reopening more specific issue(s) about the failings.

The implementations can be fleshed out when the numeric traits stabilise (and trait inheritance works).

@thestinger
Copy link
Contributor

Two more things that can be turned into issues and dealt with in the future:

  • Guarantee that the complex number type is compatible with the C representation #5737: It would be convenient to have the representation of complex numbers be compatible with C by making it packed, but I don't think that's currently possible. Luckily that can be changed later without even touching the interface at all.
  • Figure out a good convention for normalizing rational numbers #5738: There's also the question about how frequently the rational number should normalize - Mpq does it after each operation, and then exposes a raw interface for doing a few operations without normalizing. If it's always guaranteed to be normalized, #[deriving(Eq)] might as well be used. That would probably also mean making the fields priv and using scary names for raw manipulation methods.

bors added a commit that referenced this pull request Apr 6, 2013
This adds two generic data types, `Ratio` and `Cmplx` (and some aliases for useful instances, e.g. `Ratio<int>` and `Cmplx<f64>`), and basic arithmetic support, as well as `.to_str` (for both) and `.from_str` (for rational).

The complex number implementation doesn't solve #1284 other than getting something into the libraries, specifically it doesn't even try to address C interop. If the complex part of this gets merged, maybe it's worth closing that issue and reopening more specific issue(s) about the failings.

The implementations can be fleshed out when the numeric traits stabilise (and trait inheritance works).
@bors bors closed this Apr 6, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Mar 25, 2021
`match_wildcard` improvements

fixes: rust-lang#6604
fixes: rust-lang#5733
fixes: rust-lang#6862

rust-lang#5733 is only fixed in the normal case, if different paths are used for the variants then the same problem will occur. It's cause by `def_path_str` returning an utterly useless result. I haven't dug into why yet.

For rust-lang#6604 there should be some discussion before accepting this. It's easy enough to change the message rather than disable the lint for `Option` and `Result`.

changelog: Attempt to find a common path prefix for `match_wildcard_for_single_variants` and `wildcard_enum_match_arm`
changelog: Don't lint op `Option` and `Result` for `match_wildcard_for_single_variants` and `wildcard_enum_match_arm`
changelog: Consider `or` patterns and `Self` prefix for `match_wildcard_for_single_variants` and `wildcard_enum_match_arm`
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

Successfully merging this pull request may close these issues.

4 participants