Showing posts with label arc tangent. Show all posts
Showing posts with label arc tangent. Show all posts

Saturday, February 21, 2026

HP 12C: Quickly Approximating Arc Tangent

HP 12C: Quickly Approximating Arc Tangent



The HP 12C does not have trigonometric functions. Various sources list on how such functions are be approximated with varying degrees of accuracy. Today’s blog will feature a quick approximation, using only a 14 step function for the arc tangent (inverse tangent) function.


Formula Used in Approximation

(see Source)


arctan(x) ≈ x ÷ (1 + 0.28125 * x²) = x ÷ (1 + 9 * x² ÷ 32)


Best for -1 ≤ x ≤ 1


Maximum absolute error of 0.0049 radians, approximately 0.28°. The error gets worse outside these ranges. The program rounds the result to 2 decimal places. The angle is returned in radians.


HP 12C Program: Arc-tangent Approximations


FIX 2

01

42, 2

Program start

ENTER

02

36


ENTER

03

36


×

04

20


9

05

9


×

06

20


3

07

3


2

08

2


÷

09

10


1

10

1


+

11

40


÷

12

10


RND

13

42, 14

Round result to 2 decimal places

GTO 00

14

43, 33, 00

Program end

Examples


x = 0.1. Result: 0.10

x = 0.3. Result: 0.29

x = 0.5. Result: 0.47


Source


Sreeraman Rajan, Sichun Wang, Rober Inkol, and Alain Joyal. “Efficient Approximations for the Arctangent Function” IEEE Signal Processing Magazine. May 2006.


Eddie


All original content copyright, © 2011-2026. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.



Monday, November 25, 2013

ATAN2 using tan^-1 and angle/ARG (Various Calculators)

ATAN2

The function atan2(y,x) is defined as:

atan2(y,x) = tan^-1 (y/x) with respect to the quadrant the point (x, y) is in. In case you didn't know, with respect to point (x, y):

(x, y) is in Quadrant I if x > 0 and y > 0
(x, y) is in Quadrant II if x < 0 and y > 0
(x, y) is in Quadrant III if x < 0 and y < 0
(x, y) is in Quadrant IV if x > 0 and y < 0

Visually:

This is different from the two common calculator functions used to find the arctangent: Arctangent and Argument.

The Arctangent Function

TI and Casio Calculators*: tan^-1(y/x)
Hewlett Packard Calculators*: atan (y/x)

* The majority of them

Range (Output): -90° to 90°, -π/2 to π/2 radians

How to use Arctangent to get atan(y,x)

If the point is in quadrant I:
Use atan(y/x)

If the point is in quadrant II or III:
Use atan(y/x) + 180° in degrees mode
Use atan(y/x) + π in radians mode

If the point is in quadrant IV:
Use atan(y/x) + 360° in degrees mode
Use atan(y/x) + 2*π in radians mode

Special cases have to be used x or y is equal to 0:

If x=0 and y<0, the angle is 270° (3*π/2 radians)
If x=0 and y>0, the angle is 90° (π/2 radians)
If y=0 and x<0, the angle is 180° (π radians)
If y=0 and x>0, the angle is 360° or 0° (2*π or 0 radians)


The Argument Function

The complex number x + yi is used.

TI Calculators: angle(x + y*i)
Casio and Hewlett Packard Calculators: ARG(x + y*i)

Range: -180° to 180°, -π to π radians

How to use the Argument function to get atan2(y,x)

This is a great way to get atan2, which cleverly makes the use of complex numbers. In addition, there are a lot fewer things to remember:

If y≥0 (Quadrants I and II):
Use ARG(x+yi)*

(*The angle function if you are using a TI calculator)

If y<0 (Quadrants III and IV):
Use ARG(x+yi) + 360° for degrees mode
Use ARG(x+yi) + 2*π for radians mode


I hope this tip is helpful. Happy Thanksgiving and I am very thankful for all who have read, followed, and supported my blog over the last two years.

Eddie

This blog is property of Edward Shore. 2013

Classic RPN Stack Operations

  Classic RPN Stack Operations Starting Stack: T:  d Z:  c Y:  b X:  a OVER :   Copies b to the Z and X stacks, while leaving ...