-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Type inference of floating point numbers through a comparison depends on the order of the operands #21634
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
Comments
Other operators such as |
For "symmetric" binary operators, meaning the types of two side must be equal, if the type of LHS doesn't know yet but RHS does, use that as an hint to infer LHS' type. Closes rust-lang#21634
For "symmetric" binary operators, meaning the types of two sides must be equal, if the type of LHS doesn't know yet but RHS does, use that as an hint to infer LHS' type. Closes rust-lang#21634
Please note that this issue was referenced from a question on stackoverflow, implying that it would be resolved with the fix discussed here. Today I tried it with the latest version I could pull, Maybe both are unrelated after all, yet I felt the need to file some sort of report in case it should be fixed. How to reproduce my particular issueIf you replace src/rust/vec.rs:89:21: 89:33 error: the type of this value must be known in this context
src/rust/vec.rs:89 self.mulfed(Float::one() / self.len())
^~~~~~~~~~~~ |
@Byron, thanks for reporting this. I'm a bit confused though. What is |
@edwardw Sorry for the late reply. let x: T = 5.0; // where T: Float, error: mismatched types:
expected `T`,
found `_`
(expected type parameter,
found floating-point variable) [E0308] ... which forces you to use facilities of the let one: T = Float::one();
let x = one + one + one + one + one; // now x is 5.0T I am just trying to share my experiences so far, maybe the 'issues' I run into are perfectly intended, even though they seem unnecessary to me. For the issue above, my workaround is to not use a type parameter constrained to let x: MyFloat = 5.0; // type MyFloat = f32;
// Now I can easily set MyFloat to be f64 for example, which is what I originally intended with T: Float |
This fails:
with the error:
Simply flipping the order of the comparison operands allows it to compile:
Tested with
rustc 1.0.0-dev (102ab57d8 2015-01-25 13:33:18 +0000)
Originally from this Stack Overflow questionThe text was updated successfully, but these errors were encountered: