frexp

Contents

frexp#

class saiunit.math.frexp(x, unit_to_scale=None, **kwargs)#

Decompose elements into mantissa and base-2 exponent.

Returns (mantissa, exponent) such that x = mantissa * 2**exponent.

Parameters:
  • x (saiunit.Quantity | Array | ndarray | bool | number | bool | int | float | complex) – Array to decompose.

  • unit_to_scale (saiunit.Unit | None) – Unit used to convert x to a dimensionless number first.

Return type:

Tuple[Array, Array]

Returns:

  • mantissa (jax.Array) – Floating values in (-1, 1).

  • exponent (jax.Array) – Integer exponents of 2.

Examples

>>> import saiunit as u
>>> import jax.numpy as jnp
>>> m, e = u.math.frexp(jnp.array([1.0, 2.0, 4.0]))
>>> m
Array([0.5, 0.5, 0.5], dtype=float32)
>>> e
Array([1, 2, 3], dtype=int32)