[R] sprintf() question

Ei-ji Nakama nakama at ki.rim.or.jp
Mon May 18 08:40:55 CEST 2009


Hi

The result of Windows is clearly strange.

================ my Linux machine = good =======================
> sessionInfo()
R version 2.9.0 (2009-04-17)
x86_64-pc-linux-gnu

locale:
LC_CTYPE=ja_JP.EUC-JP;LC_NUMERIC=C;LC_TIME=ja_JP.EUC-JP;LC_COLLATE=ja_JP.EUC-JP;
LC_MONETARY=C;LC_MESSAGES=ja_JP.EUC-JP;LC_PAPER=ja_JP.EUC-JP;LC_NAME=C;LC_ADDRES
S=C;LC_TELEPHONE=C;LC_MEASUREMENT=ja_JP.EUC-JP;LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
> sprintf("%a",1:8)
[1] "0x1p+0"   "0x1p+1"   "0x1.8p+1" "0x1p+2"   "0x1.4p+2" "0x1.8p+2" "0x1.cp+2"
[8] "0x1p+3"

================ my Windows machine = OMG ======================
> sessionInfo()
R version 2.9.0 (2009-04-17)
i386-pc-mingw32

locale:
LC_COLLATE=Japanese_Japan.932;LC_CTYPE=Japanese_Japan.932;LC_MONETARY=Japanese_Japan.932;LC_NUMERIC=C;LC_TIME=Japanese_Japan.932

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
> sprintf("%a",1:8)
[1] "0x1p+0"            "0x1"               "0x1.8"
"0x1p+4294967294"
[5] "0x1.4p+4294967294" "0x1.8p+4294967294" "0x1.cp+4294967294"
"0x1p+4294967293"

The result improved when I changed handling of uExponent as follows

http://prs.ism.ac.jp/~nakama/working/sprintf_format_a.patch



2009/5/18 Daniel Nordlund <djnordlund at verizon.net>:
>> -----Original Message-----
>> From: Ted Harding [mailto:Ted.Harding at manchester.ac.uk]
>> Sent: Sunday, May 17, 2009 3:32 PM
>> To: Daniel Nordlund
>> Cc: r-help at r-project.org
>> Subject: RE: [R] sprintf() question
>>
>> On 17-May-09 22:03:19, Daniel Nordlund wrote:
>> > When I type the following, I get results different from what I
>> > expected.
>> >
>> >> sprintf('%a',3)
>> > [1] "0x1.8"
>> >
>> > Shouldn't the result be
>> >
>> > [1] "0x1.8p+2"
>>
>> Well, not "p+2" but "p+1"
>>   (0x1.8 = 1.1000[2] ; *2 = 11.000[2] = 3[10]) ;
>> however, I get:
>>
>>   sprintf('%a',3)
>>   # [1] "0x1.8p+1"
>>
>> which is indeed correct.
>>
>>   R version 2.9.0 (2009-04-17) ## Same as yours
>>   platform  i486-pc-linux-gnu  ## Different from yours ...
>>
>> which perhaps suggests that there may be a mis-compilation in the
>> Windows version.
>>
>> Ted.
>>
>> > I read through the help ?sprintf and didn't find anything
>> that changed
>> > my expectation.  What am I misunderstanding?  I am using
>> R-2.9.0 binary
>> > from CRAN on Windows XP Pro, and my session info is
>> >
>> >
>> >> sessionInfo()
>> > R version 2.9.0 (2009-04-17)
>> > i386-pc-mingw32
>> >
>> > locale:
>> > LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
>> > States.1252;LC_MONETARY=English_United
>> > States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
>> >
>> > attached base packages:
>> > [1] stats     graphics  grDevices utils     datasets
>> methods   base
>> >>
>> >
>> > Thanks for any enlightenment.
>> >
>
> Thanks Ted!
>
> Enlightenment is what I asked for, and it is what I got.  I was having a
> senior moment I guess.  I was picturing 8 as binary 0100, when obviously it
> is binary 1000.  So yes, the required power of 2 is 1, and it is fine with
> me that Windows implementation does not display it.  Thanks again.
>
> Dan
>
> Daniel Nordlund
> Bothell, WA  USA
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>

-- 
EI-JI Nakama  <nakama (a) ki.rim.or.jp>
"\u4e2d\u9593\u6804\u6cbb"  <nakama (a) ki.rim.or.jp>




More information about the R-help mailing list