Math function questtion.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alm2009
Forum Newbie
Posts: 7
Joined: Tue Dec 01, 2009 12:30 pm

Math function questtion.

Post by alm2009 »

Hi,
I have sample code listed below
<?php
echo sin(45);
echo "<br/>";
echo cos(45);
?>

When i run the code, I get the following results:

0.85090352453412
0.52532198881773

Here is the problem, I know that Sin(45)=Cos(45)
So what I'm doing wrong here?
Many Thanks
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Math function questtion.

Post by AbraCadaver »

alm2009 wrote:Hi,
I have sample code listed below
<?php
echo sin(45);
echo "<br/>";
echo cos(45);
?>

When i run the code, I get the following results:

0.85090352453412
0.52532198881773

Here is the problem, I know that Sin(45)=Cos(45)
So what I'm doing wrong here?
Many Thanks
Sin(45) NOT EQUAL Cos(45)

Sin(45 deg) EQUAL Cos(45 deg)

And the PHP functions expect radian.

Code: Select all

echo sin(deg2rad(45));
echo cos(deg2rad(45));
-Shawn
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
alm2009
Forum Newbie
Posts: 7
Joined: Tue Dec 01, 2009 12:30 pm

Re: Math function questtion.

Post by alm2009 »

Thanks a lot, I just realized that the trigonometrical function might not use degrees as a default.
cheers
Post Reply