Hey everyone,
I just wanted to share my script which aims to enhance arithmetic operations in batch without the use of VBscript. With this, you can do all the standard arithmetic math but with larger integers and floating-point numbers. It also takes care of evaluating all inputs, contains enhanced number comparison and evaluation functions, gives you full control over the precision of float outputs, and more!
The script takes full advantage of macros to help with the additional overhead. While the maximum number of digits across operations is limited compared to the other solutions I've seen, it appears to be much faster and I believe the fixed size should be more than enough for regular tasks. In addition, because this is a pure batch solution, it should work fine on older Windows systems. So far I've tested it on Windows XP Professional 32-bit and Windows 7 Ultimate 64-bit.
Keep in mind that this is only my second major batch script so forgive me if my code appears a bit amateurish. Despite my inexperience, I tried my best to design the script to be fast and easy to read and use.
I've also included two additional scripts. The arithmetic_examples.bat file contains examples for all the user macros in arithmetic.bat as well as some useful tips to take full advantage of the script. The other one, benchmark.bat, is a simple but powerful script designed for benchmarking other scripts and applications. It uses arithmetic.bat for time calculations and is a great showcase on how you can easily incorporate it in your own scripts.
If you find any of these useful, encounter bugs or have any suggestions, by all means let me know!
*** UPDATES ***
I recently completed another script that utilized both arithmetic.bat and benchmark.bat and found some issues.
arithmetic.bat v1.1 (2018-1-24)
* Fixed bug where user macros can't be called after changing directory.
* Fixed other minor bugs and made some tweaks.
* Added four new user macros @enableResultMes, @disableResultMes, @enablePauseOnErrors and @disablePauseOnErrors.
benchmark.bat v1.1 (2018-1-24)
* Fixed bug where user macros can't be called after changing directory.
* Script will now run even if arithmetic.bat is initialized from a different location.
Ron
Script for large integer and floating-point arithmetic and comparison using macros (updated to v1.1)
Moderator: DosItHelp
Script for large integer and floating-point arithmetic and comparison using macros (updated to v1.1)
- Attachments
-
- arithmetic_v1.1.zip
- (8.71 KiB) Downloaded 417 times
-
- arithmetic_examples_v1.1.zip
- (2.75 KiB) Downloaded 382 times
-
- benchmark_v1.1.zip
- (4.47 KiB) Downloaded 413 times
Last edited by Ron on 24 Jan 2018 13:39, edited 1 time in total.
Re: Script for large integer and floating-point arithmetic and comparison using macros
For those of us who have no experience using macros, how would I do this from the command line?
I typed arithmetic init
then addi 2 2
or add 2 2
Neither were recognized as an internal command. When I type SET I see lots
of lines related to your arithmetic script.
Thanks.
I typed arithmetic init
then addi 2 2
or add 2 2
Neither were recognized as an internal command. When I type SET I see lots
of lines related to your arithmetic script.
Thanks.
Re: Script for large integer and floating-point arithmetic and comparison using macros
Encapsulate the macro with percent signs as follows
%@addi% 3 5
%@addf% 31.881 52.38 res (saves result to variable 'res')
%@multf% 82.7 24.556
%@compi% 594 LSS 3345
These and everything shown in arithmetic_examples.bat can be done in CMD and in a script file. Normally you would have to call the file directly and then the function but I realized that was too cumbersome so I incorporated the calls in a macro to simplify things.
Ron
%@addi% 3 5
%@addf% 31.881 52.38 res (saves result to variable 'res')
%@multf% 82.7 24.556
%@compi% 594 LSS 3345
These and everything shown in arithmetic_examples.bat can be done in CMD and in a script file. Normally you would have to call the file directly and then the function but I realized that was too cumbersome so I incorporated the calls in a macro to simplify things.
Ron