rust tends to implicitly upgrade variables from f32 to f64 when I do something as simple as let x:f32 = 1.0 x *= 2.; x now becomes f64 of course I could avoid it by x *= 2 as f32;
However, is there any smarter way to do it?
rust tends to implicitly upgrade variables from f32 to f64 when I do something as simple as let x:f32 = 1.0 x *= 2.; x now becomes f64 of course I could avoid it by x *= 2 as f32;
However, is there any smarter way to do it?
This is not the case. Perhaps there's something else happening that's confusing you? Could you share the code reproduces this?
the problem is on arrayfire array.
Pls ignore it.
Sorry anyway
There is no such thing in Rust. Rust is always strict about f32 vs f64 difference.
If you want to easily change the type at compile time, the closest you can do is to use a type alias:
type MyFloat = f32;
fn main() {
let x = 1.0 as MyFloat;
}
but that affects only places where you use the type alias. There's no way to change other code automatically.
The problem here is that when Array fire arrays are added, they will be promoted to the largest size between them. (see impl of Add
[1]). To avoid this, you will have to type all your literals as f32.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.