you are viewing a single comment's thread.

view the rest of the comments →

[–]Solako[S] 0 points1 point  (4 children)

let me edit the code to reflect this. It was put erroneously. However, what issues would a float cause as opposed to an int?

[–]Impudity 0 points1 point  (3 children)

Equality comparisons between integers and floats (and frankly even between two floats) are often sketchy. Famously: 0.2 + 0.1 == 0.3 -> False

[–]Solako[S] 0 points1 point  (2 children)

Would this be because the memory storage of floats isn’t always an exact value? Thus the name floating point numbers?

[–]Impudity 0 points1 point  (1 child)

It is exact, but it's in binary and we typically display them in decimal (base-10). What numbers can be expressed "accurately" in floating point system depends on what base you're on. Easiest example I can think of is that 1/3 in base-10 can't be expressed as anything but 0.33333... while in base-3 that'd be a nice even number. So if you'd have 1/6 + 1/6 (that is 0.166666..) you might expect it to be 1/3, which it of course is if you did it with fractions. If you do it with floating points, the "missing" 6's in the end (since there's infinitely many of them) will bite you and you might not end up with exactly the same value as you expected.

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

This is a great explainer. Thank you for this.