PDA

View Full Version : Double Precision (i.e. Real*8)


micromuni
12-30-2003, 01:27 PM
I created an unmanaged Subroutine as follows

subroutine fmssub1 (Ivar, Rvar)
implicit double precision (a-z)
dll_export :: fmsSub1 ! export subroutine name

integer, intent (in out) :: Ivar
!double , intent (in out) :: Rvar

! Declare additional variables (if needed)

! executable statements
ivar = 7171717
Rvar = 777.123456789
end subroutine fmssub1

This routine is being called from a Visual Basic.Net appliction and has referenced the variables as Integer and Double.

The integer variable returns the correct value, but the double
returns the value 777.12347... The double precision is lost.

If I change the Rvar to 77.123456789D0 then I receive the
correct value in return. Is this still a requirement to add the D0
to the end of a implicitly defined double precision variable?

Thanks.

tzeis
12-30-2003, 08:06 PM
The "D0" is required to tell the compiler that the _constant_ is double precision, not the double precision variable. Anytime that you are assigning a constant to a D.P. variable, you should use the "D0" to guarantee that you are assigning a D.P. quantity to a D.P. variable.

pw317
02-17-2004, 03:31 AM
I have also noticed this and it bothers me because the Implicit Double Precision a-z should imply all variables and constants.

I have hundreds, if not thousands of constants that would all need to have d0 appended to them.

Why wouldn't the compiler treat constants as double along with everything else ?

tzeis
02-17-2004, 06:28 PM
The structure of the IMPLICIT statement pretty much dictates that it applies only to variables, because it specifies the starting letter of the variable name and associates it with a data type. Even when the IMPLICIT ... statement is specified, it is still possible to explicitly declare variables with different precisions.
The functionality that you are looking for is supplied by the compiler, when the -dbl options is used. The -dbl option causes all single precision real and complex variables, functions and constants to be promoted to double precision.