Re: integer overflow
From: Peter Nilsson (airia_at_acay.com.au)
Date: 04/17/04
- Next message: Allin Cottrell: "Re: Problem with simpe unixshell attempt"
- Previous message: Ioannis Vranos: "Re: long long"
- In reply to: Ashutosh Iddya: "integer overflow"
- Next in thread: Arthur J. O'Dwyer: "Re: integer overflow"
- Reply: Arthur J. O'Dwyer: "Re: integer overflow"
- Reply: RoSsIaCrIiLoIA: "Re: integer overflow"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 17 Apr 2004 11:27:40 +1000
"Ashutosh Iddya" <ashutosh.iddya@news.edu.au> wrote in message
news:407fba3a$0$16582$5a62ac22@freenews.iinet.net.au...
> 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.
unsigned long counter[2] = { 0 };
for (;;)
{
if (++counter[0] && ++counter[1])
puts("64+ bit counter overflowed!");
}
This is trivially extendable to as much precision as you want. But if you need a counter
bigger than a minimum of 64-bits, then I'd love to know what machine you're using and
where I can pick one up!
-- Peter
- Next message: Allin Cottrell: "Re: Problem with simpe unixshell attempt"
- Previous message: Ioannis Vranos: "Re: long long"
- In reply to: Ashutosh Iddya: "integer overflow"
- Next in thread: Arthur J. O'Dwyer: "Re: integer overflow"
- Reply: Arthur J. O'Dwyer: "Re: integer overflow"
- Reply: RoSsIaCrIiLoIA: "Re: integer overflow"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|