I must admit one of my biggest disappointments with 64-bit support in Delphi was the loss of the 80-bit Extended (as it is now mapped to the 64-bit Double). I’ve also always enjoyed (remember I did do a Maths Degree and even started a PhD in Mathematics) playing with big numbers – you know what is 100! exactly – or even 1000! etc 🙂 As such I have played a few times with implementing known algorithms and even my own designs at times, but didn’t get too far 🙁
After an ESBPCS for VCL customer asked me about this a few weeks ago, I thought I would have a better look at the situation. After much googling, it seemed that GMP Library is quite highly regarded, and that under Windows, the MPIR implementation was used by quite a few commercial applications. Even better I found a Delphi implementation of a wrapper for MPIR: GMP for Delphi – and I was quite pleased with the results.
However, it didn’t include support for 64-bit Delphi – and on reading the documentation for MPIR, special use of NativeInt and NativeUInt would be required to properly utilise the 64-bit support.
So, we decided to do our own Wrapper for MPIR.DLL and include 64-bit support, and like in GMP for Delphi, we would also include record types to better implement the resultant Multi-Precision Integer, Rational and Float. The other differences are that we would document all the routines using the MPIR documents; that we would organise things in Regions; we would develop DUnit Tests; and that we would base things on v2.7.0 (alpha 12) – with the 32-bit and 64-bit DLL built with Visual C++ from VS2013.
We are planning to make the wrapper and associated record types freely available with full source. As well as making them available in ESBDevLib for VCL/FMX – including having special Edit types based on them.
At this stage we have finished the Integer Implementation (still got more DUnit Tests) to add and moving on to the Rationals support.
I must also admit that in the past I didn’t really like this approach as I didn’t like having to include a DLL (after all I’ve been a Delphi Developer since the early Turbo Pascal days) – but it seems to be the best approach 🙂
You can check out a Demo (exe and dll) of some of the Multi-Precision Integer support. This was developed using Delphi XE4 (as this is the base version for our support) and basic Delphi Components at:
http://www.esbconsult.com/esbmpirdemo.zip (just under 3 MB).
And you can use the above to find out that: 100! = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000