Skip to content

Question about corner cases for to_int_unchecked #187

Answered by zhassan-aws
Yenyun035 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @Yenyun035. Great question. The tricky thing about floating-point numbers is that not every decimal value has a floating-point representation. So when a value is assigned to a float, the actual value that gets stored might be different. One way to check if a value can be represented as a floating-point number is this calculator: https://www.h-schmidt.net/FloatConverter/IEEE754.html.

For your example, the value 2147483646.4 cannot be represented, and the actual value that gets stored is 2147483648. This is greater than i32::MAX, so Kani should flag the failure.

Another way to check if the value can be represented is to print it, e.g. using this program: https://play.rust-lang.org/?versi…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Yenyun035
Comment options

@zhassan-aws
Comment options

Answer selected by Yenyun035
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants