# RPN Calculator for Commander X16

## Recommended Posts

Here is an RPN calculator in BASIC that is a work-alike to the HP line of calculators of yore. Because it is written in BASIC functionality is easily added.

A small usage doc is included too.

Any suggestions on additional functionality that I should add to the base calculator, (like Pi or e  as constants)? <- this has been added

Anyone know an easy way to calculate ArcSin, ArcCos, and ArcTan?  <edit - This has been managed

Let me know if there are other features you would like.

Edited by waspentalive
Update status - refresh upload files
##### Share on other sites

Oh - an updated version where in I actually added the commented out key monitoring line mentioned in the text file

##### Share on other sites

Arctan is in BASIC V2, as ATN. The others aren't. There's math that can be done using the arctan function and the understanding that the radius is always 1, though.

##### Share on other sites

On 9/29/2022 at 12:52 PM, kelli217 said:

Arctan is in BASIC V2, as ATN. The others aren't. There's math that can be done using the arctan function and the understanding that the radius is always 1, though.

Specifically, if google doesn't lie to me,

Arctan{x/[sqrt(1-x^2)] = arcsin(x)

##### Share on other sites

@BruceMcF  My google Fu confirms : at ps://mathonweb.com/help_ebook/html/algorithms.htm#arcsin

arcsin(x) = atn(x/sqr(1-x^2))   and arccos(x) = atn(sqr(1-x^2)/x)

The C64 manual  Appendix H gives inverse sine as  atn(x/sqr(-x*x+1))  and inverse cosine as atn(x/sqr(-x*x+1)) + pi/2

I am trying both of those for my calculator (even with or without the x*0.017453 to convert from deg to rad)

Unfortunately they are not returning back to the original angle.

sin 45 degrees = .70709

arcsine of (.70709) = .01234  (degrees set so the conversion is being done.)

The last time I worked with this kind of math was in ITT Tech - over 10 years ago. Little rusty.

##### Share on other sites

On 9/29/2022 at 8:32 PM, waspentalive said:

@BruceMcF  My google Fu confirms : at ps://mathonweb.com/help_ebook/html/algorithms.htm#arcsin

arcsin(x) = atn(x/sqr(1-x^2))   and arccos(x) = atn(sqr(1-x^2)/x)

The C64 manual  Appendix H gives inverse sine as  atn(x/sqr(-x*x+1))  and inverse cosine as atn(x/sqr(-x*x+1)) + pi/2

I am trying both of those for my calculator (even with or without the x*0.017453 to convert from deg to rad)

Unfortunately they are not returning back to the original angle.

sin 45 degrees = .70709

arcsine of (.70709) = .01234  (degrees set so the conversion is being done.)

The last time I worked with this kind of math was in ITT Tech - over 10 years ago. Little rusty.

When I do it on my Windows virtual calculator using 0.70711, squared, negated, added one, inverted, times 0.70711 (which is very close to 1), I get an arctan of 45.000261. Be careful you are doing sqrt(1-(x^2)) and not sqrt((1-x)^2).

When I do it by hand in VICE:
X=0.70711
ATN(X/SQR(1-(X*X)))

I get 0.785402716

Edited by BruceMcF
##### Share on other sites

I had taken the inner parens out thinking the rule says do power before multiply before addition... Going to go check - watch this space.

##### Share on other sites

New! Improved - Now does arcsine and arccosine - thanks to @BruceMcF

I had to do some trial and error to get the DEG / RAD conversion going correctly.  Now you can use either angle mode.  I don't think you can mix them however, or you must convert for yourself between calculations.  RAD = DEG * pi / 180

Edited by waspentalive
Missed Arccosine code - added new attachments
##### Share on other sites

Yeah, I have been dealing with some trigonometry in a project I'm currently in the "thinking really hard about it but not yet writing anything down" stage. And the realization came early that the X16's BASIC was slightly lacking in trig functions. All I'm worried about at this point is 'is this project even possible' so I just thought about "soh-cah-toa" and realized that it was doable to work without a full complement of inverse functions. And that's as far as it went.

##### Share on other sites

Well now you can peruse my code for the inverse functions you need and see how to convert them to using degrees if you need that.

The angle mode (degrees or radians) is controlled by the strings "DEG" or "RAD" in A\$

The inverse functions are in line numbers 5150 to 5172

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.