I have the following piece of c++ code:
void update(const int step, const int total) const
{
double s = static_cast<double>(step);
double t = static_cast<double>(total);
std::cout << s/t <<"------\n";
// etc...
}
I am using the intel c++ compiler with the -fp-trap=all flag activated. When running the code through gdb I get the following error:
Program received signal SIGFPE, Arithmetic exception.
0x000000000040ee07 in NilDa::progressBar::update (this=0x7fffffffbc9c, step=1, total=60000) at /home/d2d/dev/NilDa/sources/utils/progressBar.h:69
69 std::cout << s/t <<"------\n";
I don't really understand what is going on. The division seems to be well defined.
I'm assuming you're using the Intel C++ compiler (I'm not aware of any other compiler having such a flag). If so you can take a look here: https://software.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/compiler-reference/compiler-options/compiler-option-details/floating-point-options/fp-trap-qfp-trap.html#
As stated within that documentation the argument
all
inherits the trap for inexact results ([no]inexact
)Since 1/60000 can not be represented by an floating point number the result is inexact (1.66667e-05).