Dealing with floats

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Rishavs
Party member
Posts: 103
Joined: Sat Oct 17, 2009 5:29 am
Contact:

Re: Dealing with floats

Post 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.
User avatar
pgimeno
Party member
Posts: 3641
Joined: Sun Oct 18, 2015 2:58 pm

Re: Dealing with floats

Post 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.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Dealing with floats

Post 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
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest