float_to_list vs io:format ~w

Eckard Brauer eckard.brauer@REDACTED
Mon Jun 28 12:50:44 CEST 2021

0.2 (decimal) is an infinite (but periodic, in this case) as a binary
number, and the internal representation is a binary one. And
representing an _exact_ infinite with a finite number of positions is
impossible, as it's easy to understand.

So for having exact representations, an alternative internal number
representation would be needed, beside the binary representations
already existing (e.g. BCD numbers). But even irrationals (pi, e,...)
wouldn't be represented exactly by that... so I fear we're still looking
for the optimum.


Am Mon, 28 Jun 2021 18:31:44 +0900
schrieb zxq9 <zxq9@REDACTED>:

> Floats are white lies but useful engineering approximations and reals 
> are a fake contrivance that imagines the universe to be infinitely
> smooth.
> I'm being silly above (but seriously, reals are fake), but the bottom 
> line is it really isn't a simple thing to pick a "right"
> representation and I imagine the difference comes down to use case:
> formatting data for humans VS exporting data to other machines.
> Humans:
> "Practically speaking, the user intends 10.2 to be 10.2 even though
> that is an impossible number to represent as a float."
> Machines:
> "The closest string representation of this value is literally X so it 
> will be represented in full."
> My question is: What is the algorithm for the 10.2 -> "10.2" 
> representation? Is there some rounding rule? This is probably all 
> covered in some part of IEEE 754 I've never gotten around to reading.
> -Craig
> On 2021/06/28 18:23, Viktor Söderqvist wrote:
>  [...]  

More information about the erlang-questions mailing list