Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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

d

a numeric vector whose absolute values are either zero, or in [0.5, 1).

exp

an integer vector of the same length; note that exp == 1 + floor(log2(x)), and hence always exp > log2(x).

Author(s)

Martin Maechler

See Also

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

Examples

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
)

gmp

Multiple Precision Arithmetic

v0.6-2
GPL (>= 2)
Authors
Antoine Lucas, Immanuel Scholz, Rainer Boehme <rb-gmp@reflex-studio.de>, Sylvain Jasson <Sylvain.Jasson@inrae.fr>, Martin Maechler <maechler@stat.math.ethz.ch>
Initial release
2021-01-07

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.