473,698 Members | 2,022 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Underflow and floating-point math

An article states: "In floating point maths, where if you divide by a
sufficiently large number sufficiently often, you will always be able to
reach a value too small to distinguish from zero, given the finite precision
you have."

What happens when "a value too small to distinguish from zero" is reached by
the above division? Underflow?

What does it mean "sufficient ly often" since only one division should be
enough to cause underflow in division between two floating point numbers?

When underflow happens, the result of the above division should be regarded
as "undefined behavior"? In other words, the result could be any floating
number or just a meanless "number." Is this correct?

THANKS IN ADVANCE!


Nov 14 '05
13 7779
jacob navia <ja***@jacob.re mcomp.fr> writes:
CBFalconer wrote:
jacob navia wrote:
... snip ...
3) If the user unmasks the underflow flag with the standard
function fesetexceptionf lag before the underflow occurs, the
machine will trap at each underflow.

There is no such standard function. If you had said 'The lcc-win
peculiar function' it would have been acceptable. As it is, it is
a gross misstatement of fact.


I stand corrected. It is fesetexceptflag and not as I mistyped...

Of course even when I make an obvious typing error Chuck will not
forgive me such a sin... He never makes such errors.


I'm guessing you wrote that before you saw his apology. I suggest
dropping it.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #11
jacob navia <ja***@jacob.re mcomp.fr> writes:
tings wrote:
[snip]
When underflow happens, the result of the above division should be regarded
as "undefined behavior"? In other words, the result could be any floating
number or just a meanless "number." Is this correct?


No. The standard says (page 213, 7.12.1)
>> 5 The result underflows if the magnitude of the mathematical result is
so small that the mathematical result cannot be represented, without
extraordinary roundoff error, in an object of the specified type.195)
If the result underflows, the function returns an implementation-defined
value whose magnitude is no greater than the smallest normalized
positive number in the specified type; if the integer expression
math_errhandlin g & MATH_ERRNO is nonzero, whether errno acquires the
value ERANGE is implementation-defined; if the integer expression
math_errhandlin g & MATH_ERREXCEPT is nonzero, whether the "underflow"
floating-point exception is raised is implementation-defined. >>


That section describes the behavior of the functions in <math.h>, not
necessarily of floating-point division.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #12
"tings" <ti******@hotma il.com> writes:
An article states: "In floating point maths, where if you divide by a
sufficiently large number sufficiently often, you will always be able to
reach a value too small to distinguish from zero, given the finite precision
you have."

What happens when "a value too small to distinguish from zero" is reached by
the above division? Underflow?

What does it mean "sufficient ly often" since only one division should be
enough to cause underflow in division between two floating point numbers?

When underflow happens, the result of the above division should be regarded
as "undefined behavior"? In other words, the result could be any floating
number or just a meanless "number." Is this correct?


The quotation from the article is a rather vague statement of a more
general principle.

Floating-point overflow occurs when the mathematical result of an
operation is too large in magnitude to be represented (for example, if
a double result would be greater than DBL_MAX or less than -DBL_MAX).

Floating-point underflow occurs when the mathematical result is
non-zero, but too small to be represented. In C, I don't believe this
is considered an error; the result can be either 0.0 or some tiny
value. A flag of some sort might or might not be set.

Starting with some arbitrary value and repeatedly dividing it by some
sufficiently large value is one way to cause an underflow. For example:

#include <stdio.h>
int main(void)
{
double x = 1.0;
double previous;
int count = 0;

while (1) {
x /= 10.0;
count ++;
if (x == previous) {
printf("x = %g after %d iterations\n", x, count);
return 0;
}
else if (count >= 1000) {
printf("x = %g, bailing out after %d iterations\n", x, count);
return 0;
}
previous = x;
}
return 0;
}

On one system I just tried, this produces the output:

x = 0 after 325 iterations

