473,566 Members | 3,273 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 #1
13 7766
tings wrote:
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?
You arrive at zero because the value cannot be distinguished from
zero. IOW:
\forall floating point numbers f
\exists floating point number g, natural number n:
"f/(g^n)" == "zero"
where "expr" means evaluation of the expression in floating point
arithmetics.
We have 0 < h=f/g^n < min{floating point number e| e>0}
but h is sufficiently small to be rounded to zero.

Could you please define what you mean _exactly_ by 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?
Example:
#include <math.h>
#include <float.h>
#include <stdio.h>

int main (void)
{
double f = 2.0*DBL_MIN;
double g = 1.0/DBL_EPSILON;
unsigned int n = 3;

printf("%*.*g\n ", DBL_DIG+1, DBL_DIG, f/pow(g, n));

return 0;
}
should work on most machines.

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.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 14 '05 #2
tings wrote:
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."
You can't be sure that dividing by just a large number will do
that though. There will be lots of single numbers you could divide by
to get underflow, and after all...
(a/b)/c = a/(b*c)

It would take more work to find the number of least magnitude
that you could pick... in any case, it's just a way of stating it.
It's the same if you divide numbers that aren't so large,
enough times it will eventually happen that you get underflow.

If all you are doing is divisions by numbers whose magnitude is
big, then it's going to be the end result if you performed
just enough of these divisions [by themselves].
What does it mean "sufficient ly often" since only one division should be
enough to cause underflow in division between two floating point numbers?
I believe an underlying assumption is that you are performing
other operations and keeping a cumulative result, you are not
just dividing but performing a computation that involves systematic
application of something else, perhaps many operations (additions,
multiplications , or subtractions) as well as divisions.

So "often" is characterizing at what rate you are dividing your
current result by a large number which diminishes its magnitude
compared to operations that will amplify its magnitude in getting
your next result.

Being sufficiently often means that your divisions are not so
scattered or interleaved with other operations that increase
in magnitude that you stay away from zero.

i.e. if you had

double value = 500;

for(i = 0; i < 10000; i++) {
value = value * 100 - 1;
value = value / 100;
}

You will certainly be performing many divisions, but 'value'
will probably never be so close as to be rounded to 0.
Only about 1/3 of your operations are divisions, and 1/3 of your
operations increase value in number.

So the divisions were probably not often enough.

Now if you did

for(i = 0; i < 10000; i++) {
value = value * 100 + 1;
for(k = 0; k < 10; k++) { value = value / 100; }
}

You might find that to be dividing sufficiently often.
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?


It depends on the nature of what you are doing. In some case it
could be suggesting a possibility that you lost precision or
something blew up, but...

I wouldn't generalize that, IMO.. you need to evaluate whether the
result fits your expectations and is the right thing to get or if
the underflow is making a mess and you need to get a higher precision
or perform the computations differently.

I don't know of any hard and fast rule.
-Mysid

Nov 14 '05 #3
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.


Taking the lcc-win32 compiler as an example we have:
1) underflow is masked and will be approximated as zero. Since zero
is less than the smallest representable number it is within the
standard specs.

2) lcc-win32 does NOT set any errno flag if underflow occurs

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.

I hope this makes this clear.

jacob
Nov 14 '05 #4
"tings" <ti******@hotma il.com> wrote:
# 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."

Most representations limit the space for the exponent. So you might be able
to fit 2^-20 in the exponent, or 2^-100, or 2^-1000, but eventually you reach
an exponent like 2^-100000000000 which requires more bits in the exponent
than the representation is likely to provide. The representation might
replace that with 0 or special value to signal what happenned.

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

Depends on the implementation. Many CPUs nowadays use what's called IEEE reals.
That an additional interface on top of C (or Fortran or Pascal or ...) that
gives you more control over rounding and notification. You're going to have
check you math library documentation for more information.

# 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?

This is the business of Numerical Analyis, a strange black art that ponders
why (a+b)+c might not equal a+(b+c). Fools rush in where angels fear tread.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
OOOOOOOOOO! NAVY SEALS!
Nov 14 '05 #5
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.

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #6
CBFalconer <cb********@yah oo.com> wrote:
jacob navia wrote:

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.


Actually, there is, only it's spelled "fesetexceptfla g".
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.

Richard
Nov 14 '05 #7
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.

Nov 14 '05 #8
Richard Bos wrote:
CBFalconer <cb********@yah oo.com> wrote:

jacob navia wrote:
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.

Actually, there is, only it's spelled "fesetexceptfla g".

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.

Richard


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.

jacob

Nov 14 '05 #9
Richard Bos wrote:
CBFalconer <cb********@yah oo.com> wrote:
jacob navia wrote:

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.


Actually, there is, only it's spelled "fesetexceptfla g".


I just learned something, and you can guess how often I use those
facilities. At any rate my apologies to Jacob.

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #10

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

Similar topics

0
2951
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...
0
1852
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...
7
8484
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
3139
by: | last post by:
Sory about stupid question. What are differences between uflow and underflow functions ? Pls explains. Tks
38
8421
by: JKop | last post by:
union SignedChoice{ long with_sign; unsigned long without_sign; }; int main() { SignedChoice data;
1
2220
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
9199
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...
2
3731
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
1347
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
4130
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...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7893
Oralloy
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. ...
1
7645
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...
0
7953
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...
0
6263
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...
1
5485
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...
0
5213
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...
0
3643
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...
0
926
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...

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.