Working with Large Numbers in Tcl and NS
When tracing queue statistics for a long simulation, you may
encounter the Tcl error "integer value too large to represent". Mpexpr is
an add-on to Tcl that allows the use of arbitrarily large numbers.
Preparing Tcl
- Grab mpexpr-1.0.tar.gz
- Read the README
- Change ns-allinone/install to configure Tcl with --enable-shared instead
of --disable-shared
- Re-run ns-allinone/install
Installing mpexpr
- Unpack mpexpr-1.0.tar.gz
- Read over mpexpr/INSTALL (This page is just a summary.)
- Run configure in mpexpr/unix/ with the same --prefix and --exec-prefix
flags as when Tcl was configured (probably the directory where ns-allinone
lives)
- Edit mpexpr/unix/Makefile so that BYTE_ORDER=LITTLE_ENDIAN
- Run make in mpexpr/unix/
- Run make test in mpexpr/unix/
- Run make install in mpexpr/unix/
Using mpexpr
- In the Tcl scripts where you want to use mpexpr, include the line
package require Mpexpr
- Set the variable mp_precision to the maximum number of digits to the
right of the decimal (more digits than you need slow down execution)
- Use mpexpr in place of expr and mpformat in place of format whenever you
need very large numbers or very large amounts of precision
Other
DiRT documents
Author: Michele Weigle