Closed
Description
This code works well, despite doing a conversion of an integer constant to a float and then back to an integer the fact that the integer is too large triggers an error.
let bar: int = (120120120120120120120120 as float) as int;
$ rustc prims.rs
prims.rs:10:19: 10:20 error: int literal is too large
prims.rs:10 let bar: int = (120120120120120120120120 as float) as int;
Now in this example the number is shorter, and it does not produce an error. But the printed value isn't the same as the original number.
let bar: int = (120120120120120120 as float) as int;
println(fmt!("%?", bar));
120120120120120128
It looks like the first int -> float conversion resulted in some kind of information loss due to floating point precision/representation issues, and this loss was propogated when the value was converted back to an int.
It seems like there already is constant conversion verification, so it likely could be extended to deal with floating point issues like this.
(tested using the rust trunk)
Metadata
Metadata
Assignees
Labels
No labels