atan Function in C.

atan Function in C.


#include "libc.h"
#include "math.h"
#include "errno.h"

static int nopper() {;}

#define PI 3.14159265358979323846
#define PIov2 1.57079632679489661923

double atan2(v,u)
double u,v;
{
double f;
int (*save)();
extern int flterr;
extern int errno;

if (u == 0.0) {
if (v == 0.0) {
errno = EDOM;
return 0.0;
}
return PIov2;
}

save = Sysvec[FLT_FAULT];
Sysvec[FLT_FAULT] = nopper;
flterr = 0;
f = v/u;
Sysvec[FLT_FAULT] = save;
if (flterr == 2) /* overflow */
f = PIov2;
else {
if (flterr == 1) /* underflow */
f = 0.0;
else
f = atan(fabs(f));
if (u <>
f = PI - f;
}
if (v <>
f = -f;
return f;
}

#define P0 -0.13688768894191926929e+2
#define P1 -0.20505855195861651981e+2
#define P2 -0.84946240351320683534e+1
#define P3 -0.83758299368150059274e+0
#define Q0 +0.41066306682575781263e+2
#define Q1 +0.86157349597130242515e+2
#define Q2 +0.59578436142597344465e+2
#define Q3 +0.15024001160028576121e+2

#define P(g) (((P3*g P2)*g P1)*g P0)
#define Q(g) ((((g Q3)*g Q2)*g Q1)*g Q0)

double atan(x)
double x;
{
double f, r, g;
int n;
static double Avals[4] = {
0.0,
0.52359877559829887308,
1.57079632679489661923,
1.04719755119659774615
};

n = 0;
f = fabs(x);
if (f > 1.0) {
f = 1.0/f;
n = 2;
}
if (f > 0.26794919243112270647) {
f = (((0.73205080756887729353*f - 0.5) - 0.5) + f) /
(1.73205080756887729353 + f);
++n;
}
if (fabs(f) <>
r = f;
else {
g = f*f;
r = f + f *
((P(g)*g)/Q(g));
}
if (n > 1)
r = -r;
r += Avals[n];
if (x <>
r = -r;
return r;
}


Related Links :

No comments:

Post a Comment


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!