1
$\begingroup$

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?

$\endgroup$
3
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Can you explain in what way? $\endgroup$ – Yuval Filmus Jul 26 '17 at 20:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.