Hello, I don't have much experience with Fortran but I am trying to debug some numerical instabilities in a program. Rather than share the program with you I have found that I get some interesting results when compiling a simple code which I've include below.
program test use ANORDF_INT implicit none double precision :: P, X1, X2 X1 = (90.0-100.0)/15.0 P = ANORDF(X1) print*,P end program test
It is meant to mimic a much more complex subroutine in the program I am debugging. The first issue is that we get differences in the output when I compile the code using the -r8 flag vs. when I don't (without -r8: P = 0.252492531200061 while with -r8: P = 0.252492537546923 ). This might not be an issue for this forum but if anyone has some input on that, I'd be grateful. The other problem is hen I try and compile the code with the -r16 I get the following error:
error #6284: There is no matching specific function for this generic function reference. [ANORDF]
I was thinking perhaps it's something to do with the ANORDF function itself and perhaps it doesn't support REAL(TYPE=16). I just couldn't find any information to back up my claim.
Thanks in advance.
The loss of precision that you saw is because of the expression (90.0-100.0)/15.0. Since all the terms in the expression are single precision, so is the resulting value. Depending on the floating point processor used, the calculation may be carried out in single or double precision, and the result is converted to the type of the variable on the left if necessary.
Try (90.d0-100.d0)/15.d0 in your code.That is a double precision expression. C and Fortran have slightly different rules on how to handle mixed-precision arithmetic expressions. Using compiler options such as -r8 adds a further complication, and reliance on the code makes the code nonportable. Finally, when you use already compiled objects, whether your own or present in libraries such as IMSL, such options as -r8 have no effect on the capabilities of the library routines.
You forgot to mention that your code needs the IMSL library. That library does not support 16-byte reals. As you can see in the IMSL documentation, the generic name ANORDF resolves to either S_ANORDF or D_ANORDF. There is no Q_ANORDF. Your using the interface to ANORDF allowed the error to be found at compile time rather than at link time.