[erlang-questions] binary_to_integer/1 and binary_to_float/1 and friends

Bob Ippolito <>
Mon Apr 30 19:53:02 CEST 2012

On Mon, Apr 30, 2012 at 10:47 AM, José Valim <> wrote:

> At the beginning of this year, there was a discussion about how to
> implement binary_to_integer/1 in Erlang.
> There is a possible implementation for such function which is quite
> trivial:
>     list_to_integer(binary_to_list(binary))
> However, it has the trade-off that it can't be used in guards (unless
> defined in a macro) and there is an unnecessary conversion cost to list
> (although the cost is small since both binary and list are likely small).
> With Riak, Cowboy and other tools pushing towards using binaries instead
> of lists for strings, the need for such functions will become more and more
> common.
> Is there any chance we will see this as built-in functions and therefore
> available in guards in R16?

I think this is a good proposal. We've already got these functions for
atoms, numbers make sense too. I find myself implementing this often one
way or another, sometimes just using a JSON parser and checking that the
result is the kind of number I'm looking for.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120430/ff512caf/attachment.html>

More information about the erlang-questions mailing list