[R] Behaviour of very large numbers
murdoch at stats.uwo.ca
Thu Aug 30 17:23:40 CEST 2007
On 8/30/2007 11:08 AM, willem vervoort wrote:
> Dear all,
> I am struggling to understand this.
> What happens when you raise a negative value to a power and the result
> is a very large number?
>  47.73092
>  -3.190824e+81
You should be using parentheses. You evaluated -(51^B), not (-51)^B.
The latter gives NaN.
> # seems fine
> # now this:
>> x <- seq(-51,-49,length=100)
>  NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN <snip>
>  TRUE
>  TRUE
>  FALSE FALSE FALSE FALSE FALSE
> I am lost, I checked the R mailing help, but could not find anything
> directly. I loaded package Brobdingnag and tried:
>  NAexp(NaN) NAexp(NaN) NAexp(NaN) NAexp(NaN) NAexp(NaN)
>  NAexp(187.67) NAexp(187.65) NAexp(187.63) NAexp(187.61)
> I guess I must be misunderstanding something fundamental.
Two things: operator precedence (the ^ has higher precedence than the
unary minus), and the mathematical definition of raising something to a
fractional power. The approach R takes to the latter is to define x^B
to be exp(B * ln(x)), and ln(x) is undefined for negative x.
More information about the R-help