[erlang-questions] Bug in erlang?

Hernando Gisinger hgisinger@REDACTED
Sat Jul 13 15:40:15 CEST 2013


Erlang R16B01 (erts-5.10.2) [async-threads:10]

Eshell V5.10.2  (abort with ^G)
1> V = 1.000000e+00.
1.0
2> erlang:display(V).
1.000000e+00
true
3> erlang:display(lists:flatten(io_lib:format("~.2f",[V]))).
"1.00"
true
4> V2 = list_to_float(lists:flatten(io_lib:format("~.2f",[V]))).
1.0
5> erlang:display(V2).
1.000000e+00
true
6>


2013/7/13 Richard Carlsson <carlsson.richard@REDACTED>

> On 2013-07-13 06:33 , Mike Oxford wrote:
>
>>  From the command-line, everything is expected and looks correct...
>>
>> list_to_float(lists:flatten(**io_lib:format("~.2f",[1.**000000e+00]))).
>> 1.00
>>
>> But inside of a .beam'd module...
>>                                              erlang:display(V),
>>
>> erlang:display(lists:flatten(**io_lib:format("~.2f",[V]))),
>>                                              V2 =
>> list_to_float(lists:flatten(**io_lib:format("~.2f",[V]))),
>>                                              erlang:display(V2)
>>
>> gives...
>>
>> 1.000000e+00
>> "1.00"
>> 1.000000e+00
>>
>> So the interesting part is that it (list_to_float) works as expected
>> in the shell, but not in a compiled .beam file.
>>
>
> It's not a problem with list_to_float - I'm sure it gives you the same
> value in both cases. But in the first case you let the shell use its
> default formatting of values to print the float, and in the second case you
> use erlang:display(), which is a debugging function that always prints
> floats in a fixed format. Try using erlang:display() on the result on the
> command line and see, or use io:format(...) instead of erlang:display() to
> show the result in the module.
>
> To convince yourself further, you could use term_to_binary(V) on the
> floats in both cases and print the binary representation (e.g. use
> binary_to_list() and print the byte values).
>
>    /Richard
>
>
> ______________________________**_________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/**listinfo/erlang-questions<http://erlang.org/mailman/listinfo/erlang-questions>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130713/a4bc39e0/attachment.htm>


More information about the erlang-questions mailing list