I noticed the following when running gmp
from R
:
Rgames> log2(Inf)
[1] Inf
Rgames> log2(as.bigz(Inf))
[1] 8000
What's happening here? Or does the gmp
language (or gmp::log2.bigz
method) just not support the concept of "Inf" ?
EDIT: Josh's comment is correct: it's not the log2
function per se but rather the fact that as.bigz
appears to convert Inf
to 2^8000
as a bigz
integer. Changed title to match.
BTW, there's also this:
Rgames> log2(-Inf)
[1] NaN
Warning message:
NaNs produced
Rgames> log2(as.bigz(-Inf))
[1] NaN
EDIT: that was stupid. log2(negative_anything)
is NaN
But,
Rgames> log2(-as.bigz(-Inf))
[1] 8000
Fits with Josh's answer.
Posting Josh's detective work for him, per request:
If you download the sources for gmp
, and search for "Inf" in $gmp-HOME$/src/bigintegerR.cc
, you'll find the following lines:
/// New: numeric '+- Inf' give +- "Large" instead of NA
and a bit later
else { // dj is +- Inf : use LARGE ( = +- 2 ^ 80000 -- arbitrarily )
My guess is that since the GMP library doesn't have a concept/representation of Inf
, the R package authors had to make some decision about how to pass on user-supplied Inf
values to the external library. It looks like they used to convert Inf
to NA
, and now they convert it to 2^80000
.