Math.cos() giving incorrect results?

Hello everyone! I’m sorry to bother you all with this simple question but I can’t get my head around it.
I have this code (see below) which is working fine but math.cos(math.pi/2) is giving a really wierd number. Is this intentional or a bug? According to google and desmos math.cos(math.pi/2) should be 0.

for i = 0,math.pi/2,math.pi/100 do
	print(math.cos(i))
end
print(math.cos(math.pi/2))

These are the (last couple of) results:
image
math.cos(math.pi/2)) suddenly becomes 6.123... instaid of 0.

Is there a way around this without adding if statements or is this a bug?

Note that it says “e-17” at the end, which means “* 10^-17”, which means it is actually a really small number (17 zeros before the 6).

6 Likes