[erlang-questions] String representations of floating point numbers

Richard O'Keefe raoknz@REDACTED
Sat Mar 16 11:56:14 CET 2019


I'd say that the specification of the input to erlang:list_to_float/1
should be in
the manual entry for erlang:list_to_float/1, namely
http://erlang.org/doc/man/erlang.html#list_to_float-1
By experiment, it looks like /^[-+]?[0-9]+[.][0-9]+([eE][-+]?[0-9]+)?$/
(Note: [-+] works but [+-] of course does not.)

On Sat, 16 Mar 2019 at 11:52, Hugo Mills <hugo@REDACTED> wrote:

>    Where in the manual is the set of allowable string representations
> of floating point numbers documented? I'd have expected it to be here:
>
> http://erlang.org/doc/reference_manual/data_types.html
>
> ... but apparently not.
>
>    Specifically, I'm trying to use list_to_float/1, and I've been
> trying to reverse engineer it:
>
> 1> list_to_float("-1").
> ** exception error: bad argument
>      in function  list_to_float/1
>         called as list_to_float("-1")
> 2> list_to_float("-1.0").
> -1.0
> 3> list_to_float("-1.0e-23").
> -1.0e-23
> 4> list_to_float("-1e-23").
> ** exception error: bad argument
>      in function  list_to_float/1
>         called as list_to_float("-1e-23")
> 5> list_to_float(".3").
> ** exception error: bad argument
>      in function  list_to_float/1
>         called as list_to_float(".3")
>
>    An actual written specification would be really handy here. Even
> just a regex or EBNF for them. I'm writing a parser for something
> where the definition of floating point literals isn't quite the same
> as Erlang's, and it's a bit painful.
>
>    Hugo.
>
> --
> Hugo Mills             | Your problem is that you've got too much taste to
> be
> hugo@REDACTED carfax.org.uk | a web developer.
> http://carfax.org.uk/  |
> PGP: E2AB1DE4          |                                          Steve
> Harris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.12 (GNU/Linux)
>
> iQIbBAEBAgAGBQJcjCyYAAoJEFheFHXiqx3kBo8P+KYpzGUmaV4lA8jopR5h39S8
> XMt6e+mO4zceiz1LE9mGFozayPPgPlchuJz3h/9EgtvNKXV8AvUGLFOZHtcE5qeM
> wDwQg6kreHW/5ejrpYFCH1rZt9DftnAzMQo0SXOCQTfLkAC5W/jRrZyAE8ibVEH+
> JoAOG/ZRUTz4E3bnoSGfcrY13IwD5A3sJ3Jex6rLttVjJyfCEbBJMx5ofFXO9WbY
> PfggXSD7EALHdUOT1vQWJsRiJClq25HjAucblA+zst/8N1wllpRnK3uhA1M22lNB
> OuYv0lnvKwYmyNSs/VcXRAne5CXjpf/CxJpVMuvXdbRYxrlsybWz9+UWMk7DB+TA
> fQvCRIGROG/DlVWo8KAoMN6ZgfxE3pmVjfN3p2usDza2V43QAY+jaZF7x2SyxKxo
> Bw4/jW7RODduzWu/XQvRX0780RQlbPbNcFjrOHIt3PZe7+Qtl++6QQcVCJ+TrE8h
> 1drKkbFvm2/ecyAXdMkXV8CxiJdbgcSkz2kgIYhTUpiGJz0ubCt3HOA/byh3P8em
> /5EhxuQQo5r+Yvn4rHkOIe2KBJuBHHhNky9f8xRU7j9JnxFvm6tQK8tJ4C3fIklI
> yua+T9thS3XifUNiWTw/WX6CjSYVl2/lFtmzXYZ5+LiZgd4IImEHnXik/jOv/2eC
> ayHhzl8YuA1yxsjULsw=
> =Y3WO
> -----END PGP SIGNATURE-----
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190316/a18eb1b0/attachment.htm>


More information about the erlang-questions mailing list