[Rd] Inconsistent IEEE 754/IEC 60559 rounding behavior (PR#8452)

From: <Micah_Altman_at_harvard.edu>
Date: Thu 29 Dec 2005 - 21:10:30 GMT


Full_Name: Micah Altman
Version: 2.2
OS: Windows/Linux (RHELv3)
Submission from: (NULL) (71.243.63.53)

Documentation for round()/signif() indicates that IEC 60559 standard is used, "_go to the even digit_" is used for rounding off a 5. However, signif(), round() and sprintf() do not behave consistently -- rounding using round() follows this rule, signif() does not, and sprintf() follows the rule on Linux but not on Windows():

> version

         _
platform x86_64-redhat-linux-gnu

arch     x86_64                 
os       linux-gnu              
system   x86_64, linux-gnu      
status                          
major    2                      
minor    2.0                    
year     2005                   
month    10                     
day      06                     
svn rev  35749                  
language R                      

> sessionInfo()

R version 2.2.0, 2005-10-06, x86_64-redhat-linux-gnu

attached base packages:
[1] "methods" "stats" "graphics" "grDevices" "utils" "datasets" [7] "base"

> sprintf("%#.1g",as.double(0.25))

[1] "0.2"
> round(.25,digits=1)

[1] 0.2
> signif(.25,digits=1)

[1] 0.3

> version

         _
platform i386-pc-mingw32

arch     i386           
os       mingw32        
system   i386, mingw32  
status                  
major    2              
minor    2.0            
year     2005           
month    10             
day      06             
svn rev  35749          
language R              

> sessionInfo()

R version 2.2.0, 2005-10-06, i386-pc-mingw32

attached base packages:

[1] "methods"   "stats"     "graphics"  "grDevices" "utils"     "datasets" 
"base"     

> sprintf("%#.1g",as.double(0.25))

[1] "0.3"
> round(.25,digits=1)

[1] 0.2
> signif(.25,digits=1)

[1] 0.3
>


R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri Dec 30 08:15:35 2005

This archive was generated by hypermail 2.1.8 : Fri 30 Dec 2005 - 02:26:08 GMT