- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Sergey,
[cpp]
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fenv.h>
int main() {
feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
double x = 0;
x = log10(0.0049999999992) ;
printf("%f",x);
return 0;
}
[/cpp]
Exactly same behavior. With g++ 4.6.3 exactly the same code does not generate a SIGFPE.
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello again,
I managed to narow it down a little bit more. An ANSI C version of the same code compiled with gcc, icc AND icpc gives no SIGFPE:
[cpp]
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <fenv.h>
int main() {
feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
double x = 0;
x = log10(0.0049999999992) ;
printf("%f",x);
return 0;
}
[/cpp]
[cpp]
icc log10.cxx -g -fp-trap-all=all - no SIGFPE - ok
icpc log10.cxx -g -fp-trap-all=all - no SIGFPE - ok
gcc log10.cxx -g -lm - no SIGFPE - ok
[/cpp]
This code also compiles with all the options above and runs without SIGFPE:
[cpp]
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <fenv.h>
int main() {
feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
double x = 0;
x = log10(0.0049999999992) ;
printf("%f",x);
return 0;
}
[/cpp]
But if <iostream> is included, I get the SIGFPE with icpc and ftrap, even without any mention to cout or printf.
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>>>You've metioned ''...Linux x86_64...".>>>
That's mean that 64-bit Linux version is used.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Original post did leave unspecified whether the 32-bit ia32 or 64-bit Intel64 compiler was in use. As g++ 4.6.3 was mentioned, one might expect a recent linux distro where it's easier to install the Intel64 compiler than ia32, but this is all speculation.
I don't find -fp-trap-all listed as a g++ option, so I might suspect g++ ignored it.
As I've seen log10() implemented as a macro in terms of log(), the traditional comparison between icpc and g++ pre-processed files also might be relevant, along with the traditional icpc -V and g++ -v quotations.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
Some informations: running Ubuntu 12.10 with kernel
[cpp]
Linux voyager 3.5.0-25-generic #38-Ubuntu SMP Mon Feb 18 23:27:42 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
[/cpp]
So I confirm this is a 64 bits platform. g++ -v prints out
[cpp]
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper
Destino: x86_64-linux-gnu
Configurado com: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.7.2-2ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Modelo de thread: posix
versão do gcc 4.7.2 (Ubuntu/Linaro 4.7.2-2ubuntu1)
[/cpp]
icpc -V prints
[cpp]
Intel(R) C++ Compiler XE for applications running on IA-32, Version 13.0.0.079 Build 20120731
Copyright (C) 1985-2012 Intel Corporation. All rights reserved.
[/cpp]
and
[cpp]
Intel(R) C++ Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 13.0.0.079 Build 20120731
Copyright (C) 1985-2012 Intel Corporation. All rights reserved.
[/cpp]
Depending the "source compilevars.sh" I use (ia32 or intel64).
And now, for the tests:
1) g++ -m32 -g log10.cxx -lm with iostream: OK
2) g++ -m64 -g log10.cxx -lm with iostream: OK
3) g++ -m32 -g log10.cxx -lm without iostream: OK
4) g++ -m64 -g log10.cxx -lm without iostream: OK
Tests with Intel compiler:
1) icpc -m64 -fp-trap-all=all -g log10.cxx with iostream: *** SIGFPE ***
2) icpc -m64 -fp-trap-all=all -g log10.cxx without iostream: OK
3) icpc -m64 -g log10.cxx with iostream: OK
4) icpc -m64 -g log10.cxx without iostream: OK
5) icpc -m32 -g log10.cxx with iostream: OK
6) icpc -m32 -g log10.cxx without iostream: OK
7) icpc -m32 -fp-trap-all=all -g log10.cxx with iostream: *** SIGFPE ***
8) icpc -m32 -fp-trap-all=all -g log10.cxx without iostream: OK
I'm not using any macros whatsoever. The test code follows:
[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);
double x = 0.0;
x = log10(0.0049999999992) ;
printf("%f",x);
return 0;
}
[/cpp]
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Sergey,
The function feenableexcept should catch this kind of errors in C++, with these options:
1) g++ -m32 -ftrapping-math -ftrapv -fsignaling-nans -g log10.cxx with with iostream: OK
2) g++ -m64 -ftrapping-math -ftrapv -fsignaling-nans -g log10.cxx with with iostream: OK
3) g++ -m32 -ftrapping-math -ftrapv -fsignaling-nans -g log10.cxx with without iostream: OK
4) g++ -m64 -ftrapping-math -ftrapv -fsignaling-nans -g log10.cxx with without iostream: OK
I currently don't have another platform to do the tests. Can you compile the code that I submitted? Does it run? Does it give SIGFPE?
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I found them in the GNU software compilation:
http://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-3.4/iostream-source.html
http://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-3.4/classstd_1_1basic__iostream.html
http://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-3.3/cstdlib-source.html
http://gcc.gnu.org/onlinedocs/gcc-4.7.2/libstdc++/api/a01063_source.html
http://gcc.gnu.org/onlinedocs/gcc-4.7.2/libstdc++/api/
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I posted the links, put it appeared that my comment was flagged for review.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page