The following code prints an asterisk using FTN95.
Program p
Print '(F0.0)', 1.0
End Program p
A few other compilers have tried output 1. Does anyone know what the standard should be?
Welcome to our forums
The following code prints an asterisk using FTN95.
Program p
Print '(F0.0)', 1.0
End Program p
A few other compilers have tried output 1. Does anyone know what the standard should be?
Here's a forum post from a different vendor. It explains why, and the answer 'no'.
The Fortran standard says that it is implementation-dependent whether there is a leading zero in F format for values less than 1. The Intel Fortran (and DEC/Compaq before it) behavior is to omit the zero. Some other Fortran compilers insert the zero. I have seen requests for an option to supply the zero, but it has not yet been implemented.
Bill, I think that you answered a different question than the one asked by the OP. The real number 1.0 has an exact internal IEEE representation, so it cannot be rounded or chopped to a number less than 1. Therefore, there is no question of whether or not a leading 0 should be inserted, which is a question for cases where the absolute value of the number is less than 1.
The F95 standard says (section 10.5.1.2.1):
... When w is zero, the processor selects the field width. ... The output field consists of blanks, if necessary, followed by a minus if the internal value is negative, or an optional plus otherwise, followed by a string of digits that contains a decimal point and represents the magnitude of the internal value, as modified by the established scale factor and rounded to d fractional digits.
From those quotes, I conclude that the output string should be 1. That makes the field width = 2; arguing that printing an asterisk would enable using a field width of 1 would prioritise shortening over conveying meaningful information.
I suspect that the decimal point is required to facilitate reading the number back from the string with another Fw.d format.
mecej4, you may be correct. However, the key in this is that there is a implementation dependency in how things will show up.
Perhaps a key here is trying to print 0.0 using this format. A decimal point is displayed. Meaning that, just like for 'fully' formatted numbers, if the display is too big to fit, you get stars.
So, the implication is that for a F format, the decimal point will be displayed, always.
The pathological case here is then the F0.0.
If the value is 10, you get 2 stars, not one, for example.
Thanks for the comments. It sounds like I will have to assume that there are different implementations and and make sure my code works regardless of the compiler.
One lives and learns.
I always knew that on the ICL 1900 series Fortran 66 compiler, formatting with for example F0.0 was admissible on input, and it had the role of allowing free format input. You could really confuse yourself by mixing fixed and free format on the same line, but it has to be a bit barmy on output, where a 'processor' can decide what it means.
What's the point of a Standard if it means 'Do what thou wilt shall be the whole of the Law'? Perhaps Fortran should be renamed Thelema. And if Dan mentions devilry again, perhaps he needs to study the works of Aleister Crowley to understand why there is so much of it. 93, dear chap*.
Eddie
*See Wikipedia on Crowley if you don't understand this.
For the program
Program p
Print '(5(2x,F0.1))', 1.0,-1.0,0.0,10.0,-10.0
Print '(5(2x,F0.0))', 1.0,-1.0,0.0,10.0,-10.0
End Program p
Intel Fortran gives
1.0 -1.0 .0 10.0 -10.0
1. -1. 0. 10. -10.
Gfortran gives the same output. FTN95, 32-bit or 64-bit, gives
1.0 -1.0 0.0 10.0 -10.0
* ** . ** ***
I think that I am seeing too many stars!