Anonymous Guest
|
Posted: Sun Dec 12, 2004 7:33 am Post subject: Function precision: Double vs Extended |
|
|
I'm having trouble using a function. My function is:
[pre]
FUNCTION f(x)
USE Constants
IMPLICIT NONE
REAL(KIND=q) :: f ! Function type
REAL(KIND=q), INTENT(IN) :: x ! Argument
f = x + EXP(x)
END FUNCTION f
[/pre]
The module Constants that is used is:
[pre]
MODULE Constants
IMPLICIT NONE
INTEGER, PARAMETER :: q = SELECTED_REAL_KIND(P=16) ! Extended
END MODULE Constants
[/pre]
In the main program I declare the variables:
[pre]
REAL(KIND=q), EXTERNAL :: f
REAL(KIND=q) :: p0, y0, y1, y2
[/pre]
Then if I assign the values,
[pre]
p0 = 0.0
y0 = f(p0)
y1 = 1.0 - y0
y2 = 1.0 - f(p0)
[/pre]
the result is that which is correct, but which is incorrect!
Yet if I change in the Constants module to:
[pre]
INTEGER, PARAMETER :: q = SELECTED_REAL_KIND(P=15) ! Double
[/pre]
then the result is .
Why is this?
Note that I'm using FTN95 (FTN95/Win32 Ver. 4.6.0, Personal Edition) on a Windows XP machine with an Intel Pentium 4 processor.
Thank you.
Miguel. |
|