Hands-on Rust: usage of std::f32::MAX for 'unreachable'

Title: Hands-On Rust (Chapter 11)

When I reached the code *dist < &​std​::​f32​::MAX, I had to stop a second to remember what that was about.

I changed my code to add

const UNREACHABLE: i32 = std::i32::MAX;

and could then change the expression to *dist != &UNREACHABLE. (I know you don’t generally use == or != with floats, but I think it works here (guess I’ll find out)

Using a constant there is a good idea (although I think you meant f32::MAX. I’ll see about including that in the next beta - thank you!

I did, and had to fix it… .didn’t realize I posted it before I corrected it.

1 Like