NO

Author Topic: Problem performing 'atan'  (Read 3757 times)

buckbuilt03

  • Guest
Problem performing 'atan'
« 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.

Offline MrBcx

  • Global Moderator
  • Member
  • *****
  • Posts: 191
    • Bcx Basic to C/C++ Translator
Re: Problem performing 'atan'
« Reply #1 on: July 29, 2011, 04:23:35 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

  • Guest
Re: Problem performing 'atan'
« Reply #2 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

Offline MrBcx

  • Global Moderator
  • Member
  • *****
  • Posts: 191
    • Bcx Basic to C/C++ Translator
Re: Problem performing 'atan'
« Reply #3 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;
}
Bcx Basic to C/C++ Translator
https://www.BcxBasicCoders.com

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: Problem performing 'atan'
« Reply #4 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.
---
Stefan

Proud member of the UltraDefrag Development Team

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: Problem performing 'atan'
« Reply #5 on: July 29, 2011, 09:26: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:
Quote
atan, 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