Skip to content

printing of complex numbers in R-alpha

5 messages · Martin Maechler, Brian Ripley, robin hankin

#
Hello everyone

I am finding complex numbers to be printed oddly in R-alpha.


 > 1e100+1e100i
[1] 1e+100+1e+100i
 > 1e100 + 1e44i
[1] 1e+100+100000000000000008821361405306422640701865984i
 > dput(1e100+1e44i)
1e+100+100000000000000008821361405306422640701865984i
 >

[same thing at home on a linux box]


The first line is what I would expect, the second and third lines  
aren't:
I would prefer "1e100+1e44i".  Is this possible for  R-2.4.0?


best wishes


rksh




 > R.version
                _
platform       powerpc-apple-darwin8.7.0
arch           powerpc
os             darwin8.7.0
system         powerpc, darwin8.7.0
status         alpha
major          2
minor          4.0
year           2006
month          09
day            15
svn rev        39323
language       R
version.string R version 2.4.0 alpha (2006-09-15 r39323)



--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743
#
Robin> Hello everyone
    Robin> I am finding complex numbers to be printed oddly in R-alpha.


    >> 1e100+1e100i
    Robin> [1] 1e+100+1e+100i
    >> 1e100 + 1e44i
    Robin> [1] 1e+100+100000000000000008821361405306422640701865984i
    >> dput(1e100+1e44i)
    Robin> 1e+100+100000000000000008821361405306422640701865984i
    >> 

ouch, ouch!

    Robin> [same thing at home on a linux box]


    Robin> The first line is what I would expect, the second and third lines  
    Robin> aren't:
    Robin> I would prefer "1e100+1e44i".  Is this possible for  R-2.4.0?

It should.
It's clearly a bug --- the good news being that it's not a new
one: it already happens in 2.2.1 (e.g.)
Hence, no reason *not* to use R-beta!

Martin
#
On Thu, 21 Sep 2006, Martin Maechler wrote:

            
I think the right answer is 1e100+0i: read what 'digits' means for complex 
numbers.

It's been there since 2.2.0.
#
Hello

got it:

     o	The printing of complex numbers has changed, handling numbers
	as a whole rather than in two parts.  So both real and
	imaginary parts are shown to the same accuracy, with the
	'digits' parameter referring to the accuracy of the larger
	component, and both components are shown in fixed or
	scientific notation (unless one is entirely zero when it is
	always shown in fixed notation).

[this from the NEWS of R-2.2.0]

I'm struggling to reconcile the final clause of this with:


 > 1e100  + 1i
[1] 1e+100+1i
 > 1e100 + 1e-100i
[1] 1e+100+0i


in both of these cases, the real component is shown in scientific
notation and the imaginary component isn't.

I'm finding the following example confusing too:

 > 1e100 + pi*1i*10^(c(-100,0,1,40,100))
[1] 1e+100+3.1416e-100i 1e+100+ 3.1416e+00i 1e+100+ 3.1416e+01i
[4] 1e+100+ 3.1416e+40i 1e+100+3.1416e+100i
 >



rksh
On 21 Sep 2006, at 14:11, Prof Brian Ripley wrote:

            
--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743
#
On Thu, 21 Sep 2006, Robin Hankin wrote:

            
Yes, there is a bug here, but I think only for cases where what is printed 
should be zero, that is for complex numbers with very different 
magnitudes of real and imaginary parts.  A better version would be
[1] 1e+100+0e+00i
[1] 1e+100+0e+00i
[1] 1e+100+ 0.000000e+00i 1e+100+ 0.000000e+00i 1e+100+ 0.000000e+00i
[4] 1e+100+ 0.000000e+00i 1e+100+3.141593e+100i
[1] 1e+50+0e+00i 1e+50+0e+00i 1e+50+1e+48i
[1] 1e+50+3.2e+45i 1e+50+1.0e+45i 1e+50+3.2e+44i 1e+50+1.0e+44i 1e+50+0.0e+00i

which is what R-devel now gives.