<div dir="ltr"><div dir="ltr"><div dir="ltr">If you dive into the implementation it's effectively a wrapper around strtod from C with a validation pass that is more strict than the strtod standard.<div><br></div><div><a href="https://github.com/erlang/otp/blob/OTP-21.3/erts/emulator/sys/win32/sys_float.c#L54">https://github.com/erlang/otp/blob/OTP-21.3/erts/emulator/sys/win32/sys_float.c#L54</a><br></div><div><a href="https://github.com/erlang/otp/blob/OTP-21.3/erts/emulator/sys/unix/sys_float.c#L732">https://github.com/erlang/otp/blob/OTP-21.3/erts/emulator/sys/unix/sys_float.c#L732</a><br></div><div><br></div><div>So as far as a regex goes it would be something like this:</div><div><br></div><div>[+-]?\d+[.,]\d+([eE][+-]?\d+)</div><div><br></div><div>The major differences between this and other popular float grammars are:</div><div><br></div><div>* At least one digit is required in each part</div><div>* Both integer and fractional parts are required, even if there's an exponent part (so "1", ".1", "1e-1" would not be valid)</div><div>* The decimal separator is either , or . (the implementation will try the other if necessary to compensate for a different locale)</div><div><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Mar 15, 2019 at 3:52 PM Hugo Mills <<a href="mailto:hugo@carfax.org.uk">hugo@carfax.org.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">   Where in the manual is the set of allowable string representations<br>
of floating point numbers documented? I'd have expected it to be here:<br>
<br>
<a href="http://erlang.org/doc/reference_manual/data_types.html" rel="noreferrer" target="_blank">http://erlang.org/doc/reference_manual/data_types.html</a><br>
<br>
... but apparently not.<br>
<br>
   Specifically, I'm trying to use list_to_float/1, and I've been<br>
trying to reverse engineer it:<br>
<br>
1> list_to_float("-1").<br>
** exception error: bad argument<br>
     in function  list_to_float/1<br>
        called as list_to_float("-1")<br>
2> list_to_float("-1.0").<br>
-1.0<br>
3> list_to_float("-1.0e-23").<br>
-1.0e-23<br>
4> list_to_float("-1e-23").  <br>
** exception error: bad argument<br>
     in function  list_to_float/1<br>
        called as list_to_float("-1e-23")<br>
5> list_to_float(".3").<br>
** exception error: bad argument<br>
     in function  list_to_float/1<br>
        called as list_to_float(".3")<br>
<br>
   An actual written specification would be really handy here. Even<br>
just a regex or EBNF for them. I'm writing a parser for something<br>
where the definition of floating point literals isn't quite the same<br>
as Erlang's, and it's a bit painful.<br>
<br>
   Hugo.<br>
<br>
-- <br>
Hugo Mills             | Your problem is that you've got too much taste to be<br>
hugo@... <a href="http://carfax.org.uk" rel="noreferrer" target="_blank">carfax.org.uk</a> | a web developer.<br>
<a href="http://carfax.org.uk/" rel="noreferrer" target="_blank">http://carfax.org.uk/</a>  |<br>
PGP: E2AB1DE4          |                                          Steve Harris<br>
-----BEGIN PGP SIGNATURE-----<br>
Version: GnuPG v1.4.12 (GNU/Linux)<br>
<br>
iQIbBAEBAgAGBQJcjCyYAAoJEFheFHXiqx3kBo8P+KYpzGUmaV4lA8jopR5h39S8<br>
XMt6e+mO4zceiz1LE9mGFozayPPgPlchuJz3h/9EgtvNKXV8AvUGLFOZHtcE5qeM<br>
wDwQg6kreHW/5ejrpYFCH1rZt9DftnAzMQo0SXOCQTfLkAC5W/jRrZyAE8ibVEH+<br>
JoAOG/ZRUTz4E3bnoSGfcrY13IwD5A3sJ3Jex6rLttVjJyfCEbBJMx5ofFXO9WbY<br>
PfggXSD7EALHdUOT1vQWJsRiJClq25HjAucblA+zst/8N1wllpRnK3uhA1M22lNB<br>
OuYv0lnvKwYmyNSs/VcXRAne5CXjpf/CxJpVMuvXdbRYxrlsybWz9+UWMk7DB+TA<br>
fQvCRIGROG/DlVWo8KAoMN6ZgfxE3pmVjfN3p2usDza2V43QAY+jaZF7x2SyxKxo<br>
Bw4/jW7RODduzWu/XQvRX0780RQlbPbNcFjrOHIt3PZe7+Qtl++6QQcVCJ+TrE8h<br>
1drKkbFvm2/ecyAXdMkXV8CxiJdbgcSkz2kgIYhTUpiGJz0ubCt3HOA/byh3P8em<br>
/5EhxuQQo5r+Yvn4rHkOIe2KBJuBHHhNky9f8xRU7j9JnxFvm6tQK8tJ4C3fIklI<br>
yua+T9thS3XifUNiWTw/WX6CjSYVl2/lFtmzXYZ5+LiZgd4IImEHnXik/jOv/2eC<br>
ayHhzl8YuA1yxsjULsw=<br>
=Y3WO<br>
-----END PGP SIGNATURE-----<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div>