lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On May 8, 2016 9:57 AM, "Christophe Devalland" <christophe.devalland@gmail.com> wrote:
>
> Hi,
> this code :
>
> for i=-0.5,0.5,0.2
> do
>    print(i)
> end
>
> gives me :
>
> -0.5
> -0.3
> -0.1
> 0.1
> 0.3
>
> Why not 0.5 ?
>
> Thanks
>
>

Because 0.2 isn't expressable in any finite floating point binary number. It's an infinite repeating number. The numbers you're seeing aren't exact, they just round to those values.

/s/ Adam