Closed barreeeiroo closed 4 years ago
Technically, this is not a bug. This is a rounding method often referred to as statistician's or banker's rounding, where a tie is rounded to the nearest even number, and it is the method of rounding specified in R6RS. This method is also used for IEEE 754 floating point mathematics when required to round the result of a computation. See here for more information on the different possible rounding approaches.
That being said, I expect that many people will run into this issue where they would normally expect .5 to always round up to the next largest integer. We may want to consider the following improvement:
yail-round-normal
that calls through to Math.round
, which uses the round up on ties approach (2.5
becomes 3
)round scientific
option for the unary math blocks that generates yail-round
callsround
generate calls to yail-round-normal
instead of yail-round
round
to round scientific
to keep the semantics for existing projects.I think I've got something for this mostly working, so I'd like to lay claim :D
Please keep this simple. App Inventor's target users are kids. Introducing blocks or properties that control rounding options seems like a very advanced idea. I'd advocate following R6RS and IEE 754.
@BeksOmega We may just want to update the documentation for the block, both in the Markdown and in the tooltip, to explain the type of rounding that's done rather than overwhelm people with different options.
Sounds good to me! o7
@ewpatton Just checked, the docs are already up-to-date. And the tooltip currently reads "Round a number up or down." which I think is ok when compared to the tooltips for ceil and floor: "Rounds the input to the smallest number not less then the input" and "Rounds the input to the largest number not greater then the input" respectively.
Given that, would you still like me to update the tooltip?
@BeksOmega Yes, we should amend the tooltip to include a note about rounding numbers ending in .5 to the nearest even integer.
As seen here: https://community.makeroid.io/t/the-round-operation-bug/9144/8?u=barreeeiroo
If you input
2.5
to the round block in Math category, it outputs2
, while the correct output should be3