- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Maybe you know the compiler switch that would do a full double precision variable initialization without inserting d0 after every number. I mean when I do:
program test
real*8 i
do i=0.1, 1, 0.1
print *,i
end do
pause
endprogram
the output is
0.100000001490116
0.200000002980232
0.300000004470348
0.400000005960464
0.500000007450581
0.600000008940697
0.700000010430813
0.800000011920929
0.900000013411045
And if my modify:
program test
real*8 i
do i=0.1d0, 1d0, 0.1d0
print *,i
end do
pause
endprogram
I get
0.100000000000000
0.200000000000000
0.300000000000000
0.400000000000000
0.500000000000000
0.600000000000000
0.700000000000000
0.800000000000000
0.900000000000000
1.00000000000000
I would like that if I initialize the double precision variable it is always initialized at its full precision not single. Always using the d0 symbols makes the loops less readable and so error prone.
regards,
Maciej
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
But using them is more standard and will work with all compilers.
You may be looking for the /real:64 switch.
Linda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Also, using a non-integer variable as a DO loop control variable is a "deleted feature" and prone to many problems.
I suggest you take advantage of modern Fortran and do it as I see many do:
program test
integer, parameter :: DP = selected_real_kind(15,300)
real(DP) x
integer i
x = 0.1_DP
do i=1,10
print *,x
x = x + 0.1_DP
end do
pause
endprogram
Of course, you should also understand that 0.1 is not exactly representable in binary floating point.
If you insist on hiding your intentions from the reader of your code, the switch you are looking for is /real_size:64.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you I will use a switch as propably noone will use my code later. And yes, for me the notation with D is less readable in the code but it is only my experience. In fact I created that forum thread after making notoriuos errors with this. It simply slows down my creating process :)
So I was always wondering why is that Fortrans feature for. I dont know why Fortran specifications assumes that I dont want to use full precision of variable if I process it with some constant values. I understand, that if I intentionally wanted that behaviour I should use a D or E. But default should work with precision selected by programmer on the stage of declaration. I know it is probably some specification since ancient times kept for backward compatibility.
These are just my thoughts only. But such a flowers always causes me thinking to try IMSL with Visual Basic NET (I am still very impressed of how much VB NET is a programmer friendly language). And I see there is an edition of IMSL 7 for C#/VB NET :)
regards and thanks,
Maciej
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Intel Fortran also has a /fpconstant switch which may be closer to what you want - it keeps floating point constant in the higher precision.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It makes no such assumption. Variables in expressions have the types that they were declared with, but these declarations do not cover constants.
> But default should work with precision selected by programmer on the stage of declaration.
Declarations of variables (whether explicit or implicit) do not affect the types of constants used in expressions. Expressions can be mixed mode, i.e., be made up of parts of different types and kinds.
> I know it is probably some specification since ancient times kept for backward compatibility.
("I know" does not go well with "probably".) Although Fortran is an old language and backward compatibility may be more prized in it more than in other languages, useless and harmful features do get revised or dropped when the language is revised.
> But such a flowers always causes me thinking to try IMSL with Visual Basic NET
The grass is greener over the septic tank. For most people, language selection depends on more attributes than just flowers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank to all of you for the explanations.
Dear mecej4, I was certainly not clear enough. I provided sample code which shows what behavior I meant.
In my opinion the first code should give the same results as the second. I know that it doesnt and I have to obey the rule of this language. I wanted only to know an easier way to increase my programming, errors-free efficiency.
Best regards,
Maciej

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page