Arbitrary precision math operations

mpexpr is a Tcl command that evaluates an expression with multiple precision math.

To use this command, a Tcl script or hcitcl must use this before processing:

package require mpexpr
Note: This is only required once per run of the program doing the loading. The extension remains loaded in memory, so that it can be used as many times as required after loading.

mpexpr is based on Tcl's built-in expr command, and shares many similarities with expr. mpexpr concatenates args by adding separator spaces between them. It then evaluates the result as a Tcl expression, and returns the value.

The operators that are permitted in Tcl expressions are a subset of the operators permitted in C expressions. They have the same meaning and precedence as the corresponding C operators. Expressions almost always yield numeric results as integer or floating-point values.

For example, the expression mpexpr 8.2 + 6 evaluates to 14.2.

Tcl expressions differ from C expressions in the way that operands are specified. Tcl expressions support non-numeric operands and string comparisons.

For example:

package require mpexpr arg ?arg arg ... ? 
mpformat formatString ?arg arg ... ? 
global mp_precision 

The global variable mp_precision determines the number of significant digits that are retained during evaluation.

If mp_precision is unset, then 17 digits of precision are used.

The maximum value of mp_precision is 10000. Larger values require increasingly longer run times. Setting mp_precision to an illegal value generates an error.