[erlang-questions] Strange float / tuple problem

zxq9 zxq9@REDACTED
Sat Jun 4 06:11:29 CEST 2016


On 2016年6月4日 土曜日 12:58:14 zxq9 wrote:
> On 2016年6月3日 金曜日 23:11:16 Donald Steven wrote:
> >
> > I get:    X: 0.000000   Y: -5.000000
> > 
> > which is correct.
> > 
> > ======
> > 
> > When I make a tuple of them, add them to a list and print them via:    
> > io:format("~nL: ~p~n", [L]),
> > 
> > I get:    {4.440892098500626e-16,-5.0},
> > 
> > 
> > Your thoughts would be very welcome.
> 
> 4.440892098500626e-16 == 0.000000000000000444089209850

Sorry, I used the wrong symbol. It really should be written as:

4.440892098500626e-16 ≒ 0.000000000000000444089209850

These two are not actually equal -- and actually doing strict
comparisons on float values after computation is a recipe for
intense frustration, so avoid it by deriving an approximation
that is "good enough" first, and then comparing that.



More information about the erlang-questions mailing list