lua-users home
lua-l archive

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


On Fri, Aug 9, 2013 at 3:18 PM, Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> wrote:
>> function float_equal(lhs, rhs, epsilon)
>>     return math.abs(lhs - rhs) < epsilon
>> end
>
> As mentioned before, if you have to do this, you need to use *relative* error,
> not absolute error:
>       return math.abs(lhs - rhs) < epsilon*rhs
>
> Floating-poin numbers are not distributed uniformily in their range;
> there's lot of clustering and empty intervals, due to scaling.
>

Ah, whoops, yeah, you're right, I got sloppy there. Really that ought
to be epsilon*math.max(lhs,rhs) even.

/s/ Adam