View Full Version : usage of atan, atan2, asin, acos
vcmohan
25th February 2006, 13:04
I have a problem with these instructions. I use MSVC++ 6.0. The output I am getting from atan(x) for any positive value of x is either 0 or 1. Same is true for atan2(x,y) for any positive values of x or y. For negative values also not different except that some values I get are -1. I expect a double theta = tan(1.0) to give a value of pi/4.
Is this something to do with my copy of VC++ or did any one else experience this problem. Pl help me.
neuron2
25th February 2006, 18:39
I expect a double theta = tan(1.0) to give a value of pi/4. I assume you meant atan(1.0). Compile and run this:
// Calculate atan()
// arguments: 1.0
#include <math.h>
#include <stdio.h>
#include <errno.h>
int main( int ac, char* av[] )
{
double x, y;
if (ac != 2)
{
fprintf( stderr, "Usage: %s <x>\n", av[0] );
return 0;
}
x = atof(av[1]);
y = atan(x);
printf( "Arctangent of %f: %f\n", x, y );
return 0;
} The output is:
Arctangent of 1.000000: 0.785398 (which is pi/4).
vcmohan
26th February 2006, 04:04
Thanks for the reply. I realised that I am getting those results due to a misplaced bracket. Now I am getting correct results. Sorry for posting this.
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.