Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29249 Discussions

Is there a compiler directive for /fpconstant?

ferrad
New User
1,926 Views
I am writing a self contained function for which Iwill not provide a dsp file. I do not want to write d0 after all constants, but I want them all to interpreted as real*8. This I normally do by using /fpconstant, but this is stored in the dsp file - is there an equivalent compiler directive I can use?
Adrian
0 Kudos
7 Replies
Steven_L_Intel1
Employee
1,926 Views
Well, that's not what /fpconstant does. That switch makes the datatype of constants dependent on their context.

There is not a directive for /fpconstant, nor for /real_size:64, which does make single-precision constants double precision.

My advice is to specify the D0 or use an explicit kind specifier.
0 Kudos
ferrad
New User
1,926 Views
I guess I'm a little confused then.
In Project -> Settings -> Fortran -> Fortran Data, selecting "Extend Precision of Single Precision Constants" (which is what I interpret to mean "turn 2.0 into 2.0d0") toggles the /fpconstant compiler argument.
On the other hand, selecting 8 for the Default Real Kind is the one that turns on /real_size:64 (and this I had interpreted to mean "interpret the variable declaration'real xdata' as 'real*8 xdata' " ). I see that there is a compiler directive for this one - !DEC $REAL:8.
This interpretation works for me, so I'm not sure what is wrong with this interpretation.
Adrian
0 Kudos
Steven_L_Intel1
Employee
1,926 Views
/fpconstant affects a case such as this:

REAL(8) PI
PI = 3.1415926535897

In Fortran 90/95. the constant is single precision, and then gets extended with binary zeroes to double precision. With /fpconstant, real constants are held, internally, in REAL(8) until they are used and then converted if necessary.

/real_size:64 makes everything that is "default real kind" REAL(8): variables, constants and intrinsics, so it has a much broader effect than /fpconstant.

Ah - I forgot about !DEC$ REAL. We picked that one up from Microsoft. Perhaps that will work for you?
0 Kudos
ferrad
New User
1,926 Views
Yes, that's how I understood it. But, to get the double version of the constant into PI, Ineed to eithercompile your codewith /fpconstant, or append a d0 to the constant.
I don't want to rely on the latter, since I am not in control of the dsp file that my code will be used in. And I really wanted to know whether I could avoid adding numerous d0's to all my constants, by using a suitable compiler directive. Unfortunately, a quick test on !DEC $REAL:8 shows it doesn't do it.
Adrian
0 Kudos
Steven_L_Intel1
Employee
1,926 Views
Why exactly do you not want to add D0? Or better, something like this:

integer, parameter :: dp = selected_real_kind(15)
real(dp) pi
pi = 3.141592653589723_dp

This is the "proper" F90 way to do it.

However, !DEC$ REAL:8 works for me:

>type t.f90
!DEC$ REAL:8
REAL PI
PI = 3.141592653589723
write (*,*) PI
end
>ifort t.f90
Intel Fortran Compiler for 32-bit applications, Version 8.1 Build 20040923Z Package ID: w_fc_pc_8.1.021
Copyright (C) 1985-2004 Intel Corporation. All rights reserved.

Microsoft Incremental Linker Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.

-out:t.exe
-subsystem:console
-entry:mainCRTStartup
t.obj

>t.exe
3.14159265358972
0 Kudos
ferrad
New User
1,926 Views
Yes, !DEC$ REAL:8 does actually work, I had a typo - !DEC $REAL:8 - which compiles OK, but doesn't do the same thing...
Adrian
0 Kudos
Steven_L_Intel1
Employee
1,926 Views
Right - if there is a space after the DEC, it is not recognized as a directive and is just a comment.
0 Kudos
Reply