Microsoft KB Archive/179274

= PRB: Underflow Caused By exp Function Fails to Set errno =

Q179274

-

The information in this article applies to:


 * The C Run Time (CRT)
 * Microsoft Visual C++, 32-bit Enterprise Edition, version 5.0
 * Microsoft Visual C++, 32-bit Professional Edition, version 5.0
 * Microsoft Visual C++, 32-bit Enterprise Edition, version 6.0
 * Microsoft Visual C++, 32-bit Professional Edition, version 6.0
 * Microsoft Visual C++, 32-bit Learning Edition, version 6.0

-

SYMPTOMS
When using the exp function and an underflow error occurs, the errno variable is not set to a value.

RESOLUTION
#include  extern int errno;
 * 1) include 
 * 2) include 

void main( void ) {  double x = -1.0e+3,y;

y = exp( x );

// The exp function returns the exponential value of the // floating-point parameter, x, if successful. On overflow, // the function returns INF (infinite) and on underflow, exp // returns 0.

// Check for error conditions. // Underflow error or other. if(y==0 || (errno!=0)) {     if (y==0) printf("ERROR: Underflow Error\n"); else perror("ERROR");

printf("Errno: %i\n",errno); }  // No Errors--print results. else {     printf( "exp( %f ) = %f\n", x, y ); } }

STATUS
This behavior is by design.

MORE INFORMATION
The errno variable is a global variable, which is given an integer value upon an error. Math functions, such as exp, set this value to indicate an error state; library math routines set errno by calling _matherr. However, the errno variable is not set when an underflow occurs. According to the ANSI C specification, whether or not errno acquires the value of the macro ERANGE is implementation-defined.

Steps to Reproduce Behavior
Type in and execute the following program [when using the exp function and an underflow error occurs, the errno variable is not set to a value]: #include  extern int errno;
 * 1) include 
 * 2) include 

void main( void ) {  double x = -1.0e+3,y;

y = exp( x );

// Check for error conditions. // perror returns the error message associated with errno. if(errno!=0) {        perror("ERROR"); }  // No Errors--print results. But error did occur because we have an  // underflow error. // The underflow goes undetected because errno wasn't set to any // value. else {     printf( "exp( %f ) = %f\n", x, y ); } } Additional query words: 5.00

Keywords : kbcode kbVC500 kbVC600

Issue type : kbprb

Technology :

Last Reviewed: July 30, 2001

-

[mailto:MSDN@MICROSOFT.COM Send feedback to Microsoft]

© 2002 Microsoft Corporation. All rights reserved.