Floating Point Stack Underflow Error
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How to handle floating-point Underflow? up vote 3 down vote favorite 1 I try to understand c++ numerical properties. Thus, I am interested by the Underflow phenomenon. Can anyone give me an example of an Underflow and the way to handle it? c++ floating-point underflow share|improve this question edited Jul 12 '13 at 9:38 Pascal Cuoq 58.5k5101194 asked Jul 12 '13 at 8:14 WildThing 170213 1 0U-1. By putting a UB tag, though, I assume you mean signed underflow. –chris Jul 12 '13 at 8:15 @chris (let's assume 32-bit unsigned for the sake of argument) technically, there's no under/overflow there: the result of 0U-1 is 4294967295, not -1. 4294967295 fits in a 32-bit unsigned int and therefore doesn't overflow. By contrast, the result of -2147483648-1 is -2147483649 which doesn't fit on a signed 32-bit int and therefore overflows/underflows. –R. Martinho Fernandes Jul 12 '13 at 8:33 @R.MartinhoFernandes, I knew I should have typed out those extra characters, even if I got lazy and just used INT_MIN. Either way would probably be less than the note I had to tag on, too. That's kind of depressing. –chris Jul 12 '13 at 8:38 1 The use of “numerical” makes me think the question is about floating-point underflow, which is not undefined behavior (inasmuch as the compiler chooses to provide IEEE 754 floating-point semantics). –Pascal Cuoq Jul 12 '13 at 9:08 @PascalCuoq it is about doubles underflow –WildThing Jul 12 '13 at 9:10 add a comment| 2 Answers 2 active oldest votes up vote 3 down vote accepted An example of floating-point underflow is: double d = DBL_MIN / 3.0; A conforming IEEE 754 implementation should set d to a “subnormal”, that is, a number that is so close to zero that pr
Programming Boards C++ Programming floating point stack underflow Getting started with C or C++ | C Tutorial | C++ Tutorial | C and C++ FAQ | Get a compiler | Fixes for common problems Thread: floating point stack underflow Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 01-25-2005 #1 Curtux View Profile View Forum Posts Registered User Join Date Nov 2004 Posts 3 floating point stack underflow When I run the http://stackoverflow.com/questions/17610464/how-to-handle-floating-point-underflow program I get a floating point stack underflow error. I have searched but I can't seem to seem to find the solution. Any other errors are not my worry now just the stack underflow. Code: /* This program will allow the user to display the formula for calculating the area of a figure. r = rectangle t = triangle c = circle p = http://cboard.cprogramming.com/cplusplus-programming/60978-floating-point-stack-underflow.html parallelogram */ /////////////////////////////////////////////////////////////////////////// #include
If the return value is not used, the compiler must pop the value off of the floating-point stack in order to keep the floating-point stack http://www.nacad.ufrj.br/online/intel/Documentation/en_US/compiler_c/main_cls/fpops/common/fpops_cmp_stck_f.htm in the correct state. On systems based on Intel(R) 64 architectures, floating-point http://www.codingforums.com/computer-programming/67338-floating-point-stack-underflow.html values are usually returned in the xmm0 register. The floating-point stack is used only when the return value is a long double on Linux* and Mac OS* X systems. If the application calls a function without defining or incorrectly defining the function's prototype, the compiler cannot determine if the floating point function must return a floating-point value. Consequently, the return value is not popped off the floating-point stack if it is not used. This can cause the floating-point stack to overflow. The overflow of the stack results in two undesirable situations: A NaN value gets involved in the floating-point calculations The program results become unpredictable; the point where the program starts making errors floating point stack can be arbitrarily far away from the point of the actual error. For systems based on the IA-32 and Intel 64 architectures, the -fp-stack-check (Linux* and Mac OS* X) or /Qfp-stack-check (Windows*) option checks whether a program makes a correct call to a function that should return a floating-point value. If an incorrect call is detected, the option places a code that marks the incorrect call in the program. The -fp-stack-check (Linux* and Mac OS* X) or /Qfp-stack-check (Windows*) option marks the incorrect call and makes it easy to find the error. NoteThe -fp-stack-check (Linux* and Mac OS* X) and the /Qfp-stack-check (Windows*) option causes significant code generation after every function/subroutine call to ensure that the floating-point stack is maintained in the correct state. Therefore, using this option slows down the program being compiled. Use the option only as a debugging aid to find floating point stack underflow/overflow problems, which can be otherwise hard to find. See Also -fp-stack-check, /Qfp-stack-check option Tells the compiler to generate extra code after every function call to ensure that the floating-point stack is in the expected state.
New? Today's Posts FAQ Rules Guidelines Search Advanced Search Forum :: Computing & Sciences Computer Programming Floating Point: Stack Underflow If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. Enjoy an ad free experience by logging in. Not a member yet? Register. Results 1 to 3 of 3 Thread: Floating Point: Stack Underflow Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Rate This Thread Current Rating Excellent Good Average Bad Terrible 09-02-2005,12:09 PM #1 brsekharin View Profile View Forum Posts New to the CF scene Join Date Sep 2005 Posts 1 Thanks 0 Thanked 0 Times in 0 Posts Floating Point: Stack Underflow while i was converting a rgb(8 bit each) image to yuv(8bit each) through a function call, i am getting an error message "Floating Point: Stack Underflow". But i am getting this message only some times, with the same code void rgb_2_yuv() { unsigned char r,g,b,y,u,v; int i,j; for(i=0;i<149;i++) { for(j=0;j<228;j++) { b=fgetc(fp); g=fgetc(fp); r=fgetc(fp); if(i<144&& j<224) { rgb_pixelarray[i][j*3+0]=r; rgb_pixelarray[i][j*3+1]=g; rgb_pixelarray[i][j*3+2]=b; y=(0.3*r+0.6*g+0.1*b - 128); u=(-0.15*r-0.3*g+0.45*b); v=(0.4375*r-0.375*g-0.0625*b); yuv_pixelarray[i][j*3+0]=y; yuv_pixelarray[i][j*3+1]=u; yuv_pixelarray[i][j*3+2]=v; } } } } Reply With Quote 09-03-2005,03:28 PM #2 yonni View Profile View Forum Posts New Coder Join Date Jul 2005 Posts 77 Thanks 0 Thanked 0 Times in 0 Posts as far as i know (which, admittedly, isnt much) stack overflow and underflow is tempremental, annoying and hard to understand why its there, or how to get rid of it. I would just try changing the code. Reply With Quote 09-04-2005,06:21 PM #3 aman View Profile View Forum Posts Regular Coder Join Date Oct 2004 Posts 230 Thanks 0 Thanked 0 Times in 0 Posts Build a debug