Any kind of arithmetic is impossible in batch files - there are no arithmetic operators in the language. Any wizard will tell you that. I have said that. We were wrong. It is possible, if a bit clumsy.
The key concept is that we are dealing with symbols representing numbers, not with numbers in the abstract. The symbols are characters in the permitted set of characters for all batch operations, namely the characters '0', '1', '2', '3', '4', '5', '6', '7', '8', and '9'. Here they are used as elements in strings, argument variables, environment variables, and especially as elements in the names of argument and environment variables.
My intent is to build an entire, stack oriented, four-function calculator (limited, perhaps to positive integers, as is the code here) to handle up to ten-digit numbers. The modules for this will appear as they are developed, beginning with the simplest: addition of decimal numbers.
Each of the following arithmetic demonstration programs has a main program named TESTfoo.BAT, where foo indicates the arithmetic operator. The syntax for each is the same:
TESTfoo nnn mmm
where nnn and mmm are the two numbers involved. The numbers go
in reasonably logical order.
** Copyright 1995, Ted Davis - all rights reserved **
Input and feedback from readers are welcome. NOTE: the subject of the message must contain the word "batch" for the message to get past the spam filter.
Back to the Table of Contents page
Back to my personal links page - back to my home page