How to Use MixCalc


MixCalc is a rational number calculator. It accepts expressions consisting of any combination of whole numbers, fractions, and mixed numbers and returns a result in the appropriate reduced form. +,-, * and / perform addition, subtraction, multiplication, and division, respectively. Parentheses change the order of operations and nest arbitrarily deep. Several expressions, separated by semicolons, may appear on one line. A carriage return ends a line. MixCalc accepts input from the command line or from a redirected file. An error in the input flushes the current line and resets MixCalc. Start MixCalc by typing mixcalc at the DOS prompt. To do a series of calculations from a text file called examples, type

mixcalc < examples
To save the results of your calculations to a file called results, type

mixcalc < examples > results
An error causes a message to be displayed and halts the redirected session. Several lines of a MixCalc session with some comments follow.

White space is optional except to separate the whole number part from the fraction part of a mixed number.

> 1|2*1|2
1|4
>1|2 * 1|2
1|4
> 2 2|3+1 5|6
4 1|2
Parentheses work just as expected.

> 5 7|9 + 11 2|3 * 3 1|2
46 11|18
> (5 7|9 + 11 2|3) * 3 |2
61 1|18
The fraction bar is not an operator; it has meaning only within a fraction.

> (1/2)|3
Unknown token: |
> 1/2|3
1 1|2
This is acceptable to MixCalc, but might not be what was intended. The above example is "one divided by two-thirds," NOT "one divided by two, divided by 3." One-half over three equals one-sixth:

> (1/2)/3
1|6
End a MixCalc session by hitting control-Z (or control-C). All of the limits of the mixed number package apply to MixCalc. Numbers near the largest prime available to MixCalc are used in some examples to force errors. Here's how two compilers dealt with them.

Microsoft C/C++ 7.0

> 1|15991 + 1|15991
2|15991
> 1|16000 + 1|15991
- integer divide by 0
> 1|16001 + 1|15991
- integer divide by 0

Zortech C/C++ 3.0

> 1|15991 + 1|15991
2|15991
> 1|16000 + 1|15991
1
> 1|16001 + 1|15991
721426102 1879503890|-2113923584
In the first example everything stays within bounds. The numerator becomes 2x15,991 and the denominator 1,5991x15,991. Both fit in longs and have prime factors less than or equal to 15,991. The second example produces the numerator 31,991, which is a prime bigger than the biggest available to MixCalc. Note the denominator, 255,856,000, fits in a long and factors nicely.