[R] Behaviour of very large numbers
Gustaf Rydevik
gustaf.rydevik at gmail.com
Thu Aug 30 17:33:34 CEST 2007
On 8/30/07, Gustaf Rydevik <gustaf.rydevik at gmail.com> wrote:
> On 8/30/07, willem vervoort <willemvervoort at gmail.com> 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?
> >
> > B
> > [1] 47.73092
> >
> > > -51^B
> > [1] -3.190824e+81
> >
> > # seems fine
> > # 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.
> >
> > Any clues would be really appreciated.
> > Willem
> >
>
> non-integer exponents of non-positive values are not defined, thus the NaN.
>
> > -1^2.5
> [1] -1
> > (-1)^2.5
> [1] NaN
> >
>
> Best,
>
> Gustaf
>
To modify, that is if you are working with reals.
> x
[1] -1
> x^(1/2)
[1] NaN
> class(x)<-"complex"
> x^(1/2)
[1] 0+1i
> x<--51
> x^47.7
[1] NaN
> class(x)<-"complex"
> x^47.7
[1] 1.660795e+81-2.285889e+81i
>
Best,
Gustaf
--
Gustaf Rydevik, M.Sci.
tel: +46(0)703 051 451
address:Essingetorget 40,112 66 Stockholm, SE
skype:gustaf_rydevik
More information about the R-help
mailing list