0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Cliche problem: 0.1 + 0.2 == 0.3?

Posted at

assert!(0.1 + 0.2 == 0.3) leads to a panic
while
assert!(0.1_f32 + 0.2_f32 == 0.3_f32) will proceed without any issues

So, an actual implementation shows
0.1 + 0.2 = 0.30000000000000004

Therefore, the following will NOT work
assert!(0.1_f64 + 0.2_f64 == 0.3_f64)

But this will
assert!(0.1_f64 + 0.2_f64 != 0.3_f64)

I think a good chunk of people have heard of this problem before, but it's always nice to have a brain teaser. Hope I spelled that right.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?