RE: [S] Unusual result -- A glitch, I'd say

Byers, Bob (rhb1@cdc.gov)
Wed, 25 Mar 1998 10:58:53 -0500


Printing the partial sums illuminates the process:
a_0
?print(a_a+1)
[1] 1
?a
[1] 1
?a_0
?print((a_a+1)+(a_a+10))
[1] 22 # 11+11
?a
[1] 11
?a_0
?print((a_a+1)+(a_a+10)+(a_a+100))
[1] 133 # 22+111
?a
[1] 111
?a_0
?print((a_a+1)+(a_a+10)+(a_a+100)+(a_a+1000))
[1] 1244 #
133+1111
?a_0
?print((a_a+1)+(a_a+10)+(a_a+100)+(a_a+1000)+(a_a+10000))
[1] 12355 # 1244+11111

Apparently S+ is evaluating from left to right and applying the plus
operator whenever it has two
valid operands. This is in contrast to FORTRAN which evaluates all inner
parentheses first.

-Bob

Robert H. Byers, Jr. Ph.D.
rhb1@cdc.gov
Centers for Disease Control & Prevention
NCHSTP/Statistics & Data Mgmt Branch

> -----Original Message-----
> From: Paul A Tukey [SMTP:paul@bellcore.com]
> Sent: Wednesday, March 25, 1998 7:15 AM
> To: bert_gunter@merck.com; berwin.turlach@anu.edu.au
> Subject: RE: [S] Unusual result -- A glitch, I'd say
>
> Here's a generalization that suggests there may
> actually be a glitch in Splus:
>
> > a_0
> > print( (a_a+10000) + (a_a+1000) + (a_a+100) + (a_a+10) + (a_a+1)
> )
> [1] 55321
> > a
> [1] 11111
>
> > a_0
> > print( (a_a+1) + (a_a+10) + (a_a+100) + (a_a+1000) + (a_a+10000)
> )
> [1] 12355
> > a
> [1] 11111
>
> Trying different numbers of terms consistently gives the impression
> that the second term from the left is being treated differently
> from the others.
>
> ----------------------------------------------------------------------
> -
> This message was distributed by s-news@wubios.wustl.edu. To
> unsubscribe
> send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
> message: unsubscribe s-news
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news