R-alpha: ":" returns "real" in all cases. I'd like 1:n to be integer

Martin Maechler (maechler@stat.math.ethz.ch)
Tue, 26 Mar 96 18:15:23 +0100


Date: Tue, 26 Mar 96 18:15:23 +0100
Message-Id: <9603261715.AA01701@>
From: Martin Maechler <maechler@stat.math.ethz.ch>
To: R-testers@stat.math.ethz.ch
Subject: R-alpha: ":"  returns "real" in all cases. I'd like  1:n to be integer


I first wondered why

	typeof(1:4)  #-> "real"  instead of  "integer"

But look at the result of

	-pi : pi

which is quite a surprise (to me).
But that's the same as S is doing.

The difference to S is that there, the result of

	n:m

is integer when both arguments ``can be coerced'' (without loss of prec.)
to integer.

In S:

> all(2:pi == 2:as.double(3))
[1] T
> storage.mode(2 : pi)
[1] "double"
> storage.mode(2 : as.double(3))
[1] "integer"

In  R,  the 3rd and 2nd statement return  'numeric'
		(and will return 'real' once that  storage.mode is fixed ?!?)

	
[ The code  is in  src/main/seq.c ]
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-testers mailing list -- To (un)subscribe, send
subscribe	or	unsubscribe
(in the "body", not the subject !)  To: r-testers-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-