|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
simon
Joined: 05 Jul 2006 Posts: 268
|
Posted: Fri Aug 14, 2020 1:11 am Post subject: Formatted output |
|
|
The following code prints an asterisk using FTN95.
Code: | 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? |
|
Back to top |
|
|
wahorger
Joined: 13 Oct 2014 Posts: 1217 Location: Morrison, CO, USA
|
Posted: Fri Aug 14, 2020 2:42 am Post subject: |
|
|
Here's a forum post from a different vendor. It explains why, and the answer "no".
https://community.intel.com/t5/Intel-Fortran-Compiler/Leading-zeros-in-the-f0-x-format-descriptor/td-p/1175148
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. |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
Posted: Fri Aug 14, 2020 11:18 am Post subject: |
|
|
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):
Quote: | ...
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. |
|
Back to top |
|
|
wahorger
Joined: 13 Oct 2014 Posts: 1217 Location: Morrison, CO, USA
|
Posted: Fri Aug 14, 2020 6:35 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
simon
Joined: 05 Jul 2006 Posts: 268
|
Posted: Sat Aug 15, 2020 3:24 am Post subject: |
|
|
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. |
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Sat Aug 15, 2020 1:07 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
Posted: Sat Aug 15, 2020 1:27 pm Post subject: |
|
|
For the program
Code: | 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
Code: | 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
Code: | 1.0 -1.0 0.0 10.0 -10.0
* ** . ** *** |
I think that I am seeing too many stars! |
|
Back to top |
|
|
John-Silver
Joined: 30 Jul 2013 Posts: 1520 Location: Aerospace Valley
|
Posted: Thu Aug 20, 2020 4:51 pm Post subject: |
|
|
.... FTN95 just has good taste in music , and follows its lead _________________ ''Computers (HAL and MARVIN excepted) are incredibly rigid. They question nothing. Especially input data.Human beings are incredibly trusting of computers and don't check input data. Together cocking up even the simplest calculation ... " |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|