[Bug 429113] Re: libm pow() function does not report floating point underflow exception
Heiko
429113 at bugs.launchpad.net
Sun May 1 19:01:47 UTC 2016
The C++ program shown below gives (when compiled under Ubuntu 16.04
using g++ in c++11 mode) the output
MATH_ERRNO is set
MATH_ERREXCEPT is set
2^2000 = inf
ERROR: numerical overflow
2^2000 = inf
no error
1/2^2000 = 0
ERROR: numerical underflow
1/2^2000 = 0
no error
Whereas the expected output is
MATH_ERRNO is set
MATH_ERREXCEPT is set
2^2000 = inf
ERROR: numerical overflow
2^2000 = inf
ERROR: numerical overflow
1/2^2000 = 0
ERROR: numerical underflow
1/2^2000 = 0
ERROR: numerical underflow
Replacing g++ by clang++ (version 3.8) or icpc (version 16.0.2) gives correct results. Here, the test program follows:
#pragma STDC FENV_ACCESS ON
#include <cstdlib>
#include <iostream>
#include <cfenv>
#include <cmath>
void test_fp_exceptions() {
bool error=false;
if (std::fetestexcept(FE_DIVBYZERO)) {
error=true;
std::cerr << "ERROR: division by zero\n";
}
if (std::fetestexcept(FE_OVERFLOW)) {
error=true;
std::cerr << "ERROR: numerical overflow\n";
}
if (std::fetestexcept(FE_UNDERFLOW)) {
error=true;
std::cerr << "ERROR: numerical underflow\n";
}
if (std::fetestexcept(FE_INVALID)) {
error=true;
std::cerr << "ERROR: invalid result\n";
}
if (not error)
std::cerr << "no error\n";
std::feclearexcept(FE_ALL_EXCEPT);
std::cerr << '\n';
}
int main() {
std::cout << "MATH_ERRNO is "
<< (math_errhandling & MATH_ERRNO ? "set" : "not set") << '\n'
<< "MATH_ERREXCEPT is "
<< (math_errhandling & MATH_ERREXCEPT ? "set" : "not set") << '\n'
<< '\n';
std::feclearexcept(FE_ALL_EXCEPT);
std::cout << "2^2000 = " << std::pow(2., 2000) << '\n';
test_fp_exceptions();
std::cout << "2^2000 = " << std::pow(2., 2000.) << '\n';
test_fp_exceptions();
std::cout << "1/2^2000 = " << std::pow(2., -2000) << '\n';
test_fp_exceptions();
std::cout << "1/2^2000 = " << std::pow(2., -2000.) << '\n';
test_fp_exceptions();
return EXIT_SUCCESS;
}
--
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to glibc in Ubuntu.
https://bugs.launchpad.net/bugs/429113
Title:
libm pow() function does not report floating point underflow exception
Status in glibc package in Ubuntu:
Confirmed
Bug description:
Ubuntu 8.10 for x86-64
glibc 2.8~20080505-0ubuntu9
The pow() function in the standard C library does not report a
floating point underflow exception like it is supposed to.
Compile the attached program with '-O0 -fno-bultin-pow -lm'. Then run
it.
Expected output:
0.000000
exceptions:
inexact
underflow
Actual output:
0.000000
exceptions:
inexact
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/429113/+subscriptions
More information about the foundations-bugs
mailing list