1

I'm talking about functions such as Python's math.frexp() :

math.frexp(x)

Return the mantissa and exponent of x as the pair (m, e). m is a float and e is an integer such that x == m * 2**e exactly. If x is zero, returns (0.0, 0), otherwise 0.5 <= abs(m) < 1. This is used to “pick apart” the internal representation of a float in a portable way.

https://docs.python.org/3.4/library/math.html

And:

In some applications it is useful it obtain the mantissa and exponent of floating point numbers. http://www.technicalc.org/tiplist/en/files/pdf/tips/tip6_58.pdf

That said, what would be the usefulness of functions such as math.frexp() in real-world applications? What can I use it for?

Ruan
  • 203
  • 1
  • 6

1 Answers1

3

They are among other things very useful for calculating logarithms, or square roots and cubic roots.

For example: log x = log ($2^e * m$) = e * log 2 + log m. With 0.5 ≤ m ≤ 1, you can approximate log m using a polynomial, which wouldn't work for x which can be in the complete range of floating point numbers.

$x^{1/3}$ = $(2^e * m)^{1/3}$. Let e = 3k, 3k+1, or 3k+2, then this equals $2^k * m^{1/3}$ for 0.5 ≤ m ≤ 4. You can either use approximation by a polynomial for m, or you use Newton iteration which will be much faster for m in the small interval.

gnasher729
  • 32,238
  • 36
  • 56