Reputation: 11
I am using the modified Bessel function dbesi0.f available in the SLATEC library.
It contains the statement:
DATA BI0CS( 1) / -.7660547252 8391449510 8189497624 3285 D-1 /
which fills the first element of the double precision BIOCS vector.
I have never seen a double precision constant that contains spaces. The compiler does not flag this so I assume that it is correct. However, ??? A double precision vector should only be able to handle 15 or 16 digits so what is going on with the 34 digits? Are these provided in case someone is working with 128 bit numbers? If a machine is working with 64 bit double precision numbers, does the compiler only pay attention to the first xx digits in the DATA statement? If so, what is xx? Why is no error returned due to the spaces?
Upvotes: 1
Views: 194
Reputation: 13651
The Fortran-77 language specification states:
4.2.2 Blanks_in_Constants. Blank characters occurring
in a constant, except in a character constant, have no
effect on the value of the constant.
Note that this will not be true in fortran namelists.
It is possible with certain compilers to change the precision of the real and double data types at compile time. For example with gFortran 4.6 the flag -fdefault-real-8
will promote double to 128 bit if possible.
https://gcc.gnu.org/onlinedocs/gfortran/Fortran-Dialect-Options.html
The exact behavior is probably complier dependent, but the maximum number of significant digits for the given data type should be read. For standard 64 bit doubles, only the first 15-17 digits will be used. In addition to allowing for compiler options that increase the number of bytes of the double type, the authors may have included the longer string for reference purposes, or to simplify the future creation of a higher precision version using SELECTED_REAL_KIND
.
Upvotes: 0
Reputation: 21431
Note the file is fixed form source. In fixed form source spaces within statements (excluding spaces within character literals) and statement labels are not significant. Statements and statement labels just need to be contained within the right span of columns. Someone writing fixed form source can add and remove spaces outside of character literal constants to illuminate or obfuscate code to their heart's content.
(The syntax of Fortran source is consequently designed such that the compiler can parse the code without regard to spaces - for example the space between DATA
and BI0CS
at the start of your example snippet could be eliminated, making it DATABI0CS
, or if you've got punched cards to burn it could have been written D A T A B I 0 C S
. This source form feature is not generally regarded as a good thing, though it does come in handy for grouping digits in constants as per your example.)
The Fortran processor will generally use the closest internal approximation to the double precision literal constant that it can. This is not simply a case of ignoring decimal digits, because trailing decimal digits can still affect which particular internal value is closest when the radix of the processor's model for real numbers is not 10.
Providing additional precision in the source over what can be used by the Fortran processor is a form of proofing the code for use on processors that have greater numerical precision.
(The last few digits of that real literal constant make me suspect that it is intended to be an exact value at some meaningful number (possibly 64) of binary digits, but I haven't checked.)
Upvotes: 1