cvnravi
cvnravi

Reputation:

Double precision in Fortran

I am using the Fortran 11 compiler in Visual Studio from Windows. How can I set real values to double precision from project properties? For example, in Fortran Powerstation (4.0) we have the menu option settings->code generation->default real kind (here we can set the type of the real data type). Similarly, how can we set double precision to the real variable in the Fortran 11 compiler?

Thanks in advance.

Upvotes: 1

Views: 2548

Answers (3)

TrippLamb
TrippLamb

Reputation: 1619

You can change the project properties to achieve this.

Open the Project Properties Dialog then navigate to ConfigurationProperties->Fortran->Data.

Then choose the drop down beside Default Real KIND and choose "8(/real)size64).

I am sure this is valid from VS2012 and on.

Upvotes: 1

user79973
user79973

Reputation: 55

One other way around is using module iso_fortran_env. Then you can specify the real kind with predefined variables REAL32, REAL64 and REAL128, which are single precision, double precision and quadruple precision, if your compiler supports.

For example:

program main

    use iso_fortran_env

    implicit none

    real(real32)  :: a1 ! single precision
    real(real64)  :: a2 ! double precision
    real(real128) :: a4 ! quadruple precision

end program

Upvotes: 1

T.E.D.
T.E.D.

Reputation: 44814

Unless you are looking to maintain the code under both compilers, perhaps you would be better off just changing the source code to use real*8's. That would get it behaving consistently when you do ports in the future too.

Upvotes: 1

Related Questions