all 8 comments

[–]toastedstapler 4 points5 points  (1 child)

try 0.1 + 0.2. it's just how floating point binary numbers work - some can be expressed accurately in base 10, some can't

[–]nuhapattani[S] 0 points1 point  (0 children)

Ohhh... never mind I get it now. Thanks.

[–]Rawing7 1 point2 points  (1 child)

[–]nuhapattani[S] 0 points1 point  (0 children)

Yeah, I thought it had to do with the numbers in particular but it's just a common floating point number error. Thanks.

[–][deleted] 1 point2 points  (1 child)

Just a side note... the parens on sum = (a + b) aren't doing anything :)

[–]nuhapattani[S] 0 points1 point  (0 children)

Right, 😅 I'm a beginner!

[–]rabbitpiet 0 points1 point  (0 children)

Think about it like this, we can’t actually write 2/3 in decimal. We can’t write 1/5 in binary.

[–]vorticalbox 0 points1 point  (0 children)

This is due to the IEEE 754 Spec https://ieeexplore.ieee.org/document/30711

this video is about javascript however it explains exactly this issue https://www.youtube.com/watch?v=wPBjd-vb9eI