1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-12 10:04:40 +02:00

Round math.sin instead of approximating it

This commit is contained in:
Valansch 2018-09-28 18:42:36 +02:00 committed by GitHub
parent b94f65ba51
commit 646d050dd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,20 +1,11 @@
local tau = 2 * math.pi local _sin = math.sin
local half_pi = math.pi / 2 local _cos = math.cos
math.sin = function(x) math.sin = function(x)
local sign = 1 return math.floor(_sin(x) * 10000000 + 0.5) / 10000000
x = (x / tau * 360) % 360
if x < 0 then
x = - x
sign = - sign
end
if x > 180 then sign = - sign end
x = x % 180
if x == 0 then return 0 end
local a = x * (180 - x)
return sign * 4 * a / (40500 - a)
end end
math.cos = function(x) math.cos = function(x)
return math.sin(x + half_pi) return math.floor(_cos(x) * 10000000 + 0.5) / 10000000
end end