Learn R Programming

gmp (version 0.5-13)

frexpZ: Split Number into Fractional and Exponent of 2 Parts

Description

Breaks the number x into its binary significand (“fraction”) $d in [0.5, 1)$ and $ex$, the integral exponent for 2, such that $x = d * 2 ^ ex.$

If x is zero, both parts (significand and exponent) are zero.

Usage

frexpZ(x)

Arguments

x
integer or big integer (bigz).

Value

a list with the two components

See Also

log2, etc; for bigz objects built on (the C++ equivalent of) frexp(), actually GMP's mpz_get_d_2exp().

Examples

Run this code
frexpZ(1:10)
## and confirm :
with(frexpZ(1:10),  d * 2^exp)
x <- rpois(1000, lambda=100) * (1 + rpois(1000, lambda=16))
X <- as.bigz(x)
stopifnot(all.equal(x, with(frexpZ(x), d* 2^exp)),
          1+floor(log2(x)) == (fx <- frexpZ(x)$exp),
          fx == frexpZ(X)$exp,
          1+floor(log2(X)) == fx
)

Run the code above in your browser using DataLab