[Coco] Different Computer Give Different Answers to TAN(X)

Melanie and John Mark Mobley johnmarkmelanie at gmail.com
Wed Mar 25 15:37:07 EDT 2020


I have studied how different computers/calculators compute TAN(90 degrees).  Some of my computers only work in radians and I cannot exactly hit 90 degrees.  Ex. PI=ATN(1)*4 : PRINT TAN(90*PI/180).  Some of my calculators use Binary Coded Decimal (BCD) and give different answers than my binary computers.   BCD Ex. ZERO=TAN(89.999)+TAN(90.001).  This will set ZERO to 0.  Binary computer Ex. JUNK=TAN(89.999*PI/180)+TAN(90.001*PI/180).  Between the use of binary (not BCD) and the use of radians the numbers come out different.

TANDY Pocket Computer PC-3 (BCD)
Mode=DEG (not RAD)
DEGREE
TAN(89.999)=  57295.77951
TAN(90.000)= Overflow error
TAN(90.001)= -57295.77951

I like the BCD DEG answer.

TANDY Pocket Computer PC-3 (BCD)
Mode=RAD (not DEG)
RADIAN
TAN(89.999*PI/180)=  57295.77951
TAN(90.000*PI/180)= Overflow error
TAN(90.001*PI/180)= -57295.77951

Tandy Color Computer 2 Emulator (Binary)
Mode=radians (you cannot change the mode)
PI=ATN(1)*4 : REM PI=3.14159266 BUT IT SHOULD BE 3.14159265 
TAN(89.999*PI/180)=  57296.8107 
TAN(90.000*PI/180)= Overflow error
TAN(90.001*PI/180)= -57295.6101

Note that the numbers are different between the two systems.  I could try a different value of PI.  I just tried a different value of PI but it did not work any better.  The formula for Pi works better than PI=3.14159266 or PI=3.14159265.

I tried another computer and it did not give an overflow error for TAN(90*PI/180).

TANDY 102 PORTABLE COMPUTER
Mode=radians (you cannot change the mode)
PI=ATN(1)*4
TAN(89.999*PI/180)=  57295.779667691
TAN(90.000*PI/180)= -15915494309189
TAN(90.001*PI/180)= -57295.779461426
TAN(1.5707963267948)=  15915494309189
TAN(1.5707963267949)= -15915494309189

See no overflow error.

So you see different computers/calculators give different answers.

---

Let's try Linux BC (Basic Calculator) Arbitrary Precision Calculator

scale=30 work the problem out to 30 places past the decimal point
a=arctan
s=sin
c=cos
tan(x)=sin(x)/cos(x)
-l (Dash L) use the math library

Ex: scale=30

bc -l
scale=30
pi=a(1)*4
pi
3.141592653589793238462643383276
s(89.999*pi/180)/c(89.999*pi/180)
57295.779507264556703365572420453592
s(90.000*pi/180)/c(90.000*pi/180)
1000000000000000000000000000000.000000000000000000000000000000
s(90.001*pi/180)/c(90.001*pi/180)
-57295.779507264556703365585551678992

+57295.779507264556703365572420453592
-57295.779507264556703365585551678992
 =========================xxxxxxxxxxxx

The value of scale makes a difference.

Ex: scale=34

bc -l
scale=34
pi=a(1)*4
pi
3.1415926535897932384626433832795028
s(89.999*pi/180)/c(89.999*pi/180)
57295.7795072645567033655767370243654814
s(90.000*pi/180)/c(90.000*pi/180)
Runtime error (func=(main), adr=43): Divide by zero
s(90.001*pi/180)/c(90.001*pi/180)
-57295.7795072645567033655767373526461164

+57295.7795072645567033655767370243654814
-57295.7795072645567033655767373526461164
 ==============================xxxxxxxxxxx

-John Mark Mobley




More information about the Coco mailing list