Version 4 of Bignums Fast and Dirty

Updated 2004-02-06 12:58:27

I had a need the other day for dealing with some really big numbers. Unfortunately, the machine I was using did not have mpexpr installed. Woe is me. Until I came up with the following fast and very dirty workaround. Works on Unix systems and Windows systems with Cygwin:

 proc mpexpr { args } {
  return [ exec echo $args | bc -l ]
 }

 % mpexpr 12342342354564636*94852304570297207525
 1170699616126044020647089347918085900

Is it a cheat? Well, yeah, it's a cheat. But it was darn handy!

CMcC I've written bignum, a quick critcl wrapper for libgmp, giving arbitrary precision ints and floats.

SS I've written tclsbignum, Tcl bindings for sbignum (bignum C implementation). Note that sbignum's C implementation itself is mine, and I'll be happy to release it under the same license as Tcl if it can be useful to put bignums in the core. The lib is not as complete or fast as GPM, but is mostly API compatible and much much more simple, and performances are acceptable. It contains all the useful primitives needed for a programming language (including sqrt, powers, powers mod N, GCD, and so on).

You can find the library at http://www.hping.org/tclsbignum .

Sarnold I have written a little library for multiple precision arithmetics and analysis, in pure Tcl : see MPA. It should be cross-platform, although I have tested it only on Windows with ActiveTcl.

DKF: Time to learn a bit more exec magic:

  proc mpexpr args {
     exec bc -l <<[join $args]
  }

Category Mathematics