Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Atan function not accurate (?)

Author
Message
Geoff
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Sheffield (U.K.)
Posted: 29th Jun 2009 18:40
num# = 55/50
Print Atan(num#)

When I type the following code, DB gives the answer as 45.
I believe the answer should be 47.7263
What am I doing wrong, please?
Geoff.
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 29th Jun 2009 18:51
It seems that DarkBASIC is rounding the 55/50 operation because both numbers are integers, even though the result is being stored in a float. Try 55.0/50.0 instead.



Diggsey: I have a spine and memory, but one memorable guy says he hates me. What am I?
Geoff
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Sheffield (U.K.)
Posted: 29th Jun 2009 19:02
Thank you for the quick solution.
I can now work on my snooker game prog.
I may be back.
Geoff.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 1st Jul 2009 00:18
When integers are used, DB will always return an integer regardless of the result variable's type. At least one number in your equation must be a float in order to return a float.

[url="http://dbcc.zimnox.com"][/url]
Geoff
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Sheffield (U.K.)
Posted: 1st Jul 2009 13:18
Thank you Phaelax, I think I've got it, now.
Regards, Geoff.

Login to post a reply

Server time is: 2024-11-24 03:25:58
Your offset time is: 2024-11-24 03:25:58