Elixir: Elixir seems to want to display everything in exponential notation.

Created on 21 May 2013  路  4Comments  路  Source: elixir-lang/elixir

I think this was a problem a few releases ago; it appears to have returned. This is a rebuilt Elixir; I did a git pull, make clean, make test.

Erlang R16B (erts-5.10.1) [source] [smp:2:2] [async-threads:10] [hipe] [kernel-poll:false]

Interactive Elixir (0.8.3.dev) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> 17 / 5    
3.39999999999999991118e+00

I did another pull and complete rebuild; the problem appears to have now gone away.

Elixir Bug Discussion

Most helpful comment

We are dropping support for R15 soon so I wouldn't worry about it. It is intentional the representation is skewed in there.

In any case, it is very surprising the behaviour you get on R16B because in my machine and in the build it works fine:

iex(1)> 17/5
3.39999999999999991118

@jdeisenberg can you please try out a few combinations? Like:

:erlang.float_to_binary(17/5, [:compact, { :decimals, 20 }])
:erlang.float_to_binary(17/5, [{ :scientific, 20 }])

What does each of them return? Is there a combination of parameters you can pass that makes it work? Also, which OS are you using?

All 4 comments

I tried bisecting and the problem lies dangerously close to this commit: [45ad425793ab3a7c5dfb66530446e6e3b0bc644d] Improve representation of floats and integers, closes #1021.

I wasn't able to build this particular commit because of R16B dependency, but a few commits after it's already broken.

It's weird that tests pass for you on R16B. I've removed the condition on the release number here and the test failed for me.

1) test_float (Binary.Chars.NumberTest)
     ** (ExUnit.ExpectationError)
                  expected: "1.00000000000000000000e+00"
       to be equal to (==): "1.0"
     at test/elixir/binary/chars_test.exs:55

We are dropping support for R15 soon so I wouldn't worry about it. It is intentional the representation is skewed in there.

In any case, it is very surprising the behaviour you get on R16B because in my machine and in the build it works fine:

iex(1)> 17/5
3.39999999999999991118

@jdeisenberg can you please try out a few combinations? Like:

:erlang.float_to_binary(17/5, [:compact, { :decimals, 20 }])
:erlang.float_to_binary(17/5, [{ :scientific, 20 }])

What does each of them return? Is there a combination of parameters you can pass that makes it work? Also, which OS are you using?

A complete rebuild on Fedora 17 at home (also Fedora 17 on the machine that first exhibited the problem) made the problem go away.I rebuilt with "make clean; make test". Here's what your tests produce, Jose:

iex(3)> :erlang.float_to_binary(17/5, [:compact, { :decimals, 20 }])
"3.39999999999999991118"
iex(4)> :erlang.float_to_binary(17/5, [{ :scientific, 20 }])
"3.39999999999999991118e+00"

I have no idea how the problem occurred.

Ok, I am closing this, if the problem comes back, please let us know!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vothane picture vothane  路  3Comments

ckampfe picture ckampfe  路  3Comments

shadowfacts picture shadowfacts  路  3Comments

ericmj picture ericmj  路  3Comments

sashaafm picture sashaafm  路  3Comments