# tan inverse

This is a discussion on tan inverse within the C Programming forums, part of the General Programming Boards category; I have an adjacent and opposite. I think I can use: tan(x) = opposite / adjacent but how do I ...

1. ## tan inverse

I have an adjacent and opposite. I think I can use: tan(x) = opposite / adjacent but how do I get the tangent inverse? Please help! <<snipped email>>

2. Welcome to the forum, dwelliott!

We don't email replies, however. The forum policy is YOU need to post up your attempt at a program code, and THEN we will attempt to answer your specific questions about the problem.

Right here.

I suspect if you Google for "inverse of a tangent", you'll have your answer in short order.

3. The easiest way, I suppose, is to expand the inverse tangent function into a series.

Just using wolfram alpha, you can re-write atan(x) into x - (x^3)/3 + (x^5)/5 - (x^7)/7 + ...

So what you wanna do is, take your opposite over adjacent value and then plug it into that formula I just posted. The more terms the more accurate it is. Also, write an exponent routine because Idt C has one built into it. I think this gives you the answer in radians as well.

4. The inverse tangent is directly computed by atan() in math.h.

Asking for the inverse tangent of x just means that you want a measure (in radians, in C) whose tangent is x. Arc tangent is just another name for this.

5. Hmm... I'm pretty sure math.h's routine would use the expansion, wouldn't it? You easily decide the number of terms to keep based on data type, couldn't you?

Otherwise, don't you have to have a look-up table of values?

6. C99 and POSIX.1-2001 and later provide atan2(y,x), which yields the angle between the positive axis and (x,y), including the quadrant. If x>0, atan2(y,x) = atan(y/x).

Many architectures do have an arctangent function built-in. Using the polynomial is quite rare; something like CORDIC atan2() is very simple and quite efficient, especially if you need to use software emulation for the result type. (If you need the full precision of the result type, you need extended precision for the temporaries, or some other way to correct the least significant bit(s) of the result.)

7. Originally Posted by Nominal Animal
C99 and POSIX.1-2001 and later provide atan2(y,x)
It was specified in C before 1999. It was in C89 and, although I would hesitate to describe something as standard before there was actually a standard, atan2() also existed for a considerable time in the pre-standard C library.

8. Originally Posted by grumpy
It was in C89
Good catch. Even the man page I linked to mentions that (for atan2(), for double argument and result); I should have checked and not relied on my memory!

Originally Posted by grumpy
also existed for a considerable time in the pre-standard C library.
Right. They are also available on some very limited architectures, like GCC with emulated floating-point on ARM, where there is very little available RAM or ROM. The CORDIC implementations of sin, cos, atan and atan2 are simple enough and only need a table of about 64 values for full double support. As only substraction, addition, and bit shifts are needed, it's very easy to implement even for software-emulated numeric types.

CORDIC itself is OLD; the first academic paper is from 1959 (Jack E. Volder, "The CORDIC Trigonometric Computing Technique," IRE Transactions on Electronic Computers, Vol. EC-8, pp.330-334, 1959.

9. Originally Posted by dwelliott
I have an adjacent and opposite. I think I can use: tan(x) = opposite / adjacent but how do I get the tangent inverse? Please help! <<snipped email>>
one nice feature about programing in Linux is the use of man pages. If you are not programming in Linux, then hit up google and do a search for "man math.h" you will find your answer there.

I add this for the simple reason that you can perform this task on many features in C then when you have done so and have some code, post the code here for further detailed help.

There are some great folks in these forums that are very skilled at programming.

10. No need to search; the Linux man-pages project lives at kernel org. There is even a nice list of all library function man pages. Even if the man pages are Linux-oriented, they do mention which standards define the functions, and whether the functions are part of C89 or C99, in the Conforming to section in each man page.

11. Originally Posted by Nominal Animal
No need to search; the Linux man-pages project lives at kernel org. There is even a nice list of all library function man pages. Even if the man pages are Linux-oriented, they do mention which standards define the functions, and whether the functions are part of C89 or C99, in the Conforming to section in each man page.
yup, but that still requires a search to learn. im so new to C that i live by my man pages and getting help from here and other places.