C programming - Urgent help required

Hi,

I am writing a small 'C' program to add very large floating point numbers. Now the program should be capable of adding the maximum floating point number that is possible on Sun Solaris machine.

Can some let me know whether there is any extra logic that needs to applied for making sure that the program can handle addition of largest floating number that a machine allows.

Thanks,

You might want to read this. But the quick answer is as long as you don't overflow, you're ok.

If you suspect that your variable may overflow, then I suggest you assume it will.
In programming, Murphy's law is a law of nature :slight_smile:
In this case, it would state that 'if a variable _can_ overflow, then there is a 100% chance that it _will_ overflow'

I do not know the actual implementation of floating point under Solaris or other 64 bit OSes, but it would make sense to assume that they are 64 bits in length. This is quite easy to find out, so I assume you will if you don't already know.

Before reading any of this, look for a bignum library, that may have what you need.

If a double is stored in 64 bits, then you could overcome the problem by creating your own 128bit bigfloat

struct bigfloat {
long m; // Mantissa
long e; // Exponent
};

and define the operations you need on bigfloat:

bigfloat bigfloat_add(bigfloat a, bigfloat b)

etc.

This is only one of several approaches, another is to not use float at all, but BCD or even arbitrary length strings.

I don't know what it is that you want to do, if it is some scientific experiment, then just disregard the rest of this.

But in certain applications the use of floating point is illegal!

If I am not mistaken these include safety-critical applications and accounting systems.