<div dir="ltr">On Thu, Feb 1, 2018 at 12:49 PM Loïc Hoguin <<a href="mailto:essen@ninenines.eu">essen@ninenines.eu</a>> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
And there is scalbn (also known as ldexp, apparently) which does x*2^i<br>
where x is a double and i is an integer. I'm not sure what it's used for<br>
to be honest.<br>
<br></blockquote></div><div class="gmail_quote"><br></div><div class="gmail_quote">ldexp is used together with its cousin, frexp. The frexp function can "split" a floating point number in its exponent and mantissa parts. And ldexp recombines them back. This allows you to have explicit control over a situation where overlfow or underflow might happen: you can get at the underlying FP representation without bitwise tricks (so that it is portable), manipulate your number and reassemble it.</div><div class="gmail_quote"><br></div><div class="gmail_quote">Erlang's floating point numbers are handled differently than in most languages. Some of this is a trade-off: in Erlang, we prefer errors to occur when you do something bad, rather than a propagation of the error. The latter is a NaN. As a result, Erlang doesn't allow certain things:</div><div class="gmail_quote"><br></div><div class="gmail_quote">* -0.0 is eliminated to 0.0</div><div class="gmail_quote">* No NaNs</div><div class="gmail_quote">* No Infty/-Infty. This is a pure headache in the eministat library currently.</div><div class="gmail_quote"><br></div><div class="gmail_quote">It does produce the need for you to map external fp numbers into a way which Erlang accepts internally. OTOH, it does eliminate some subtle bugs where a NaN is propagated way too long in the program and you don't know where the error occurred in the first place.</div><div class="gmail_quote"><br></div></div>