I find that there is a bug with respect to the management of the NaNs from C to fortran. This bug happens on Ubuntu 64bits (and not with 32bits).
returnanan.c defines 2 functions nan = returnanan() : returns a NAN, void returnanan2(nan) : sets the NAN in the input argument, passed by address. test.f computes NAN with 3 methods : #1 : uses returnanan() #2 : creates NAN with (1-ONE)/(1-ONE) #3 : uses returnanan2(nan) This produces the following output : (returnanan) nan = nan // OK X #1: 0.0000000000000000 // WRONG X #2: NaN // OK (returnanan2) nan = nan // OK X #3: NaN // OK My conclusion is that there is a problem when the NAN is passed from the C to the fortran. I cannot explain the fact that if the address of the NAN is passed to the C function, it works. This bug is related to Scilab, see : http://bugzilla.scilab.org/show_bug.cgi?id=4378 Best regards, Michaël Baudin -- Software Development Engineer michael.bau...@scilab.org The Scilab Consortium http://www.scilab.org/ ======================================= returnanan.c: #define C2F(name) name##_ #include <stdio.h> double C2F(returnanan)(void) { static int first = 1; static double nan = 1.0; if ( first ) { nan = (nan - (double) first)/(nan - (double) first); first = 0; } printf ( "(returnanan) nan = %e\n",nan); return ((double)nan); } void C2F(returnanan2)(double * nan) { double one = 1.0; *nan = (1.0 - one)/(1.0 - one); printf ( "(returnanan2) nan = %e\n",*nan); } ======================================= test.f PROGRAM test DATA ONE/1.0D0/ DOUBLE PRECISION X X = returnanan() PRINT * , "X #1:", X X = (1-ONE)/(1-ONE) PRINT * , "X #2:", X call returnanan2(X) PRINT * , "X #3:", X END ======================================= Now type : gcc -c returnanan.c gfortran -c test.f gfortran -o mytest returnanan.o test.o ./mytest ======================================= $ gcc -v Utilisation des specs internes. Target: x86_64-linux-gnu Configuré avec: ../src/configure -v --with-pkgversion='Ubuntu 4.3.3-5ubuntu4' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Modèle de thread: posix gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4) -- Summary: Bug with management of NaNs Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: michael dot baudin at scilab dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41831