On Dec 2, 2016, at 9:39 AM, Bryan Enders <pinebo...@gmail.com> wrote:
String.Chars.to_string/1 is only implemented by default for types that can be represented with unambiguous precision… with the exception of Float. The ambiguity with regards to representing tuples and maps (and by extension structs) would seem to be the primary reason for omitting a default implementation for those types. The same could be said of floats. A programmer attempting to interpolate 1_000.0 into a string might be quite surprised to discover that the string representation is "1.0e3". They might be even more surprised to discover that interpolating 12_123_123_123_123_123_123.0 will be rounded in its representation as "1.2123123123123122e19". The protocol implementation must make formatting assumptions with regards to precision when it comes to floats. I would recommend the eventual deprecation of the default String.Chars implementation for Float.
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/e5d26d6d-9a57-444d-bca2-7a17bce4c79f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
the utility of not having to format the float for interpolation/logging for such a core type is worth keeping the behavior
String.Chars.to_string/1 is only implemented by default for types that can be represented with unambiguous precision… with the exception of Float. The ambiguity with regards to representing tuples and maps (and by extension structs) would seem to be the primary reason for omitting a default implementation for those types. The same could be said of floats. A programmer attempting to interpolate 1_000.0 into a string might be very surprised to discover that the string representation is "1.0E3". They might be even more surprised to discover that interpolating 12_123_123_123_123_123_123.0 will be rounded in its representation as "1.2123123123123122e19". The protocol implementation must make formatting assumptions with regards to precision when it comes to floats. I would recommend the eventual deprecation of the default String.Chars implementation for Float.
--
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-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/a2c0dfa4-97ec-4f97-8953-ce8660d2bedd%40googlegroups.com.
> String.Chars.to_string/1 is only implemented by default for types that can be represented with unambiguous precision… with the exception of Float.A float number can be represented as a string with no ambiguity. There are many papers that explain how to do so quickly and accurately, the earlier and latest I am aware are:
https://lists.nongnu.org/archive/html/gcl-devel/2012-10/pdfkieTlklRzN.pdfWhat is not possible is the opposite: to get a string representing a number and represent that accurately as a float. So the ambiguity in your example is not from when the float is converted to a string but from when we parse the string in your Elixir source code and attempt to represent it as a float.Therefore to_string is behaving as expected.José ValimSkype: jv.ptecFounder and Director of R&D
On Fri, Dec 2, 2016 at 3:33 PM, Bryan Enders <pinebo...@gmail.com> wrote:
String.Chars.to_string/1 is only implemented by default for types that can be represented with unambiguous precision… with the exception of Float. The ambiguity with regards to representing tuples and maps (and by extension structs) would seem to be the primary reason for omitting a default implementation for those types. The same could be said of floats. A programmer attempting to interpolate 1_000.0 into a string might be very surprised to discover that the string representation is "1.0E3". They might be even more surprised to discover that interpolating 12_123_123_123_123_123_123.0 will be rounded in its representation as "1.2123123123123122e19". The protocol implementation must make formatting assumptions with regards to precision when it comes to floats. I would recommend the eventual deprecation of the default String.Chars implementation for Float.
--
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.