Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7957 Discussions

-fp-trap-all=all generates SIGFPE in log10

mfactor
Beginner
1,221 Views

Hello all,

I'm testing the icpc compiler and found a curious case: if I compile the code below

    [cpp]

#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fenv.h>

using namespace std;

int main() {
feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
cout << log10(0.0049999999992) <<endl;

return 0;
}

[/cpp]

If I compile it with icpc log10.cxx -lm -g, it runs ok and gives the right answer (-2.30103), but if I enable icpc log10.cxx -lm -g -fp-trap-all=all , I get a SIGFPE. I'm using icpc version icpc (ICC) 13.0.0 20120731 on Linux x86_64. Any ideas?

Cheers 

0 Kudos
23 Replies
mfactor
Beginner
172 Views

Hello Sergey,

Thanks for your time. I'll wait the answer from the Intel Engineers. 

Cheers

0 Kudos
SergeyKostrov
Valued Contributor II
172 Views
>>... >>gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-3.4/iostream-source.html >>gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-3.4/classstd_1_1basic__iostream.html >>gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-3.3/cstdlib-source.html I didn't find anything that could control a state of Floating-Point Unit or possibly related to SIGFPE exception. While we're waiting for a response from Intel I'll think what else could be done.
0 Kudos
SergeyKostrov
Valued Contributor II
172 Views
Here are a couple of notes: - SIGFPE exception has to be raised by CRT-function signal - If you have a complete set of sources of STL and CRT libraries for GCC you need to find all calls to signal function ( I don't expect too many ) and you could be closer to understanding what is wrong - These calls could look like: ... if( signal( SIGFPE, ( void ( cdecl * )( int ) )SignalHandler ) == SIGERR ) { ... printf( "Failed to Set a Handler for Detection of a Floating-Point Error\n" ); ... } ... and SignalHandler could look like: ... void cdecl SignalHandler( int iSignalCode, int iSignalExtCode ) { ... g_iSignalCode = iSignalCode; // Saves the Signal & Signal Extended Codes g_iSignalExtCode = iSignalExtCode; _reset87(); // Resets FPU longjmp( jmpbuf, -1 ); // Restores calling environment, returns to 'setjump' with a code -1 ... } ... - Take into account that processing of exceptions with signal is a Very Old Technology and it was replaced by a modern Try-Catch exceptions handling.
0 Kudos
Reply