problems with floats?

250 views
Skip to first unread message

Jordi Polo

unread,
Jun 26, 2013, 5:34:14 PM6/26/13
to elixir-l...@googlegroups.com

Hi, 
I am toying around with Elixir and I am getting this:

iex(3)> 1.2
1.19999999999999995559
iex(4)> 1.4
1.39999999999999991118

This is a surprising result.
I do not know if it only happens on particular hardware setups or it is a property of how floats are stored internally in the language or beam.

Devin Torres

unread,
Jun 26, 2013, 5:51:04 PM6/26/13
to elixir-l...@googlegroups.com
This was broken here:


:io_lib.format("~p", [float]) gives the shortest representation of floats. I'm not sure why José changed it.


--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Gustavo Brunoro

unread,
Jun 26, 2013, 5:57:24 PM6/26/13
to elixir-l...@googlegroups.com
Also, 1.2 and 1.4 aren't precisely represented by the IEEE 754 floating point standard. Those are the internal representations of those numbers.


2013/6/26 Jordi Polo <mum...@gmail.com>

--

José Valim

unread,
Jun 27, 2013, 2:51:50 AM6/27/13
to elixir-l...@googlegroups.com
There is a paper that describes how to properly print float numbers:


We just need to implement the solution described there. :)
There is an implementation in OTP which we could use in the meantime:


We shall change it after the pretty printing pull request is merged!


José Valim
Skype: jv.ptec
Founder and Lead Developer
Reply all
Reply to author
Forward
0 new messages