views:

79

answers:

2

Nice as the Tcl libraries math::bignum and math::bigfloat are, the middle ground between the two needs to be addressed. Namely, bignums which are in different radices and have a radix point.

At present math::bignum only handles integers (afaict) and math::bigfloat won't let you specify different radices to math::bigfloat::fromstr (ditto).

Does anyone know of a library, for any of the major scripting languages (e.g. Tcl, Perl, Python, Ruby, Lua) or less major ones (newLISP for example), which implements bignums in different radices with handling for radix point?

A: 

I couldn't find any libraries for this, but I haven't looked for long.

But you can work around the problem similar to what you would do if you want 64-bit datatypes, but only 32-bit datatypes are available. With the libraries you already have, you should be able to represent a number in base b like this:

 ABCDEF.GHIJKLMN

can be split to the two bignums ABCDEF and GHIJKLMN. GHIJKLMN in fact is representing GHIJLMN / pow(b, length(GHIJKLMN)) => GHIJKLM / pow(b, 8). Now you can overwrite the operators you need which should be possible for things like +, -, *, /. If you need more things like sqrt, log or pow, this workaround will get too complex and you should really look for a library.

schnaader
A: 

Your best bet is to use GMP (libgmp).

I myself have looked long and hard for a .NET version without luck.

leppie