Page 1 of 1
sin() and cos() functions in v3.8B
Posted: Fri Oct 03, 2003 12:08 pm
by Behnood
please someone check the sin() and cos() functions in ver3.8B
it seems that there is a difference in calculating these functions in new version versus version 3.72
regards
Reza
Posted: Fri Oct 03, 2003 12:10 pm
by LarsG
What difference are you talking about... I'm using them in this game I'm making, and I didn't see any difference when I upgraded til 3.8 (3.79Beta)
-Lars
Posted: Fri Oct 03, 2003 1:18 pm
by dmoc
Me too, sin & cos all over the place and seems ok.
Posted: Fri Oct 03, 2003 6:36 pm
by Behnood
i used this code in my program:
pi4=atan(1)
for direction=0 to 7
x=int(cos(direction*pi4)+.5)
y=int(sin(direction*pi4)+.5)
next direction
here is the result for x in version 3.72 and 3.8b
direction 3.72 3.8b
---------- ------ ------
0 1 1
1 1 1
2 0 0
3 -1 0
4 -1 0
5 -1 0
6 0 0
7 1 1
any idea?!
regards
Reza
Posted: Fri Oct 03, 2003 6:50 pm
by LarsG
I don't know if 3.72 didn't use radian values, but if it didn't, just try multiplying your direction with (3.141593 / 180)...
(probably won't help you, but it's worth a shot..)
-Lars
Posted: Fri Oct 03, 2003 6:53 pm
by Behnood
sure atan() (or arctan()) will return result in radian in all languages.
may be the problem is in the int() function
any idea?
regards
Reza
Posted: Fri Oct 03, 2003 7:08 pm
by LarsG
I can't figure it out.. are you sure you're using the same formula?!
I tried your code, but it returned the 3.8 result as you wrote..
-Lars
Posted: Fri Oct 03, 2003 7:21 pm
by Behnood
what do you mean it returned 3.8 results?!
the problem is diferences between 3.72 results and 3.8 results
direction 0 1 2 3 4 5 6 7
3.72 1 1 0 -1 -1 -1 0 1
3.8 1 1 0 0 0 0 0 1
Posted: Fri Oct 03, 2003 7:43 pm
by LarsG
I got almost the same results as you did in 3.8
one number differs though..
I got the sequence: 1 1 0 0 0 0 1 1
-Lars
Posted: Fri Oct 03, 2003 7:54 pm
by Behnood
ok, but i wrote my program to get results like what i got from v3.72!
why formula return different result in new version?!
Posted: Fri Oct 03, 2003 8:01 pm
by LarsG
Dunno.. maybe ask Fred..
-Lars
Posted: Fri Oct 03, 2003 8:19 pm
by fsw
1.) Make sure you declare floats as floats
when you set:
pi4=ATan(1)
x=Int(Cos(direction*pi4) + 0.5)
result: 11000011
but
when you set:
pi4.f=ATan(1)
x=Int(Cos(direction*pi4) + 0.5)
result: 11000001
2.) Use:
x=Round(Cos(direction*pi4) + 0.5, 0)
instead of
x=Int(Cos(direction*pi4) + 0.5)
to get the same result as v3.72
The Handbook says:
Int()
Returns the interger part of a float number.
Example
Result = Int(10.565) ; Will return '10'
...
so if you look at the float values the v3.72 INT(x) command didn't work right...
Posted: Sat Oct 04, 2003 3:18 pm
by Behnood
so there was a bug in int function (v3.72) and nothing wrong with 3.8 beta about this function, yes?
thanks
regards
Reza
Posted: Sun Oct 05, 2003 2:48 am
by fsw
You're welcome
Hope that now all works well.
Posted: Sun Oct 05, 2003 9:42 am
by Behnood
yes, those are ok now.
thanks