# Sine Values Wrong?

### » Thu Oct 16, 2008 3:37 am

I'm not too sure, since I don't know much about sine, but I'm pretty sure that the sine function is returning the wrong values in some cases. For instance, it claims that the sine of 180 is(roughly) 1.2, instead of the 0 it should be. But it gets really weird when I make a sine wave, where it creates a perfect sine wave with no visible problems. I've got a .CAP that will give you the sine for the angle you input for as well as a button that will create a sine wave:

Sine Calculator/Sine Wave

Am I just stupid, or is it actually giving out the wrong sine values?
Moderator
B
115
S
41
G
20
Posts: 1,586
Reputation: 19,196

### » Thu Oct 16, 2008 4:25 am

You are right, it should be zero. But the value it receives is not 1.2, it's much closer to zero: it's about 0.00000000000000012! See the e-016 in the end :D! Actually, I was deceived by this in another situation. Is there a way to show small numbers without scientific notation?
B
3
S
2
G
5
Posts: 263
Reputation: 2,201

### » Thu Oct 16, 2008 5:17 am

[quote="Drasa":jx2llt4q]You are right, it should be zero. But the value it receives is not 1.2, it's much closer to zero: it's about 0.00000000000000012! See the e-016 in the end ! Actually, I was deceived by this in another situation. Is there a way to show small numbers without scientific notation?[/quote:jx2llt4q]

Ah, crazy! I didn't realize the 'e' stood for 'exponent'. Thanks for that. And I agree, there needs to be a way to show a smaller number. I can't seem to find one.
Moderator
B
115
S
41
G
20
Posts: 1,586
Reputation: 19,196

### » Thu Oct 16, 2008 5:21 am

You could use "round" or "int" (int'd floor it).
Last event:
[code:1d78ex69]round(1000*sin(int(EditBox.Text))) / 1000[/code:1d78ex69]
B
6
S
3
G
6
Posts: 219
Reputation: 3,013

### » Thu Oct 16, 2008 1:55 pm

Yeah, computers can't calculate math exactly precisely, because they only used a fixed number of digits. For example, if you do one-third times three using only 6 digits of precision, you get:

0.333333 * 3 = 0.999999

which clearly isn't 1 - which you'd expect to get from multiplying a third by three. The same thing is happening, but in binary.
Scirra Founder
B
414
S
245
G
92
Posts: 25,205
Reputation: 200,351

### » Thu Oct 16, 2008 2:06 pm

011011000110111101101100001000000110100100100000011000110110000101101110001000000111010001111001011100000110010100100000011010010110111000100000011000100110100101101110011000010111001001111001

~011100110110111101101100
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
84
S
34
G
41
Posts: 3,032
Reputation: 30,999