Puzzle 6Please Reboot the Universe
 fn​ ​main​() {
 if​ 0.1 + 0.2 == 0.3 {
  println!(​"Arithmetic still works."​);
  } ​else​ {
  println!(​"Please reboot the universe."​);
  }
 }

Guess the Output

images/aside-icons/important.png

Try to guess what the output is before moving to the next page.

images/hline.png

The program will display the following output:

 Please reboot the universe.
images/hline.png

Discussion

You would expect 0.1 + 0.2 to equal 0.3—it does, but not in floating-point ...

Get Rust Brain Teasers now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.