473,739 Members | 5,405 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cheking overflow

there is a function f
i need to check whether the value returned by f is positive or
negative
but if the number overflows and shows negative even when actually it
is positive
how can i check that the number is really negative?

Aug 16 '07 #1
7 1899
quarkcode wrote, On 16/08/07 11:26:
there is a function f
i need to check whether the value returned by f is positive or
negative
but if the number overflows and shows negative even when actually it
is positive
how can i check that the number is really negative?
You will have to check for overflow in function f and return (or
otherwise make available) the status. Note that you generally need to
check whether an operation will overflow *before* doing the operation
rather than after, unsigned integer types being the exception.
--
Flash Gordon
Aug 16 '07 #2
quarkcode wrote:
>
there is a function f. i need to check whether the value returned
by f is positive or negative but if the number overflows and shows
negative even when actually it is positive how can i check that
the number is really negative?
You can't. Once the overflow occurs all operation is classified as
"undefined behaviour". You have to detect the overflow before it
actually occurs. How to do this depends on the types and codes
involved.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>
--
Posted via a free Usenet account from http://www.teranews.com

Aug 16 '07 #3
On 16 Aug, 11:26, quarkcode <shaunak...@gma il.comwrote:
there is a function f
i need to check whether the value returned by f is positive or
negative
but if the number overflows and shows negative even when actually it
is positive
how can i check that the number is really negative?
One possibility might be for f to use a wider type internally, one
which is big enough that your routine won't overflow it. You can then
see whether the result is within the range of values you are able to
return from f - if it is not, then f could flag up an error somehow,
or you could replace the actual value with an artificial one (eg
INT_MAX).

I'll leave the details to you...

Paul.

Aug 16 '07 #4
quarkcode <sh********@gma il.comwrote:
# there is a function f
# i need to check whether the value returned by f is positive or
# negative
# but if the number overflows and shows negative even when actually it
# is positive
# how can i check that the number is really negative?

ANSI C doesn't require overflow detection. You would have used to
system dependent facilities, if they exist, though I've never heard
of a C compiler that can report integer overflow.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Wow. A sailboat.
Aug 16 '07 #5
On Aug 16, 6:32 am, CBFalconer <cbfalco...@yah oo.comwrote:
quarkcode wrote:
there is a function f. i need to check whether the value returned
by f is positive or negative but if the number overflows and shows
negative even when actually it is positive how can i check that
the number is really negative?

You can't. Once the overflow occurs all operation is classified as
"undefined behaviour". You have to detect the overflow before it
actually occurs. How to do this depends on the types and codes
involved.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>

--
Posted via a free Usenet account fromhttp://www.teranews.co m
suppose i calculate f(x),the function being long enough and i
calculate using link list.Can i know at what point dring the
calculation is it going to overflow
if i want to trap overflow before it actually happens

Aug 20 '07 #6
quarkcode wrote:
>
On Aug 16, 6:32 am, CBFalconer <cbfalco...@yah oo.comwrote:
quarkcode wrote:
there is a function f. i need to check whether the value returned
by f is positive or negative but if the number overflows and shows
negative even when actually it is positive how can i check that
the number is really negative?
You can't. Once the overflow occurs all operation is classified as
"undefined behaviour". You have to detect the overflow before it
actually occurs. How to do this depends on the types and codes
involved.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>

--
Posted via a free Usenet account fromhttp://www.teranews.co m

suppose i calculate f(x),the function being long enough and i
calculate using link list.Can i know at what point dring the
calculation is it going to overflow
if i want to trap overflow before it actually happens
What is your procedure for "calculate using link list"?

What kind of operators and operands are invloved in
"calculate using link list"?

What's involved in "calculate using link list"
is pretty nebulous from my point of view.

--
pete
Aug 20 '07 #7
quarkcode wrote:
CBFalconer <cbfalco...@yah oo.comwrote:
>quarkcode wrote:
>>there is a function f. i need to check whether the value returned
by f is positive or negative but if the number overflows and shows
negative even when actually it is positive how can i check that
the number is really negative?

You can't. Once the overflow occurs all operation is classified as
"undefined behaviour". You have to detect the overflow before it
actually occurs. How to do this depends on the types and codes
involved.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>

--
Posted via a free Usenet account fromhttp://www.teranews.co m

suppose i calculate f(x),the function being long enough and i
calculate using link list.Can i know at what point dring the
calculation is it going to overflow
if i want to trap overflow before it actually happens
Why is my sig, and my ISPs added sig, still present here? They are
plainly marked with sig markers. Are you crippled in some manner
that prevents operation of the selection and deletion keys? Is
this the same reason you fail to add blanks between sentences, and
fail to capitalize the personal pronoun 'I'?

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Aug 20 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
4831
by: Andrew Fedoniouk | last post by:
I have a simple test document which produce the following in Mozilla and Opera: http://terrainformatica.com/w3/p2/problem1.png Internet Explorer behaves as per recommendation (I guess) Did I miss something and width of paragraph can be set less than its content (without overflow specification)? Document is here: http://terrainformatica.com/w3/p2/problem1.htm
4
3553
by: aling | last post by:
Given: signed a, b; How to judge overflow of the sum of these two operands? Just use one *if* statement. Is this statement right? if ((a>0 && b>0 && sum<=0) || (a<0 && b<0 && sum>=0)) // overflow else // not overflow
19
3143
by: Jim | last post by:
I have spent the past few weeks designing a database for my company. The problem is I have started running into what I believe are stack overflow problems. There are two tab controls on the form (nested), three list views, one tree control with up to 30,000 nodes, maybe 15 comboboxes (half of which have a large recordset as rowsource), 20 or so buttons and around 30 text boxes (not to mention the images, labels, etc and around 1000 lines...
27
4560
by: REH | last post by:
I asked this on c.l.c++, but they suggested you folks may be better able to answer. Basically, I am trying to write code to detect overflows in signed integer math. I am trying to make it as efficient as possible without resorting to assembly language, and without causing undefined behavior. That, of course, means catching the overflow before it happens. What I asked was (stripping any relevance to C++):
7
2421
by: wij | last post by:
Hi: Is there better way of detecting multiplication overflow for type long than by using double precision of lldiv to verify the result? Thanks in advance. I.J.Wang
25
6259
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;
8
10669
by: starffly | last post by:
In my program, the caculated value is supposed to be no more than the constant named MAXINT,otherwise, overflow error will be informed.however, I cannot test if the value exceeds MAXINT within the integer scope smaller than MAXINT,so I want to seek a measure to test the excess without the value's comparing to MAXINT. Please let me know if you have a good idea. THX.
2
2755
by: lexor | last post by:
Hi! I'm struggling with a strange IE behavior regarding tables. I have a table like the following one <table cellpadding="0" cellspacing="0" border="1" width="500"> <tr> <td><div style="overflow:hidden;width: 355px;">Header1</div></td> <td><div style="overflow:hidden;width: 100px;">Header2</div></td> <td><div style="width: 100%;overflow:hidden;">Header3</div></td> </tr>
42
7023
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
0
8969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9266
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,...
0
8215
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6754
isladogs
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...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4826
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3280
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
2
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.