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

John Guin johnguin at hotmail.com
Wed Mar 25 17:05:11 EDT 2020


Not surprising - I've spent a few years with floating point math.

This is a good starting point if you want to ramp up on the challenges: https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

the tl;dr is "there are any infinite amount of numbers and computers can only hold a finite subset of them"

John

________________________________
From: Coco <coco-bounces at maltedmedia.com> on behalf of Melanie and John Mark Mobley <johnmarkmelanie at gmail.com>
Sent: Wednesday, March 25, 2020 12:37 PM
To: coco at maltedmedia.com <coco at maltedmedia.com>
Subject: [Coco] Different Computer Give Different Answers to TAN(X)

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



--
Coco mailing list
Coco at maltedmedia.com
https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpairlist5.pair.net%2Fmailman%2Flistinfo%2Fcoco&data=02%7C01%7C%7Cc6efae470ce2417631b208d7d0f3ef2f%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637207618414940523&sdata=vGwo0DLNoJCqhBKs7kaVqW5qVwWRUCQ6%2F8OzE30EXTU%3D&reserved=0


More information about the Coco mailing list