[R] Behaviour of very large numbers
Nordlund, Dan (DSHS/RDA)
NordlDJ at dshs.wa.gov
Thu Aug 30 17:40:57 CEST 2007
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of willem vervoort
> Sent: Thursday, August 30, 2007 8:09 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Behaviour of very large numbers
>
> 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?
>
> B
> [1] 47.73092
>
> > -51^B
> [1] -3.190824e+81
>
> # seems fine
It seems fine because the precedence of the '^' operator is higher than the unary negation operator '-'. Your example is actually evaluated as -(51^B).
> # now this:
> > x <- seq(-51,-49,length=100)
>
> > x^B
> [1] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
> NaN NaN NaN <snip>
> > is.numeric(x^B)
> [1] TRUE
> > is.real(x^B)
> [1] TRUE
> > is.infinite(x^B)
> [1] 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:
> as.brob(x^B)
> [1] NAexp(NaN) NAexp(NaN) NAexp(NaN) NAexp(NaN) NAexp(NaN)
> > as.brob(x)^B
> [1] NAexp(187.67) NAexp(187.65) NAexp(187.63) NAexp(187.61)
>
> I guess I must be misunderstanding something fundamental.
>
Yes, you can't raise a negative number to a fractional power.
Hope this is helpful,
Dan
Daniel J. Nordlund
Research and Data Analysis
Washington State Department of Social and Health Services
Olympia, WA 98504-5204
More information about the R-help
mailing list