[erlang-patches] [patch] new float_to_list/2

Serge Aleynikov <>
Wed Jul 18 20:47:26 CEST 2012

On 7/18/2012 5:18 AM, Lukas Larsson wrote:
> However, I would also like the fast functionality to be used by
> float_to_list_1 as well, is possible to do this and stay backwards
> compatible? Hopefully you just have to shift the comma and add e+XX at
> the end of the optimized case and call sys_double_to_chars for the
> unoptimized.

See my comments below regarding 'scientific' option.  Since
float_to_list_2 is a new function I would think that you are questioning
the issue of backward compatibility only in terms of converting
float_to_list_1 to use float_to_list_2 implementation.  However, I think
that this will have adverse performance tax on float_to_list_2, which
will diminish the benefit.  It's been a while however, since I wrote
that patch, perhaps there's a way to retrofit scientific notation
without a performance penalty.

It's more than simple shifting of the comma, since there's also rounding

This case is easy:

4> float_to_list(1.01234).
5> float_to_list(1.01234, [{decimals, 20}]).

This case is a bit more complex (illustration of rounding impact):

7> float_to_list(10123412345.0123451234).
8> float_to_list(10123412345.0123451234, [{decimals, 20}]).

> Also float_to_list(1.0) should return the same thing as
> float_to_list(1.0,[]), otherwise the API will be inconsistent with how
> other such APIs work.

Actually if you trace this subject back there was another request that
the default number of decimals is chosen to be consistent with what
printf() does, so I changed the implementation to accommodate that request:

Eshell V5.9  (abort with ^G)
1> float_to_list(1.0, []).

Which is different from the default of float_to_list/1:

2> float_to_list(1.0).

Maybe one could introduce a 'scientific' option to float_to_list/2, to
use the float_to_list/1 implementation?


> On 24/05/12 16:02, Serge Aleynikov wrote:
>> Henrik,
>> Fetch:    git fetch https://github.com/saleyn/otp/tree/float_to_list_2
>> Diff:    https://github.com/saleyn/otp/compare/float_to_list_2
>> I added the definition for the new BIF to make the type checker happy:
>> https://github.com/saleyn/otp/commit/f9ddbeda5426ca83cda03c06a9860220ea4a22c7
>> Once you do the "otp_build tests", how do you execute all tests suites
>> in $ERL_TOP or if possible only tests in a given SUITE?  I tried the
>> following but all tests fail:
>> [otp/erts/emulator/test]$ ../../../bin/erl -noshell -s test_server_ctrl
>> run_test DIR "." -s erlang halt
>> I did however run individual tests in bif_SUIT:types to make sure my
>> patch didn't break anything.
>> Serge
>> On 5/24/2012 5:17 AM, Henrik Nord wrote:
>>> Hi again.
>>> This test is not passing: emulator/bif_SUIT:types
>>> No type information:
>>> [{erlang,float_to_list,2}]
>>> On 04/21/2012 07:19 AM, Serge Aleynikov wrote:
>>>> git fetch https://github.com/saleyn/otp/tree/float_to_list_2
>> _______________________________________________
>> erlang-patches mailing list
>> http://erlang.org/mailman/listinfo/erlang-patches

More information about the erlang-patches mailing list