Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cosine Function Innacurate? What gives?

Status
Not open for further replies.

wraygun

Programmer
Dec 9, 2001
272
US

Hi there,

Why is it that when I use the following line in qbasic it returns a different value than a scientific calculator?

print cos(18)

The computer returns the value:

.6603167

When I do the equivalent function on a scientific calulator, the result is :

.951056516

I know the latter is correct, and the qbasic result isn't. Can anyone explain this and perhaps offer a suggestion for accurate cosine function in qbasic?

Thanks
Harold
 
qbasic counts the function in radians, scientific calculator in degrees
 
if you set your scientific calculator on the radian mode, it will return the same answer as qbasic, so the qbasic-answer is also correct, but just on a different scale
 
Thanks,

I further found out that to convert degrees to radians,you divide as follows:

degrees /(3.14159265/180) = radians

cosine(radians) in qbasic = cosine(degrees) on a scientific calculator.

Wraygun
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top