Pelles C forum

C language => Beginner questions => Topic started by: buckbuilt03 on July 29, 2011, 03:16:12 AM

Title: Problem performing 'atan'
Post by: buckbuilt03 on July 29, 2011, 03:16:12 AM
Need atan(x/y);  x = 1e3 ohms.  y = 338.63 ohms.  Theta should equal 18.71 degrees.  coming up with decimal.  I even tried this as well....ratio = x/y;  atan(ratio);  theta = (x/y)/tan.  Help please...no debug errors.
Title: Re: Problem performing 'atan'
Post by: MrBcx on July 29, 2011, 04:23:35 AM
Quote from: buckbuilt03 on July 29, 2011, 03:16:12 AM
Need atan(x/y);  x = 1e3 ohms.  y = 338.63 ohms.  Theta should equal 18.71 degrees.  coming up with decimal.  I even tried this as well....ratio = x/y;  atan(ratio);  theta = (x/y)/tan.  Help please...no debug errors.
[/quote

The only way that theta can equal 18.71 degrees is if you arrange things like this (shown in BASIC)

r2d = 57.2958     ' convert radians to degrees

PRINT atn (338.63 / 1e3) * r2d
Title: Re: Problem performing 'atan'
Post by: buckbuilt03 on July 29, 2011, 05:02:02 AM
So what you're saying is that C can't perform a binary trig function without prior conversion??  I know how to convert on paper from repetition of the formula but,..........hmmmmmnnnnn, maybe I've been staring at the monitor too long. 
Thanks man...I'll further research your example,

much obliged,

buck
Title: Re: Problem performing 'atan'
Post by: MrBcx on July 29, 2011, 05:12:56 AM
#include <math.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
printf("% .15G\n",(double)atan(338.63/1e3)*57.2958);
  return 0;
}
Title: Re: Problem performing 'atan'
Post by: Stefan Pendl on July 29, 2011, 06:18:02 PM
In most languages trigonometry is performed in radians, so you need to convert back and forth into degrees.
Title: Re: Problem performing 'atan'
Post by: Bitbeisser on July 29, 2011, 09:26:02 PM
Quote from: Stefan Pendl on July 29, 2011, 06:18:02 PM
In most languages trigonometry is performed in radians, so you need to convert back and forth into degrees.
And the doc/online help clearly state that this is the case for Pelle's C as well:
Quoteatan, atanf, atanl functions

Purpose:
Computes the arc tangent.

Syntax:
float atanf(float x);
double atan(double x);
long double atanl(long double x);

Declared in:
<math.h>

Description:
The function computes the angle whose tangent is x, in the interval [-pi/2, +pi/2] radians.

Returns:
The arc tangent of x.
Ralf