Bug 14491 - strange rounding with the "digits" option
strange rounding with the "digits" option
Status: RESOLVED FIXED
Product: R
Classification: Unclassified
Component: Accuracy
old
All All
: P5 minor
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-01-30 23:40 UTC by ansa.ansa
Modified: 2011-03-05 17:40 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ansa.ansa 2011-01-30 23:40:00 UTC
> options(digits=2)
> 6.93        - as I expect
[1] 6.9
> 7.93        - surprising
[1] 8



Why is 7.93 not printed as 7.9? It seems that the digit before the decimal place influences the rounding: for digits up to 6, the rounding is as I expect; for digits over 7, it rounds up, which surprises me. Another surprising case:

> 7.92
[1] 7.9        - as I expect
> 7.921
[1] 8          - surprising
Comment 1 Martin Maechler 2011-02-11 17:48:57 UTC
There's been a an R-devel conversation about this,
a thread, starting at
https://stat.ethz.ch/pipermail/r-devel/2011-February/059815.html

The bug is in  scientific()  in  src/main/format.c
and Petr is repeating part of my analysis and gives some further details.

IMO, it *is* a bug and should be fixed, even though it will mean changing R outputs in a few somewhat rare cases.

Martin Maechler
Comment 2 Martin Maechler 2011-03-05 17:40:55 UTC
(In reply to comment #1)
> There's been a an R-devel conversation about this,
> a thread, starting at
> https://stat.ethz.ch/pipermail/r-devel/2011-February/059815.html
> 
> The bug is in  scientific()  in  src/main/format.c
> and Petr is repeating part of my analysis and gives some further details.
> 
> IMO, it *is* a bug and should be fixed, even though it will mean changing R
> outputs in a few somewhat rare cases.
> 
> Martin Maechler

Petr Savicky and I have investigated and tested things, offline,
and thanks to his contributions, I've now committed a fix ...
which also addresses a long-standing misfeature for the case  
digits >= 16   (which  ?print.default  *did* warn about).

Hence this should be fixed in "R-devel" i.e. pre-2.13.0
from svn revision  54672
on.

Martin Maechelr