454,922 Members | 1,185 Online
Need help? Post your question and get tips & solutions from a community of 454,922 IT Pros & Developers. It's quick & easy.

# Result of sin function differs?

 P: n/a Hello all. I was doing some kind of development and in the test file I have something like this: ///// Test File ///// double x = sin(45); The output for that statement is: ///// Output Test File ///// 0.707107 Unfortunately the output in my system differs from the one in the test file. I run the following example in my system: #include #include using namespace std; int main() { cout << sin(45) << endl; // prints 0.850904 return 0; } The example above prints 0.850904 in my system. In addition to that, my calculator says sin(45) is 0.707107, while calculator at google says that it is 0.850904. I am just curious if I am doing something wrong. Thanks a lot. Mar 24 '07 #1
8 Replies

 P: n/a sin(45 degree) is approximately 0.707107, sin(45 in radian) is approximately 0.850904. My 2 cents. Stephen Wong @ Hong Kong On Sat, 24 Mar 2007, asd wrote: Hello all. I was doing some kind of development and in the test file I have something like this: ///// Test File ///// double x = sin(45); The output for that statement is: ///// Output Test File ///// 0.707107 Unfortunately the output in my system differs from the one in the test file. I run the following example in my system: #include #include using namespace std; int main() { cout << sin(45) << endl; // prints 0.850904 return 0; } The example above prints 0.850904 in my system. In addition to that, my calculator says sin(45) is 0.707107, while calculator at google says that it is 0.850904. I am just curious if I am doing something wrong. Thanks a lot. Mar 24 '07 #2

 P: n/a asd wrote: Hello all. I was doing some kind of development and in the test file I have something like this: ///// Test File ///// double x = sin(45); The output for that statement is: ///// Output Test File ///// 0.707107 Unfortunately the output in my system differs from the one in the test file. I run the following example in my system: #include #include using namespace std; int main() { cout << sin(45) << endl; // prints 0.850904 return 0; } The example above prints 0.850904 in my system. In addition to that, my calculator says sin(45) is 0.707107, while calculator at google says that it is 0.850904. You are confusing different ways of measuring angles. A half of a right angle can be specified as 45 deg or as Pi/8 rad. In the above computations, the number 45 sometimes is interpreted as deg and sometimes as rad. Best Kai-Uwe Bux Mar 24 '07 #3

 P: n/a "asd" #include using namespace std; int main() { cout << sin(45) << endl; // prints 0.850904 return 0; } The example above prints 0.850904 in my system. In addition to that, my calculator says sin(45) is 0.707107, while calculator at google says that it is 0.850904. I am just curious if I am doing something wrong. This program should explain. #include #include #include const double pi = 3.1415926; int main() { double degrees = 45.0; // There are 2 pi radians in a circle. // There are 360 degrees in a circle. double radians = ( 2.0*pi) / 360.0 * degrees; // std::sin expects input as radians std::cout << std::sin( radians ) << "\n"; std::string wait; std::getline( std::cin, wait ); } Mar 24 '07 #4

 P: n/a Thank you so much for all of your answers. Now I am struggling with asin. the test file has: asin(.5); // test output 30 // My output with radian conversion 0.00872676 // without radian conversion 0.523599 I would be glad if you could also help this one. Thanks alot. Mar 24 '07 #5

 P: n/a "asd"

 P: n/a On Sat, 24 Mar 2007 15:31:09 -0700, Jim Langston wrote: "asd" Thank you so much for all of your answers.Now I am struggling with asin.the test file has:asin(.5);// test output30// My output with radian conversion0.00872676// without radian conversion0.523599I would be glad if you could also help this one.Thanks alot. comments for asin in VC++ is: The units of the returned elements are in radians. The return value is a principal value between +pi/2 and -pi/2 that is consistent with the sine value input. No way you're going to get a value of 30 out of that unless you multiply it by some factor. I don't know where they get 30 from. Thank you so much Jim, it worked. Mar 25 '07 #7

 P: n/a Kai-Uwe Bux

 P: n/a Marcus Kwok wrote: Kai-Uwe Bux You are confusing different ways of measuring angles. A half of a rightangle can be specified as 45 deg or as Pi/8 rad. I think you mean Pi/4 rad. Sort of: I think, I meant 2*Pi/8 :-) Thanks Kai-Uwe Bux Mar 26 '07 #9

### This discussion thread is closed

Replies have been disabled for this discussion.