<div dir="ltr">Both the NNN_NNN and the Base#NNN notation go back to Ada, so they are not particular either for OCaml or Erlang, respectively.<div><a href="http://archive.adaic.com/standards/83lrm/html/lrm-02-04.html">http://archive.adaic.com/standards/83lrm/html/lrm-02-04.html</a></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><br> /Richard</div></div>
<br><div class="gmail_quote">2017-02-08 16:35 GMT+01:00 Jesper Louis Andersen <span dir="ltr"><<a href="mailto:jesper.louis.andersen@gmail.com" target="_blank">jesper.louis.andersen@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Another example is OCaml, which supports entering integers as<br><br># 1_000_000;;<br>- : int = 1000000<br><br></div>which is very nifty, but unique to OCaml and thus not too portable.<br></div><div class="HOEnZb"><div class="h5"><br><div class="gmail_quote"><div dir="ltr">On Wed, Feb 8, 2017 at 12:16 PM Mikael Pettersson <<a href="mailto:mikpelinux@gmail.com" target="_blank">mikpelinux@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Oleksii Semilietov writes:<br class="m_4655389722511884420gmail_msg">
> Hi all!<br class="m_4655389722511884420gmail_msg">
><br class="m_4655389722511884420gmail_msg">
> I playing with converting binaries and lists to floats and I found<br class="m_4655389722511884420gmail_msg">
> something what I can't solve via elegant way. I believe it's my leakage of<br class="m_4655389722511884420gmail_msg">
> understanding floats.<br class="m_4655389722511884420gmail_msg">
><br class="m_4655389722511884420gmail_msg">
> So, what is different between 1e-8 and 1.0e-8 ?<br class="m_4655389722511884420gmail_msg">
><br class="m_4655389722511884420gmail_msg">
> For example we have float as list "0.01". It is easy to convert it to<br class="m_4655389722511884420gmail_msg">
> float just via list_to_float("0.01").<br class="m_4655389722511884420gmail_msg">
> But when floats coming from external world as binaries or lists which looks<br class="m_4655389722511884420gmail_msg">
> like "1e-8", and not like "1.0e-8", I can't find proper way to convert it.<br class="m_4655389722511884420gmail_msg">
><br class="m_4655389722511884420gmail_msg">
> For example in PHP both 1e-8 and 1.0e-8 is equivalent<br class="m_4655389722511884420gmail_msg">
> var_dump(floatval("1e-8") === floatval("1.0e-8")) returns true.<br class="m_4655389722511884420gmail_msg">
> Javascript 1E-8 === 1.0E-8 is also true.<br class="m_4655389722511884420gmail_msg">
><br class="m_4655389722511884420gmail_msg">
> In Erlang<br class="m_4655389722511884420gmail_msg">
><br class="m_4655389722511884420gmail_msg">
> list_to_float("1.0E-8") =:= 0.00000001<br class="m_4655389722511884420gmail_msg">
> true<br class="m_4655389722511884420gmail_msg">
><br class="m_4655389722511884420gmail_msg">
> but<br class="m_4655389722511884420gmail_msg">
><br class="m_4655389722511884420gmail_msg">
> list_to_float("1E-8") =:= 0.00000001.<br class="m_4655389722511884420gmail_msg">
> ** exception error: bad argument in function list_to_float/1 called as<br class="m_4655389722511884420gmail_msg">
> list_to_float("1E-8")<br class="m_4655389722511884420gmail_msg">
><br class="m_4655389722511884420gmail_msg">
><br class="m_4655389722511884420gmail_msg">
> How to convert it via right way?<br class="m_4655389722511884420gmail_msg">
<br class="m_4655389722511884420gmail_msg">
Write your own conversion routine.<br class="m_4655389722511884420gmail_msg">
<br class="m_4655389722511884420gmail_msg">
Your mistake is assuming literals like floats have the same look and feel<br class="m_4655389722511884420gmail_msg">
regardless of language or environment. That's in general not true.<br class="m_4655389722511884420gmail_msg">
<br class="m_4655389722511884420gmail_msg">
You may also consider the different notation for integers with non-decimal<br class="m_4655389722511884420gmail_msg">
base, e.g. 0xabba vs 16#abba, or character literals, etc.<br class="m_4655389722511884420gmail_msg">
<br class="m_4655389722511884420gmail_msg">
What it means is that a tool written in one language but processing source<br class="m_4655389722511884420gmail_msg">
code for another, must be prepared to do all conversions on its own without<br class="m_4655389722511884420gmail_msg">
relying on ready-made services in the implementation language.<br class="m_4655389722511884420gmail_msg">
______________________________<wbr>_________________<br class="m_4655389722511884420gmail_msg">
erlang-questions mailing list<br class="m_4655389722511884420gmail_msg">
<a href="mailto:erlang-questions@erlang.org" class="m_4655389722511884420gmail_msg" target="_blank">erlang-questions@erlang.org</a><br class="m_4655389722511884420gmail_msg">
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" class="m_4655389722511884420gmail_msg" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br class="m_4655389722511884420gmail_msg">
</blockquote></div>
</div></div><br>______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>