Loïc Paulevé
2009-Mar-24 22:36 UTC
[R] Return value from a C program is different from the R console
Dear R-users, I'm trying to call the qgamma function from a C program. But I'm experiencing a strange issue: the value returned by the C function seems to be different from the value returned by a R console. I'm running on linux 2.6.27 (ubuntu), i686 arch; R version 2.7.1 (2008-06-23) (shipped by ubuntu). My C code: #include <stdio.h> #include <Rmath.h> int main() { double q, shape, scale, res; q = 0.025; shape = 50; scale = 0.08; res = qgamma(q, shape, scale, TRUE, FALSE); printf("qgamma(%.5f, shape=%.5f, scale=%.5g, lower.tail=TRUE, log.p=FALSE) = %.5f\n", q, shape, scale, res); return 0; } Result : qgamma(0.02500, shape=50.00000, scale=0.08, lower.tail=TRUE, log.p=FALSE) = 2.67178 When executing into R :> qgamma(0.02500, shape=50.00000, scale=0.08, lower.tail=TRUE, log.p=FALSE)[1] 2.968877 I dunno which value is the correct one, but I suspect a wrong usage of the double type in my C code. Any help? Thanks! Lo?c