SourceCode:MathHelper
Back to SourceCode
#MathHelper class
Static variables:
#array of 65536 floats, used as a lookup table for trigonometric calculations
SIN_TABLE = float[65536]
for i in range(65536):
SIN_TABLE[i] = float(Math.sin(2*i*Math.PI/65536))
Static functions:
# float -> float
def sin(f):
return SIN_TABLE(int(f * 10430.378F) & 65535)
# float -> float
def cos(f):
return SIN_TABLE(int(f * 10430.378F + 16384.0F) & 65535)
# number -> float
def sqrt(x):
return float(Math.sqrt(x))
# number -> int
def floor(x):
i = int(x)
if x < i: return i-1
else: return i
# number -> int
def ceiling(x):
i = int(x)
if x > i: return i+1
else: return i
# number^3 -> number
def clamp(x, inf, sup):
if x < inf: return inf
elif x > sup: return sup
else: return x