|
| 25 May 2012 09:32 PM |
I tried typing in:
print(math.sin(math.pi))
And instead of getting the correct answer of zero, I got:
1.2246063538224e-016
But sure enough, I tried:
print(math.sin(math.pi)+.1)
And got:
.1
So why can't it just display 0? |
|
|
| Report Abuse |
|
|
L2000
|
  |
| Joined: 03 Apr 2008 |
| Total Posts: 77448 |
|
|
| 25 May 2012 09:37 PM |
I'm guessing it's due to having something like 0.00000000000000000001.
Since rounding it wouldn't give a correct answer (It would give that it has no value, while it does), it has to give the 1.22...e-016 value. Then, when you add 0.1, it can round down to 0.1 and still have a somewhat accurate answer, so it works.
So, basically, it can't be rounded down to 0. |
|
|
| Report Abuse |
|
|
200AB
|
  |
| Joined: 24 Aug 2010 |
| Total Posts: 1604 |
|
|
| 25 May 2012 09:38 PM |
| My guess is because it's trying to put it in radians. |
|
|
| Report Abuse |
|
|
|
| 25 May 2012 09:42 PM |
Use math.floor
♪ Can you dig it? ♪ |
|
|
| Report Abuse |
|
|
pwnedu46
|
  |
| Joined: 23 May 2009 |
| Total Posts: 7534 |
|
|
| 26 May 2012 12:36 AM |
"+.1"
That part that you added to the end of the conversion will explain it. |
|
|
| Report Abuse |
|
|
pwnedu46
|
  |
| Joined: 23 May 2009 |
| Total Posts: 7534 |
|
|
| 26 May 2012 12:42 AM |
| Sorry, I misread your post. I think it has something to do with the rounding. |
|
|
| Report Abuse |
|
|
3lex33
|
  |
| Joined: 08 Oct 2008 |
| Total Posts: 5220 |
|
|
| 26 May 2012 03:07 AM |
1.2246063538224e-016
e-016 means that that long number(1.2246063538224) is multiplied by (1/(10^16)), which is incredibly small number. I can only guess that roblox follows high math and auto replaces zero with very small number. To fix it, as other said, use math.floor |
|
|
| Report Abuse |
|
|
|
| 26 May 2012 11:54 AM |
Wierd, I tried typing in
print(math.sin(3.14159265))
And I got 0
The big problem is: I am making a calculator, so I can't just take the equation and floor it incase someone did 2-1.5 or something. I tried this:
if ans+1 == 1 then display 0
But apparently,
math.sin(math.pi)+1 ~= 1
So now I have a big problem. Maybe I should use the first 50 digits for pi instead of math.pi. |
|
|
| Report Abuse |
|
|
|
| 26 May 2012 11:58 AM |
| gaghagh. Apparently that method isn't working anymore. |
|
|
| Report Abuse |
|
|