Page 2 of 2

Re: Dealing with floats

Posted: Thu Jul 28, 2016 7:13 pm
by Rishavs
my bad, posted the code while i was still playing with it.

Code: Select all

function equals( x, y )

    if math.abs(x) >= 1000 and math.abs(y) >= 1000 then
        eps = 10
    elseif math.abs(x) >= 100 and math.abs(y) >= 100 then
        eps = 5 
    elseif math.abs(x) >= 10 and math.abs(y) >= 10 then
        eps = 1
    else
        eps =  0.1
    end
    
    return math.abs( x - y ) <= ( eps )
end

@pgimeno
Never heard of mantissa. Gonna read it now. Thanks for the heads up.

Re: Dealing with floats

Posted: Thu Jul 28, 2016 9:14 pm
by pgimeno
To put it simply, the mantissa is your number scaled by a power of two, so that it is always between 0.5 and 1.

Re: Dealing with floats

Posted: Thu Jul 28, 2016 10:37 pm
by zorg
pgimeno wrote:To put it simply, the mantissa is your number scaled by a power of two, so that it is always between 0.5 and 1.
That's true only in that function, mantissa by itself has a more expanded meaning. :3