print(math.sin(math.pi / 2)) print(math.sin(math.pi)) print(math.sin(3 * math.pi / 2)) print(math.sin(2 * math.pi))
I am learning trigonometry on Khan Academy because I'm not at the age when they teach trig in school. So when I put these values in here is what I get from the console.
1 <--- This value is what I expected
1.2246467991474e-016 <--- I was expecting 0
-1 <--- This value is what I expected
-2.4492935982947e-016 <--- I was expecting 0
Here is what I get from my calculator..
1
0
-1
0
Can someone tell me why this happens in ROBLOX?
You're getting almost zero. That's scientific notation, with an exponent of -16. The first number, written out in full, is 0.00000000000000012246467991474
-- almost zero.
You get that number because math.pi
isn't exact, it's a (very good) approximation. So math.sin(math.pi)
gives you a (very good) approximation of 0
.
Your calculator actually gets a similarly "fuzzy", but because it's meant for humans, it rounds it out a bit when it shows it to you. This isn't acceptable for Lua because unrequested rounding violates the requirements of math set by IEEE.