On Fri, 16 Apr 2004, Ashutosh Iddya wrote:
> Hi ,
>
> I am performing an integer count of a particular operation in my program.
> After a sufficiently large value an overflow occurs. At the moment I have
> gone around the problem by declaring it as a double, even that has its
> limits. Is there a method of preventing this overflow or some method of
> recovering from it. Any help in this regard would be greatly appreciated.
If overflow is happening with your data type you could detect it but
preventing it means switching to a different data type. For an integer
data type (long long) is your best bet. If you are only working with
unsigned numbers then (unsigned long long) is your best bet.
You might still get overflow. If this is the case you can try using double
as your data type. Another option is to search the web for "big number C
library". There are libraries you can use for numbers bigger than unsigned
long long.
If you go with the big number library it will probably be slower than
using long long. You might me able to create your own limited big number
library. If you are just counting then you only need addition and some way
of printing the number.
--
Send e-mail to: darrell at cs dot toronto dot edu
Don't send e-mail to