Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loss of precision when passing large number in 0.085.1 #2

Open
armoha opened this issue Sep 3, 2018 · 0 comments
Open

Loss of precision when passing large number in 0.085.1 #2

armoha opened this issue Sep 3, 2018 · 0 comments

Comments

@armoha
Copy link

armoha commented Sep 3, 2018

I hate Lua 5.3. Please compiles with compatibility flags for future releases. (including bit32 library)

function log2(x)
    return math.log(x) / math.log(2)
end

function lshift(x, by)  -- bit32 free, Lua 5.2, 5.3 compatible lshift
    if log2(x) + by < 31 then
        return x * 2 ^ by
    else
        return 2147483648 + (x - 2 ^ math.floor(log2(x))) * 2 ^ by
    end
end

function Str2Val(Str, Start)
    local ret = 0
    for i = 0, 3 do
        if string.len(Str) >= Start + i then
            ret = ret + lshift(string.byte(Str, Start+i), 8*i)
        end
    end
    return ret
end

function isname(player, name)
    local p = ParsePlayer(player)
    local t = {}
    t[#t+1] = Memory(0x57EEE8 + 36 * p, AtLeast, lshift(string.byte(name, 1), 24))
    t[#t+1] = Memory(0x57EEE8 + 36 * p, AtMost, lshift(string.byte(name, 1), 24) + 16777215)
    for i = 2, string.len(name), 4 do
        t[#t+1] = Memory(0x57EEE8 + 36 * p + (i+2), Exactly, Str2Val(name, i))
    end
    return t
end

Trigger {
    players = {P1},
    conditions = {
        isname(P1, "ㄱㄴㄷㄹㅁ")
    },
    actions = {
        Comment(" ");
    }
}

-- TEP 0.083.1 works as expected
Trigger { --  
	players = {P1},
	conditions = {
		Memory(0x57EEE8, AtLeast, -1543503872);  -- 0xA400 0000
		Memory(0x57EEE8, AtMost, -1526726657);  -- 0xA4FF FFFF
		Memory(0x57EEEC, Exactly, -1532713823);  -- 0xA4A4 A4A1
		Memory(0x57EEF0, Exactly, -1532386137);  -- 0xA4A9 A4A7
		Memory(0x57EEF4, Exactly, 177);  -- 0xB1
	},
	actions = {
		Comment(" ");
	},
}

-- in TEP 0.085.1, big number loses its precision
Trigger { --  
	players = {P1},
	conditions = {
		Memory(0x57EEE8, AtLeast, 0xA4000000);
		Memory(0x57EEE8, AtMost, 0xA5000000);
		Memory(0x57EEEC, Exactly, 0xA4A4A480);
		Memory(0x57EEF0, Exactly, 0xA4A9A480);
		Memory(0x57EEF4, Exactly, 0x000000B1);
	},
	actions = {
		Comment(" ");
	},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant