expr round(0.5) returns no more 1
Closed / Fixed1275043fffffffffffffffffffffffffffffffffCreated 21 years agoUpdated 21 years ago
Descriptionplain2005-08-28 08:58:31
--- Environment --- WindowsME and Tcl 8.5a4 built with MingW --- Example of code --- With Tcl8.4 (and even 8.5a3) : expr round(0.5) --> 1 expr round(-0.5) --> -1 With the new 8.5a4 : expr round(0.5) --> 0 expr round(-0.5) --> 0 --- Discussion --- I have been told that now the new functionality is to round to even numbers. The reason for this bug report is that the tcllib's math::bigfloat package used to test the bigfloat round command against the builtin [expr round()]. It does no more, because I hand-coded the attempted result as 1 or -1. But I would like to know at least one example where the round function we are used to causes a bug. Then, I could want to implement the same behavior in my package.
dkf Ticket [1275043fff]: 1 change
[History diff]2005-08-28 18:52:31
dkf Ticket [1275043fff]: 1 change
[History diff]2005-08-28 18:52:45
dgp Ticket [1275043fff]: 1 change
[History diff]2005-08-28 21:32:19
kennykbplain2005-08-29 23:46:29
Logged In: YES user_id=99768 Thank you for this report. You are right that a gratuitous change of the semantics to "round to even" should be avoided (perhaps a "nearbyint" function should be supplied to give those semantics). In addition to your reported error, while designing the test cases for this problem, I discovered that expr round(0.49999999999999994) gave 1.0 in 8.4. This last is surely a bug (and applies to any number whose fractional part differed from 0.5 by 1/2 ulp). I added a test case for that problem as well, and backported the whole mess to 8.4 as well.
Log in (anonymous is fine) to add a comment.