a simple fundamental

long double p;
long double q;

how could i find and store the sum of p & q ? where p and q might have their maximum value.

i hope, i'd get a lot of solutions. :slight_smile:

-sham

When you want to exceed the maximum value of the largest data type that a language has, you have a clear path to follow: invent your own data type. You will need to write routines to convert long double to and from your private data type. You will need to write your own routines to add to elements of your private data type. And you will need to write your own routines to display the values of your private data type.

The bad news: none of this is easy and it probably cannot be written portably. The good news: your private data type can take many forms, so there are indeed a lot of solutions. :smiley:

Hi,

  The simplest way i feel is to do this using two arrays. One for p and another for q. Store each digit of p in one array and of q in another. Add every element from the last index of array and put the sum in the same index of a third result array \(or u can use one of the two arrays itself as the result array\) hold the carry in a temporary variable and use this one to add to the next indices of the array. 


 Well, this in itself is the algorithm. Your way is easy now, i guess. If you are thru with this one, try multiplication of two such numbers

The fastest algorithms for calculating floating point numbers to tens of thousands of digits involve Number Theoretic Transforms. But I thought that only a few special purpose program had been written that use them. But I have just found APFLOAT: A C++ High Performance Arbitrary Precision Arithmetic Package. The claims that the author makes for this package are jaw-dropping:

If you really need highly precise floating point numbers this package may be worth checking out.

You might also try the GNU MultiPrecision library. I don't know how it compares to the APFLOAT: A C++ High Performance Arbitrary Precision Arithmetic Package that Perderabo mentioned, but it might be worth a shot. The site is http://swox.com/gmp/
Good Luck!