Math(s) to large number of significant figures

Firstly, this is a question purely out of academic interest and not something I’m working on.

How would you work on numbers to a very large number of significant figures in Xojo?

I was watching a programme on the history of maths (http://www.bbc.co.uk/programmes/b00dxjls) and wondered how I might ‘race’ the various infinite expressions for Pi against each other to say 100, 1000 or x number of decimal places / significant figures.

I’m sure people must have done stuff like this before in Xojo but my searches were unsuccesful.

you devise your own “datatype”, using a string, or more likely an array of digits to represent your “super number”
but then you also have to devise you own methods for adding, subtracting etc…

Not impossible of course, since it has been done…

If you really wanted to work with such numbers in Xojo then take a look at Bob Delaney’s math plugins. His Decimal plugin allows you to work with numbers whose size is only limited by available memory. You can find it at: Decimal Plugin or go to Delaney dot com to see his full selection of math oriented plugins.

Lovely stuff. Thank you for that Harrie.

[quote=167489:@Dave S]you devise your own “datatype”, using a string, or more likely an array of digits to represent your “super number”
but then you also have to devise you own methods for adding, subtracting etc…

Not impossible of course, since it has been done…[/quote]

I used to fiddle with this sort of thing years ago in 6502 and Z80 assembly - an area where I found BCD (Binary Coded Decimal) really came into it’s own.

Richard, I developed an open source project to do just this with Xojo (pure Xojo, no plugins or externals). I have just pulled the sources because I plan to release some commercial products around them. In my case, I stored floating points numbers in decimal. I used a memory block containing int8 values for the digits, an integer for sign and int64 for exponent.

There are a number of algorithms involved. Fo add and subtract you use algorithms similar to elementary school techniques. Multiply uses FFT multiplication for large numbers. Sine and Cosine you use Taylor series. Logs use arithmetic geometric mean. And so forth.

I have been working on this in my spare time for years.

My plan is to introduce an arbitrary precision calculator on the Mac Apple Store in a couple of months with a precision of one million digits. I am debating on whether to wait for LLVM prior to submission since it will provide a big speed boost. But it could be a bag of pain if the first LLVM release is bug prone. Only time will tell.

By the way, my routines are in many cases faster than the ones in Bob Delaney’s plugins. It’s not that native Xojo is faster or that Bob’s routines are slow but rather the algorithms selected.

I chose to store in decimal for two reasons. First the numbers you store are represented exactly. This is not the case in the majority of implementations since they use a binary representation (binary mantissa and exponent). Second if you store your numbers as decimal converting to a string is real fast, which you need for such things a calculators.

William - thanks for the insights and the best of luck with MAS when you get there.

If you are willing to use a plugin, I recommend Bob Delaney’s excellent FP plugin which allows you to assign any number of significant digits. I use it extensively in my MathScriptor app. It even does complex math with arbitrary precision.

link text