

function isNan(v)
    return v ~= v
end


function clamp(v, min, max)
	return math.max(math.min(v, max), min)
end


function lerp(a, b, t)
	local v = a + (b - a) * t
	if a > b then
		return clamp(v, b, a)
	else
		return clamp(v, a, b)
	end
end


function roundMultiple(v, m)
    local a = math.floor(v / m) * m;
    local b = a + m;
  
    if v - a > b - v then
    	return b
    else
    	return a
    end
end


function isBetween(number, bound1, bound2)
    local lowerBound = math.min(bound1, bound2)
    local upperBound = math.max(bound1, bound2)
    
    return number >= lowerBound and number <= upperBound
end


function bitand(a, b)
    local result = 0
    local bitval = 1
    while a > 0 and b > 0 do
        if a % 2 == 1 and b % 2 == 1 then -- test the rightmost bits
            result = result + bitval      -- set the current bit
        end
        bitval = bitval * 2 -- shift left
        a = math.floor(a/2) -- shift right
        b = math.floor(b/2)
    end

    return result
end


function bitor(a, b)
    return a + b
end