Page 1 of 1

RPN.exe: Floating-point arithmetic operations in Reverse Polish Notation

Posted: 22 Jan 2021 01:14
by Aacini
When floating point operations are required in a Batch file, the possible solutions are limited to just a few options. PowerShell is a common solution, but it is very slow. JScript is more efficient, but it also have some drawbacks. The other possible standard methods to perform non-integer operations in a Batch file have also multiple problems...

Some time ago I wrote an auxiliary program called printf.exe that allows to perform floating point arithmetic operations; however, it is difficult to use...

I want to present now my new RPN.exe program. This application is comprised of several parts that provides different advantages in the same package. In its simplest form, it allows to perform floating point operations in Reverse Polish Notation in a very simple way. For example, to evaluate the algebraic expression (3+4) / (5+6) and store the result in a variable, just type:

Code: Select all

for /F %a in ('rpn 3 4 + 5 6 + /') do set "resul=%a"
The RPN.zip package have several other features, like an interactive mode that allows to practice RPN expressions in a simple way that includes a simple help feature, up to a very simple, but complete and efficient, programming language. You may download this application from my new APAacini.com site. Note that this download site is new, so the system will show a warning about the "low number of times" that RPN.zip file have been downloaded. Just ignore the warning messages.

If you download and use it, I'll appreciate if you post here any opinion or comment about the RPN.exe package.

Enjoy it! :D

Antonio

PS - The RPN package is best suited for young people of about 13-15 years old, that is, for any people capable of use (and program) an electronic calculator. If you know such a people and you want to introduce them to the computer programming world, I suggest you to pass to them a copy of RPN.zip package...

Re: RPN.exe: Floating-point arithmetic operations in Reverse Polish Notation

Posted: 24 Jan 2021 08:45
by jfl
I gave it a try, and it's indeed nice and easy to use for doing calculations at the command prompt. :)

The rpn.exe executable is surprisingly small. Was it all written in assembly language?

The stack-based RPN notation reminds me a lot of the old Forth programming language.
Add support for strings, and you'll be very close to having a Forth interpreter!

Just one minor feature request: When I extracted your executable, my first reflex was to run it with the /? option to get help.
I later understood that you have to type 'rpn help' for that.
I suggest adding "/?", "-?", and "--help" as synonyms, as the first two are the standard help commands for Windows, and the latter is for Unix.

Finally, if you want to store the result in a batch variable at the command prompt, my new $.bat allows simplifying your example to:

Code: Select all

$ result rpn 3 4 + 5 6 + /
Don't you think it's better for convincing 13-15 years old that programming is cool? :wink:

Re: RPN.exe: Floating-point arithmetic operations in Reverse Polish Notation

Posted: 28 Jan 2021 10:10
by Aacini
Yes, the RPN.exe program is entirely written in assembly language. Of course, RPN.exe expressions are similar to Forth and to any stack-based programming language. However, it was designed to be as similar as possible to the Hewlett-Packard ancient stack based calculators. I will follow your recomendation and I will add the /? and -? parameters in the next version to show the help screen.

Did you read the (extensive) manual? I invite you to pay attention to two features unique to RPN.exe program:
  • The management of the IEEE-754 special values described in the user's manual, like Infinites, the NotANumber entity, negative zero, etc. This means that RPN.exe expressions will never produce an error! For example, this calculation:

    Code: Select all

    rpn 4 0 / 1/x
    
    that is equal to inverse of Infinite, gives zero as result, that is the right answer! Isn't it?
  • The management of 80-bits floating point numbers, that allows to enter and display numbers with 19 decimal digits and an exponent of ten above 4000.
I'll appreciate it if you could give any additional comment about this application...

Antonio

Re: RPN.exe: Floating-point arithmetic operations in Reverse Polish Notation

Posted: 18 Feb 2021 18:26
by Aacini
A new version of RPN.exe application is ready! This new version 1.0 includes several changes, some minor, some larger...

- I revised the method used to convert the 80-bits X register into an ASCII string when ENG:p format is given. Although the new method is better, it still may fail with certain values...
- A help screen is now displayed when /? or -? parameter is given.
- STO and RCL operations with no parameters now access LASTx register.
- HMS and HR (HH.MMSSCC to/from decimal hours) conversions have been added.
- I added HEX:# hexadecimal output format to compensate for the errors in ENG:p format. This operation is interesting because it allows to review the internal representation of the value in X register, including Infinities, NaN's and subnormal numbers.
- HPSTACK operation now enables/disables the HP stack emulation mode so just 4 stack registers are managed, the X register is saved in LASTx before all operations, and the T register is duplicated after operations over 2 registers. This is the larger modification completed in this version. I suggest you to read again the chapter 1- "RPN.exe vs. Stack-based calculators" in the new manual where the HP emulation mode is described.

You may download the new RPN.exe version 1.0 from the same link of the first version. There is also a new RPN_SP.exe program with a Spanish language messages version.

Antonio

PS - I invite you to review this thread about RPN.exe application...

Re: RPN.exe: Floating-point arithmetic operations in Reverse Polish Notation

Posted: 23 Mar 2021 20:53
by Aacini
The RPN.exe user's manual is now in Spanish.

El manual de usuario de RPN.exe se encuentra ahora traducido al español en el archivo "Operaciones Aritméticas en RPN.html". Descargue la nueva versión del paquete desde esta liga.

Antonio