RPN Calculator for Commander X16

Talk about your programs in progress. Discuss how to implement features, etc.
Forum rules
This section is for testing Commander X16 programs and programs related to the CX16 for other platforms (compilers, data conversion tools, etc.)

Feel free to post works in progress, test builds, prototypes, and tech demos.

Finished works go in the Downloads category. Don't forget to add a hashtag (#) and the version number your program was meant to run on. (ie: #R41).
Post Reply
waspentalive
Posts: 24
Joined: Fri Jun 17, 2022 5:51 pm
Location: Sacramento, CA

RPN Calculator for Commander X16

Post by waspentalive »


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

 

I am re-uploading the latest version here. The Text file is a mini-manual. The "CALCULATOR" is a tokenized basic program.

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

 
Calculator.txt
CALCULATOR
waspentalive
Posts: 24
Joined: Fri Jun 17, 2022 5:51 pm
Location: Sacramento, CA

RPN Calculator for Commander X16

Post by waspentalive »


Oh - an updated version where in I actually added the commented out key monitoring line mentioned in the text file
CALCULATOR
kelli217
Posts: 517
Joined: Sun Jul 05, 2020 11:27 pm

RPN Calculator for Commander X16

Post by kelli217 »


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.

BruceMcF
Posts: 1336
Joined: Fri Jul 03, 2020 4:27 am

RPN Calculator for Commander X16

Post by BruceMcF »



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)

waspentalive
Posts: 24
Joined: Fri Jun 17, 2022 5:51 pm
Location: Sacramento, CA

RPN Calculator for Commander X16

Post by waspentalive »


@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.

BruceMcF
Posts: 1336
Joined: Fri Jul 03, 2020 4:27 am

RPN Calculator for Commander X16

Post by BruceMcF »



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

 

waspentalive
Posts: 24
Joined: Fri Jun 17, 2022 5:51 pm
Location: Sacramento, CA

RPN Calculator for Commander X16

Post by waspentalive »


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

 

waspentalive
Posts: 24
Joined: Fri Jun 17, 2022 5:51 pm
Location: Sacramento, CA

RPN Calculator for Commander X16

Post by waspentalive »


 

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

Edit again - re-uploading files as I had not actually done arc-cosine yet.
CALCULATOR
Calculator.txt
kelli217
Posts: 517
Joined: Sun Jul 05, 2020 11:27 pm

RPN Calculator for Commander X16

Post by kelli217 »


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.

waspentalive
Posts: 24
Joined: Fri Jun 17, 2022 5:51 pm
Location: Sacramento, CA

RPN Calculator for Commander X16

Post by waspentalive »


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

Post Reply