develooper Front page | perl.perl5.porters | Postings from January 2005

RFC: Math::BigInt Calc vs. FastCalc

Thread Next
January 1, 2005 12:44
RFC: Math::BigInt Calc vs. FastCalc
Message ID:


in a recent discussion with Ed Allen Smith about FastCalc the topic of Calc 
vs. FastCalc came up. See:

Basically, FastCalc is a faster version of Calc because it has some of the 
operations in XS instead in Perl.

The advantage of FastCalc over GMP, Pari etc al is that it is never slower - 
GMP et al. keep the numbers internally in base 2 (instead of base 10) and 
thus some operations can be slower (e.g. everything that looks at a number in 
base ten, like rounding, length() etc)ยด, as well as operations with very 
small numbers).

However, FastCalc shares about 80% of the code with Calc, which now creates a 
maintenance nightmare for me - each update of Calc also needs an copy&paste 
update in FastCalc. And each bugfix that changes the testsuite in BigInt 
needs also a new FastCalc release. Ugh.

OTOH, I wouldn't want to replace Calc in BigInt with FastCalc, because a 
pure-perl implementation is still better on platforms where the XS cannot be 
compiled (lack of compiler f.i.). Having the ability to just copy 
and over and getting them instantly to work is sometimes incredible 

After a long thinking I got an idea:

I could fuse FastCalc into Calc, so that the latter tries to load FastCalc, 
and if it failes, just continues normally. If it works, the FastCalc routines 
replace the Calc ones.


* no changes in at all
* minimal changes in Calc to allow optional loading of FastCalc
* I need no longer to maintain a sepate package, this frees my time for other 
important work (and also avoids that a borken FastCalc package floats around 
because I forgot to test it with the latest BigInt)
* people get (slightly) faster Bigint math by default - Allen reports a factor 
two for his cases - this varies greatly depending on which operations you 
use, of course. However, every bit helps. Right now most people don't know 
that they can install an extra library to get faster math, or they lack the 
tools for this (like under some OS).


* slight bloat for the core - FastCalc.xs must be included (it is, however, 
small compared to and - 11 Kb vs. 130 + 60 Kbyte!)
* testsuite should cover both paths. That will increase the tests quite a bit 
if not done intelligently. Right now you only incure both testsuites if you 
install FastCalc on top of a normal Perl.

Regardless of whether this is done, the actual overhead in BigInt itself must 
still be addressed. A seperate mail from me will deal with ideas on how to do 

Tell me what you think of this.

Best wishes,


- -- 
 Signed on Sat Jan  1 21:27:39 2005 with key 0x93B84C15.
 Visit my photo gallery at
 PGP key on or per email.

 "Five exclamation marks, the sure sign of an insane mind." -- Terry

Version: GnuPG v1.2.4 (GNU/Linux)


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About