Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upType inference of floating point numbers through a comparison depends on the order of the operands #21634
Comments
kmcallister
added
the
A-typesystem
label
Jan 28, 2015
This comment has been minimized.
This comment has been minimized.
|
Other operators such as |
edwardw
added a commit
to edwardw/rust
that referenced
this issue
Jan 31, 2015
edwardw
referenced this issue
Jan 31, 2015
Merged
Make use of a binary operator's RHS type for LHS inference #21817
edwardw
added a commit
to edwardw/rust
that referenced
this issue
Jan 31, 2015
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Feb 2, 2015
bors
closed this
in
#21817
Feb 3, 2015
This comment has been minimized.
This comment has been minimized.
|
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())
^~~~~~~~~~~~ |
This comment has been minimized.
This comment has been minimized.
|
@Byron, thanks for reporting this. I'm a bit confused though. What is |
This comment has been minimized.
This comment has been minimized.
|
@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.0TI 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 |
shepmaster commentedJan 25, 2015
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 question