[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: not all numbers are treated the same way
- From: Peter Cawley <lua@...>
- Date: Wed, 14 Jul 2010 23:01:50 +0100
On Wed, Jul 14, 2010 at 10:59 PM, Pantelis Kavallieratos
<kavallieratos@gmail.com> wrote:
> one would expect that b=1-(1-a) leads to b=a
> that is not always the case if a is a rational number less than 1
> if a is one of the following 1/3, 1/5, 1/6, 2/6, 1/7, 3/7, 1/9, 3/9, 1/10,
> 2/10, 3/10, 1/11 ...
> b=1-(1-a)
> print(a==b)
> returns false!
Welcome to the world of floating point arithmetic.
> =("%.20f"):format(1/3)
0.33333333333333331000
> =("%.20f"):format(1-(1-1/3))
0.33333333333333326000