Dear R-developer (Marsaglia??)
The following piece of code from package SuppDist , routine "dist.cc"
seems
to have a bug
ULONG MWC1019(void){
ULONG long t;
int i = endQ-1;
t = 147669672LL*Q[i] + Q[endQ];
Q[endQ] = (t>>32);
if(i>0)
return(Q[i--] = t);
i = endQ-1;
return(Q[0] = t);
}
in fact , being "i" a local variable that have automatic storage, it
is
initialized to endQ-1 (1019)
each time the routine is called so that it can never
cycle through all values as it should.
I think it should be declared as static:
ULONG MWC1019(void){
ULONG long t;
static int i = endQ-1;
t = 147669672LL*Q[i] + Q[endQ];
Q[endQ] = (t>>32);
if(i>0)
return(Q[i--] = t);
i = endQ-1;
return(Q[0] = t);
}
Best regards,
Guido Montorsi
Guido Montorsi wrote:> Dear R-developer (Marsaglia??) > > The following piece of code from package SuppDist , routine "dist.cc" seems > to have a bugThe package is called *SuppDists*. Bug reports and contributions for contributed packages should be addressed to the package maintainer (CCing, he might not be listening) rather than to R-help. Thanks. Uwe Ligges> ULONG MWC1019(void){ > ULONG long t; > int i = endQ-1; > > t = 147669672LL*Q[i] + Q[endQ]; > Q[endQ] = (t>>32); > if(i>0) > return(Q[i--] = t); > i = endQ-1; > return(Q[0] = t); > } > > in fact , being "i" a local variable that have automatic storage, it is > initialized to endQ-1 (1019) > each time the routine is called so that it can never > cycle through all values as it should. > > I think it should be declared as static: > > ULONG MWC1019(void){ > ULONG long t; > static int i = endQ-1; > > t = 147669672LL*Q[i] + Q[endQ]; > Q[endQ] = (t>>32); > if(i>0) > return(Q[i--] = t); > i = endQ-1; > return(Q[0] = t); > } > > Best regards, > > Guido Montorsi > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
On Mon, 14 Mar 2005 16:54:46 +0100, "Guido Montorsi" <montorsi at polito.it> wrote :>Dear R-developer (Marsaglia??) > >The following piece of code from package SuppDist , routine "dist.cc" seems >to have a bugYou should normally send package bug reports to the maintainer, in this case Bob Wheeler (who I've cc'd). By the way, I agree that code does look wrong, but it would also be helpful to provide R code that gives obviously wrong answers because of it. Duncan Murdoch> >ULONG MWC1019(void){ > ULONG long t; > int i = endQ-1; > > t = 147669672LL*Q[i] + Q[endQ]; > Q[endQ] = (t>>32); > if(i>0) > return(Q[i--] = t); > i = endQ-1; > return(Q[0] = t); >} > >in fact , being "i" a local variable that have automatic storage, it is >initialized to endQ-1 (1019) > each time the routine is called so that it can never >cycle through all values as it should. > >I think it should be declared as static: > >ULONG MWC1019(void){ > ULONG long t; > static int i = endQ-1; > > t = 147669672LL*Q[i] + Q[endQ]; > Q[endQ] = (t>>32); > if(i>0) > return(Q[i--] = t); > i = endQ-1; > return(Q[0] = t); >} > >Best regards, > >Guido Montorsi > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html