[R] Behaviour of very large numbers
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu Aug 30 18:17:51 CEST 2007
On Thu, 30 Aug 2007, 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?
Where are the 'very large numbers' here? R can cope with much larger
numbers (over 10^300).
> B
> [1] 47.73092
>
>> -51^B
> [1] -3.190824e+81
Yes, that is -(51^B).
> # 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
>
> I guess I must be misunderstanding something fundamental.
You are. A negative number to a non-integer power is undefined in the
real number system.
Look at (x+0i)^B.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list