Page 1 of 1
RPN Calculator for Commander X16
Posted: Wed Sep 28, 2022 9:06 pm
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
RPN Calculator for Commander X16
Posted: Wed Sep 28, 2022 9:08 pm
by waspentalive
Oh - an updated version where in I actually added the commented out key monitoring line mentioned in the text file
CALCULATOR
RPN Calculator for Commander X16
Posted: Thu Sep 29, 2022 4:52 pm
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.
RPN Calculator for Commander X16
Posted: Thu Sep 29, 2022 6:47 pm
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)
RPN Calculator for Commander X16
Posted: Fri Sep 30, 2022 12:32 am
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.
RPN Calculator for Commander X16
Posted: Fri Sep 30, 2022 2:23 am
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
RPN Calculator for Commander X16
Posted: Fri Sep 30, 2022 2:59 am
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.
RPN Calculator for Commander X16
Posted: Fri Sep 30, 2022 3:27 am
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
RPN Calculator for Commander X16
Posted: Fri Sep 30, 2022 3:50 am
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.
RPN Calculator for Commander X16
Posted: Fri Sep 30, 2022 4:41 am
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