You can, of course, get the same effect by repeatedly multiplying by a
small number, or by dividing or multiplying just once by a very large
or small number, respectively. Underflow is determined by the
mathematical result of the operation. The sentence you quoted should
be considered merely an example of what can cause it.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #13
jacob navia <ja***@jacob.re mcomp.fr> wrote:
Richard Bos wrote:
CBFalconer <cb********@yah oo.com> wrote:
If you had said 'The lcc-win peculiar function' it would have
been acceptable.


No, then it would have been off-topic. That is jacob navia's usual modus
operandi, and IYAM, _not_ to be encouraged.
As it is, it is a gross misstatement of fact.


I suspect a mere typo - in this, unusual, case.


Well, it was a typo. I excuse me for committing such a grave sin.

I will pay for this in programmer's hell in its 8th circle:
the one reserved for heretics and non-conformant implementors.


No, you won't.

Not for this typo, that is.

Richard
Nov 14 '05 #14

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

Similar topics

0
2964
by: William Ryan | last post by:
As an experienced Java Programmer, trust me on this, stick with .NET if you are already using it. It's hard to tell based on what you post. Is all of your code wrapped in an exception handler? Somewhere when the form is initialized or Form Load, I'd add a try catch and trap System.ArithmeticException... Step through each line with the debugger and if you post the line (ideally with the whole code snippet) I think we can figure it out.
0
1855
by: Davis King | last post by:
I'm trying to make a stream buffer which reads from a socket and it works fine in visual stuiod, borland 5.5.x and g++ 3.2.x but I get an infinite loop in g++ 3.0.4! I imagine it's somehow my fault though :) So I have implemented overflow, xsputn, underflow, uflow, pbackfail and xsgetn. I haven't made any buffers as I just want it to read and write from the socket immediatly. The infinite loop appears when I write cout <<...
7
8493
by: Oplec | last post by:
Hello, How can underflow and overflow of the basic arithmetic types be tested for using standard C++? For instance, if two long doubles are multiplied together, test whether or not the result is too large to fit in a long double? Thank you for your time, Oplec.
2
3148
by: | last post by:
Sory about stupid question. What are differences between uflow and underflow functions ? Pls explains. Tks
38
8441
by: JKop | last post by:
union SignedChoice{ long with_sign; unsigned long without_sign; }; int main() { SignedChoice data;
1
2231
by: Alan Johnson | last post by:
The std::streambuf class defines both of these functions as virtual, and they are apparently meant to be overloaded in derived classes to get more characters from an input sequence. Could someone explain what the difference between the two is, please? Alan
5
9227
by: Ian Pilcher | last post by:
I'm trying to figure out if an increment to a variable of an integer type, followed by a decrement, (or vice versa) is guaranteed to restore the variable to its initial value, even if the first operation causes the variable to overflow/underflow. In other words, if foo_t is an integer type, are the following two functions guaranteed to *always* return a non-zero value? int check_overflow(foo_t f) {
2
3738
by: alok | last post by:
I am getting inconsistent behvior on Linux and Solaris platfors while computing doule ( 64 bit precision ) multiplications. I have following two double numbers whose integer representation is as following I have a union typedef union { double double_val; unsigned long long uint_val;
1
1351
by: Maarten | last post by:
when i open a form in my mdi it goes well the firstime, but the secondtime i get an error: overflow or underflow in arithetic operation the debugger marks the font settings of a label. plz help me thanks Maarten
4
4141
by: Tom | last post by:
I have a VB.NET framework 1.1 application that I am installing on my user's workstation. It works fine on EVERY machine except for one - on this one machine it generates a 'Overflow or underflow in the arithmetic operation' when I attempt to instantiate my first form, as so: Dim frm As New frmMyForm() Based on some things I saw here, I thought it might be that this workstation didn't have a MS Sans Seriff font on it (since that is the...
0
9026
jinu1996
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...
1
8893
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
8861
tracyyun
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...
1
6518
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
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3045
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
2328
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
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.