by Retr0id · 2y ago · 0 comments
This is just me being idiosyncratic I guess, but if I see a number with a decimal place, I default to interpreting it as an fp64 unless otherwise specified - which yields a "correct" answer of 2.0 (which is not an answer I can get to in my head, admittedly)
If the question-asker wanted integer arithmetic, they'd have left off the ".0", and if they wanted something other than fp64 roundTiesToEven they should've been more explicit :P
The answers are all equally "correct" given a particular set of operating rules, the interesting part is what rules they picked.
Edit: See also, https://en.wikipedia.org/wiki/Definitions_of_mathematics - "Mathematics has no generally accepted definition"
So they aren't on the same level, IEEE-754 is not an alternative standard to math. The answers can all be considered correct by a certain definition, but they are not equally correct in our shared context as human beings who know what math is.
59 + 1 can very reasonably be 1:00, for example.
I'm not saying 2.0 is the correct answer, I'm just saying it's not any less correct than 1 is.
(That said, I would never enter an integer with a decimal, and I would think of precision if it was a float. That said that said, there are other ways to bump into that problem which wouldn't make it so obvious - such as dealing with inputs from a user.)
In particular, 9999999999999999.0 rounds up to 10000000000000000.0
(note, this behavior depends on the rounding mode, https://en.wikipedia.org/wiki/IEEE_754#Rounding_rules )