Eryk, On Sep 13, 2005, at 2:26 PM, nwew wrote:
> printf("%f\n",NUMERIC_POINTER(mat)[1]); > [...] > However it prints > 0.0000 > if [EMAIL PROTECTED] are integers ( [EMAIL PROTECTED]<-matrix(1:12,3,4) ). > > Can anyone explain it to me why? > I thought that NUMERIC_POINTER makes it clear that i expect > datatype numeric. > (Why otherwise the distinction with INTEGER_POINTER) You answered your own question - NUMERIC_POINTER expects that the SEXP you pass to it is numeric=double. When you use it, it's your responsibility to make sure that the SEXP is numeric and not integer or anything else. Probably you may want to use AS_NUMERIC to ensure that. [btw: NUMERIC_POINTER() is a compatibility macro for REAL() and AS_NUMERIC(x) for coerceVector(x,REALSXP)]. Also you should be aware that C uses 0-based indices so NUMERIC_POINTER(mat)[1] accesses the 2nd element of the vector. Cheers, Simon ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel