Problem performing 'atan'

Started by buckbuilt03, July 29, 2011, 03:16:12 AM

Previous topic - Next topic

buckbuilt03

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.

MrBcx

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
Bcx Basic to C/C++ Translator
https://www.bcxbasiccoders.com

buckbuilt03

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

MrBcx

#include <math.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
printf("% .15G\n",(double)atan(338.63/1e3)*57.2958);
  return 0;
}
Bcx Basic to C/C++ Translator
https://www.bcxbasiccoders.com

Stefan Pendl

In most languages trigonometry is performed in radians, so you need to convert back and forth into degrees.
---
Stefan

Proud member of the UltraDefrag Development Team

Bitbeisser

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