You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 = (120120120120120120120120asfloat)asint;
$ 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 = (120120120120120120asfloat)asint;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)
The text was updated successfully, but these errors were encountered:
We don't do conversion verification we do simple checking that a literal won't overflow.
With that in mind, I don't think this is something we'll fix, since it would require arbitrary precision numbers at compile time or the constant folder to be much more complex.
…1995
Fix all occurences `needless_borrow` internally
The bug that got 'needless_borrow' moved into the nursery was fixed two years ago in d4370f8.
This did trigger over a thousand times internally, so that's all the other changes. I vetted most of them, but there's a lot The only interesting change is to the lint list. `declare_tool_lint` already makes a reference, so there's no need to take a reference to the lints.
changelog: None
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.
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.
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)
The text was updated successfully, but these errors were encountered: