|
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 :-)
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.
__________________
PS
All of the above is to be read as '... unless I am wrong'
ENDPS
|