9

Python and C have frexp and ldexp functions (they basically go back and forth between y, and x and i in y = x*2^i).

I guess that exp means exponent (of 2). What is the meaning of "ld" and "fr"? I see in http://pubs.opengroup.org/onlinepubs/009695399/functions/ldexp.html that "ld" could mean "load" (from mantissa/exponent form), but even this is not fully clear. I am not sure about "fr", though (http://pubs.opengroup.org/onlinepubs/9699919799/functions/frexp.html does not similarly give a clue).

So, what is the meaning of the names frexp and ldexp? I am hoping that this could help remembering which is which.

Eric O. Lebigot
  • 91,433
  • 48
  • 218
  • 260
  • 4
    I'd guess that `frexp()` stands for *fraction* and *exponent*. No idea about `ldexp()`. – EOF Aug 15 '16 at 09:31
  • 1
    `frexp` breaks a floating point number into a normalized fraction and exponent. `ldexp` is sort of the inverse, multiplying a fraction by an integral power of 2. As a guess, `frexp` could be shorthand for "fraction and exponent" like EOF says, while `ldexp` could be shorthand for "load exponent". Or the names could be completely arbitrary. – John Bode Aug 15 '16 at 12:15
  • They are clearly explained in the text of the linked pages. What **specificcally** don't you understand? Did you try out (using your assumptions wha the text means)? What did you get? Was that what you expected? What did you expect? – too honest for this site Aug 15 '16 at 12:34
  • @Olaf: I am confused: I don't see that the **names** of the functions are "clearly explained in the text of the linked pages". If they are, this would be a good answer to give to this StackOverflow question! – Eric O. Lebigot Aug 15 '16 at 18:34
  • @EOL: Well, the functions are explained and at least for `ldexp` the name is clear. For `frexp` there really is no direct explanation, but then there are other functions which have no really explanatory names. Considering how rearely they are used, I don't see much reason to memorise their names anyway. Just remember the fact there "is some function" and check the standard library. – too honest for this site Aug 15 '16 at 19:11
  • I must say that I like @JohnBode's interpretation. And sometimes people do know some interesting facts about names, so there is hope that someone does have an answer (see, e.g., http://stackoverflow.com/questions/10059673/named-regular-expression-group-pgroup-nameregexp-what-does-p-stand-for). – Eric O. Lebigot Aug 15 '16 at 19:33

1 Answers1

2

It's very simple. As you already discovered earlier ldexp means load exponent: just multiply number by 2 raised to the power of some value. And the inverse function for ldexp which called frexp means extraction of float radix from a value:

Breaks the floating point number x into its binary significand (a floating point with an absolute value between 0.5(included) and 1.0(excluded)) and an integral exponent for 2, such that.*

ldexp and frexp function in Python came from C since old C90 standart. So, it's very old beard.

*http://www.cplusplus.com/reference/cmath/frexp/

Egor Richman
  • 559
  • 3
  • 13