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.
Thanking you.
Ashutosh
Nov 14 '05
25 2724
Dan Pop wrote: In <40************ ***@sun.com> Eric Sosman <Er*********@su n.com> writes:
Grumble wrote: [...] For my information, are there implementations where double is wider than 64 bits? ^^^^^^
VAX H-format floating point had/has 128 bits; I don't recall how they're divided up between exponent and fraction. Also, when I was working with VAXen the C implementations were not able to use H-format.
So, you're providing a non-example. long double would have been the right type for the VAX H_FLOAT type, [...]
Could have been, yes -- except that VAX C predated the
1989 ANSI C Standard and had no `long double' type.
-- Er*********@sun .com
In <40************ ***@sun.com> Eric Sosman <Er*********@su n.com> writes: Dan Pop wrote: In <40************ ***@sun.com> Eric Sosman <Er*********@su n.com> writes:
>Grumble wrote: >> [...] >> For my information, are there implementations where double is wider >> than 64 bits? ^^^^^^ > > VAX H-format floating point had/has 128 bits; I don't recall >how they're divided up between exponent and fraction. Also, >when I was working with VAXen the C implementations were not >able to use H-format.
So, you're providing a non-example. long double would have been the right type for the VAX H_FLOAT type, [...]
Could have been, yes -- except that VAX C predated the 1989 ANSI C Standard and had no `long double' type.
Guess what? VAX C survived the 1989 ANSI C Standard, therefore it could
have used long double for this purpose.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Dan Pop wrote: In <40************ ***@sun.com> Eric Sosman <Er*********@su n.com> writes:
Dan Pop wrote: In <40************ ***@sun.com> Eric Sosman <Er*********@su n.com> writes:
>Grumble wrote: >> [...] >> For my information, are there implementations where double is wider >> than 64 bits? ^^^^^^ > > VAX H-format floating point had/has 128 bits; I don't recall >how they're divided up between exponent and fraction. Also, >when I was working with VAXen the C implementations were not >able to use H-format.
So, you're providing a non-example. long double would have been the right type for the VAX H_FLOAT type, [...]
Could have been, yes -- except that VAX C predated the 1989 ANSI C Standard and had no `long double' type.
Guess what? VAX C survived the 1989 ANSI C Standard, therefore it could have used long double for this purpose.
VAX C "survived," but never adopted the Standard.
Digital presumably felt that getting the pre-Standard
compiler to handle a redefined language risked too much
breakage to existing code.
So Digital continued to "support" VAX C while bringing
out an entirely new "DEC C" compiler, Standard-conforming
(modulo bugs and the usual pettifogging) but not burdened
with the problems of backward compatibility. DEC C, of
course, supported `long double` -- but IIRC it was identical
to plain `double' in all but name, and there was still no
support for VAX H-format.
DEC C also ran on the then-new Alpha machines, where
VAX H-format was not available. But "compatibil ity" doesn't
seem to have been the reason for non-support of H; after
all, DEC C on Alpha had support[*] for IEEE single- and
double-precision floating-point that wasn't available on VAX.
[*] I recall one early version of the DEC C libraries
in which the printf() family couldn't render IEEE
`double' correctly. It seemed that the IEEE numbers
were mis-interpreted as VAX G-format, also 64 bits
but with a different layout ...
-- Er*********@sun .com
In <40************ ***@sun.com> Eric Sosman <Er*********@su n.com> writes: Dan Pop wrote: In <40************ ***@sun.com> Eric Sosman <Er*********@su n.com> writes:
>Dan Pop wrote: >> >> In <40************ ***@sun.com> Eric Sosman <Er*********@su n.com> writes: >> >> >Grumble wrote: >> >> [...] >> >> For my information, are there implementations where double is wider >> >> than 64 bits? ^^^^^^ >> > >> > VAX H-format floating point had/has 128 bits; I don't recall >> >how they're divided up between exponent and fraction. Also, >> >when I was working with VAXen the C implementations were not >> >able to use H-format. >> >> So, you're providing a non-example. long double would have been the >> right type for the VAX H_FLOAT type, [...] > > Could have been, yes -- except that VAX C predated the >1989 ANSI C Standard and had no `long double' type. Guess what? VAX C survived the 1989 ANSI C Standard, therefore it could have used long double for this purpose.
VAX C "survived," but never adopted the Standard.
Never fully adopted the standard. It contained plenty of extensions to
K&R C and I don't remember whether long double was among them.
Digital presumably felt that getting the pre-Standard compiler to handle a redefined language risked too much breakage to existing code.
So Digital continued to "support" VAX C while bringing out an entirely new "DEC C" compiler, Standard-conforming (modulo bugs and the usual pettifogging) but not burdened with the problems of backward compatibility. DEC C, of course, supported `long double` -- but IIRC it was identical to plain `double' in all but name, and there was still no support for VAX H-format.
So, you're confirming yourself that your original reply had exactly zilch
to do with Grumble's question.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
On Sat, 17 Apr 2004 +1000, "Peter Nilsson" <ai***@acay.com .au> wrote: "Ashutosh Iddya" <as************ @news.edu.au> wrote in message news:40******* *************** *@freenews.iine t.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!"); }
unsigned long counter[2] = { 0 };
for( ; ; )
{
if( ++counter[0] || ++counter[1] ) ;
else puts("64+ bit counter overflowed!");
}
On Sat, 17 Apr 2004 12:02:41 +1000, "Peter Nilsson"
<ai***@acay.com .au> wrote: "Arthur J. O'Dwyer" <aj*@nospam.and rew.cmu.edu> wrote in message news:Pi******* *************** *************@u nix48.andrew.cm u.edu... On Sat, 17 Apr 2004, Peter Nilsson wrote: > > "Ashutosh Iddya" <as************ @news.edu.au> wrote... > > > > 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])
ITYM if (!(++counter[0] || ++counter[1]))
Or...
if (++counter[0] == 0 && ++count[1] == 0)
or if( !++counter[0] && !++counter[1] )
? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: John Black |
last post by:
Hi,
If I have many integer calculation in my code, what's the best way to
detect integer overflow?
unsigned int i1 = 0xFFFFFF00, i2 = 0xFFFF;
then in statement unsigned int i3 = i1 + i2; there is overflow and
the result is not what I want. If such sum calculation scatters around
my code, I wonder what's the best way to catch it?
|
by: REH |
last post by:
If the is_modulo field of the numeric_limits class is true for signed
integer types, can I assume that overflow for such types is defined
behavior? If so, is the behavior the same regardless of
implementation?
Also, if the range of an integer type is not symmetrical around zero
(i.e., 2's comp.), is it safe to assume that the extra value(s) is one
the negative side?
Thanks,
|
by: Ashutosh Iddya |
last post by:
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.
Thanking you.
|
by: junky_fellow |
last post by:
Is there any way by which the overflow during addition of two integers
may
be detected ?
eg.
suppose we have three unsigned integers, a ,b, c.
we are doing a check like
if ((a +b) > c)
do something;
|
by: Chris Botha |
last post by:
Hi, I have an UInt32 and want to stick the value into an Integer and get an
Overflow exception, BUT using C# the same value can be casted into an int
and the value is as expected. The Hex value is FFFFFFDB, which should
be -37.
Thanks.
| |
by: Robert Seacord |
last post by:
The CERT/CC has released a beta version of a secure integer library for
the C Programming Language. The library is available for download from
the CERT/CC Secure Coding Initiative web page at:
http://www.cert.org/secure-coding/
The purpose of this library is to provide a collection of utility
functions that can assist software developers in writing C programs that
are free from common integer problems such as integer overflow, integer...
|
by: Freaker85 |
last post by:
Hello,
I am new at programming in C and I am searching a manner to parse a
string into an integer.
I know how to do it in Java, but that doesn't work in C ;o)
I searched the internet but I didn't found it yet.
help please
thank you
Freaker85
|
by: thomas.mertes |
last post by:
Is it possible to use some C or compiler extension to catch
integer overflow?
The situation is as follows:
I use C as target language for compiled Seed7 programs.
For integer computions the C type 'long' is used.
That way native C speed can be reached.
Now I want to experiment with raising a Seed7 exception
(which is emulated with setjmp(), longjmp() in C) for integer
|
by: Chris Becke |
last post by:
I *know* my CPU has opcodes that can do this - when adding (or subtracting) there is a carry flag that can be invoked to make the result essentially 1 bit longer than the data size used in calculations.
When multiplying two numbers, the CPU automatically returns a double width result.
c & c++ give programmers these bloody ridiculous integer types of undetermined size and no really optimal way to even build a variable width number library...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |