# [R] Behaviour of very large numbers

Martin Becker martin.becker at mx.uni-saarland.de
Thu Aug 30 18:11:21 CEST 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?
>
>  B
> [1] 47.73092
>
>
>> -51^B
>>
> [1] -3.190824e+81
>
> # seems fine
>

Well, this seems not to be what you intended to do, you didn't raise a
negative value to a power, but you got the negative of a positive number
raised to that power (operator precedence, -51^B is the same as -(51^B)
and not the same as (-51)^B...).

If you really want to raise a negative value to a fractional power, you
may want to tell R to use complex numbers:

B <- 47.73092
x <- complex(real=seq(-51,-49,length=10))

x^B

[1] 2.117003e+81-2.387323e+81i 1.718701e+81-1.938163e+81i
[3] 1.394063e+81-1.572071e+81i 1.129702e+81-1.273954e+81i
[5] 9.146212e+80-1.031409e+81i 7.397943e+80-8.342587e+80i
[7] 5.978186e+80-6.741541e+80i 4.826284e+80-5.442553e+80i
[9] 3.892581e+80-4.389625e+80i 3.136461e+80-3.536955e+80i
>

Regards,

Martin

> # 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
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

```

More information about the R-help mailing list