[Rd] Problem with rnorm ?
Tong Wang
wangtong at usc.edu
Sun May 13 06:01:45 CEST 2007
It's working , Thanks a lot !!!
tong
----- Original Message -----
From: Prof Brian Ripley <ripley at stats.ox.ac.uk>
Date: Saturday, May 12, 2007 4:27 am
Subject: Re: [Rd] Problem with rnorm ?
To: Tong Wang <wangtong at usc.edu>
Cc: R-devel <r-devel at r-project.org>
> 1) You are linking an executable against -lR. You can't do that as
> here,for R is never initialized (and I very much doubt you will be
> able to
> give a reference that recommended you to do that). You need to
> link
> against standalone libRmath, or start up R properly if you really
> need R.
>
> 2) The arguments to rnorm() are doubles, not integers: did you not
> get a
> warning? I would expect automatic conversion to occur, but it is
> better
> to get this right.
>
> On Fri, 11 May 2007, Tong Wang wrote:
>
> > Hi,
> > I couldn't get the rnorm() work right in C, for example, the
> following code produce strange results.
> >
> > #include <stdio.h>
> > #include <Rmath.h>
> >
> > int main(void){
> > double x[3];
> > for(int i=0;i<3;i++) x[i]=rnorm(0,1);
> > printf("%lf,%lf,%lf",x[0],x[1],x[2]);
> > return 0;
> > }
> >
> > output : -8.773321,-8.773321,-8.773321
> > compiling script: gcc -std=gnu99 -Wall -IC:/PROGRA~1/R/R-
> 24~1.1/include test.c -LC:/PROGRA~1/R/R-24~1.1/bin -lR -o test
> >
> > Could someone tell me what's wrong with my code ? Thanks a lot.
> >
> > ______________________________________________
> > R-devel at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>
> --
> Brian D. Ripley, ripley at stats.ox.ac.uk
> Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
> University of Oxford, Tel: +44 1865 272861 (self)
> 1 South Parks Road, +44 1865 272866 (PA)
> Oxford OX1 3TG, UK Fax: +44 1865 272595
>
More information about the R-devel
mailing list