[Bug fortran/35036] illegal E format descriptor produces wrong output
--- Comment #15 from jvdelisle at gcc dot gnu dot org 2008-02-21 02:21 --- Subject: Bug 35036 Author: jvdelisle Date: Thu Feb 21 02:20:27 2008 New Revision: 132510 URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=132510 Log: 2008-02-20 Jerry DeLisle [EMAIL PROTECTED] PR libfortran/35036 * write_float.def (output_float): Add error checks for zero digits after decimal point in E and D format specifiers. Modified: trunk/libgfortran/ChangeLog trunk/libgfortran/io/write_float.def -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35036
[Bug fortran/35036] illegal E format descriptor produces wrong output
--- Comment #16 from jvdelisle at gcc dot gnu dot org 2008-02-21 02:23 --- Subject: Bug 35036 Author: jvdelisle Date: Thu Feb 21 02:22:45 2008 New Revision: 132511 URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=132511 Log: 2008-02-20 Jerry DeLisle [EMAIL PROTECTED] PR libfortran/35036 * gfortran.dg/fmt_zero_digits.f90: Revise test. Modified: trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/fmt_zero_digits.f90 -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35036
[Bug fortran/35036] illegal E format descriptor produces wrong output
--- Comment #17 from jvdelisle at gcc dot gnu dot org 2008-02-21 02:23 --- Fixed on trunk. -- jvdelisle at gcc dot gnu dot org changed: What|Removed |Added Status|ASSIGNED|RESOLVED Resolution||FIXED Target Milestone|--- |4.4.0 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35036
[Bug fortran/35036] illegal E format descriptor produces wrong output
--- Comment #11 from jvdelisle at gcc dot gnu dot org 2008-02-02 08:28 --- Here is a different view on this; from the standard: For an internal value that is neither an IEEE infinity nor a NaN, the form of the output field for a scale factor of zero is: [ ± ] [0].x1 x2 . . . xd exp where: ± signifies a plus sign or a minus sign. . signifies a decimal symbol (10.5). x1 x2 . . . xd are the d most significant digits of the internal value after rounding. You will notice that the series of significant digits begins with x(1) going up to x(d). x(0) is not defined in the allowable output. This makes sense since this particular format has no significant digits to the left of the decimal point and it is meaningless not to display at least 1 significant digit. I would say then that the code is invalid. Further, I don't think the discussion in the standard about the scaling factor k is intended to say anything about the value of d, it is only speaking of what to do under certain conditions of k relative to d. Now if you look at the output from this simple test program: a = 1.e5 write(*,'(E15.0)') a write(*,'(E15.1)') a write(*,'(E15.2)') a write(*,'(E15.3)') a write(*,'(E15.4)') a write(*,'(E15.5)') a write(*,'(E15.6)') a write(*,'(E15.7)') a write(*,'(E15.8)') a end $ gfc pr35036.f $ ./a.out 0.E+01 0.1E+06 0.10E+06 0.100E+06 0.1000E+06 0.1E+06 0.10E+06 0.100E+06 0.1000E+06 The pattern is clear and it breaks to nonsense for d=0. The standard (F2003) also says: 10.6.1 (5) However, the processor shall not produce asterisks if the field width is not exceeded when optional characters are omitted. I don't think this case is an issue of exceeding the width. Therefore I think a runtime error is appropriate. Even better would be a compile time error as well. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35036
[Bug fortran/35036] illegal E format descriptor produces wrong output
--- Comment #12 from dominiq at lps dot ens dot fr 2008-02-02 11:13 --- I agree that If -d k = 0 is confusing when you don't specify k. However you can remove the k and get if -d0, aka if 0d, then in my opinion it rule out d=0 and the format Ew.0 is invalid and should diagnosed at compile time when possible. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35036
[Bug fortran/35036] illegal E format descriptor produces wrong output
--- Comment #13 from jvdelisle at gcc dot gnu dot org 2008-02-02 19:36 --- Created an attachment (id=15081) -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15081action=view) Proposed patch This patch provides an error for precision (number of digits left of decimal point) specified with E and D formats. This is consistent with the Standards and Sun f95. It also gives an error if the scaling factor is out of acceptable range. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35036
[Bug fortran/35036] illegal E format descriptor produces wrong output
--- Comment #14 from jvdelisle at gcc dot gnu dot org 2008-02-03 00:06 --- Created an attachment (id=15082) -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15082action=view) Revised test case This test case is updated with additional tests. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35036
[Bug fortran/35036] illegal E format descriptor produces wrong output
--- Comment #10 from burnus at gcc dot gnu dot org 2008-01-31 12:46 --- (In reply to comment #9) Sun f95 gives: Error 1078: scale factor out of range ifort gives: g95 and openf95 give the same result as ifort: While NAG f95 follows sunf95 by giving the run-time error: Scale factor 0 out of range for d=0 This is for write(*, '(E8.0)') 1e5. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35036
[Bug fortran/35036] illegal E format descriptor produces wrong output
--- Comment #1 from pinskia at gcc dot gnu dot org 2008-01-31 01:29 --- Hmm, gfortran produces something slightly different: [dhcp-10-98-10-23:~] apinski% ~/local-gcc/bin/gfortran t.f -pedantic [dhcp-10-98-10-23:~] apinski% ./a.out 0.E+01 -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35036
[Bug fortran/35036] illegal E format descriptor produces wrong output
--- Comment #2 from kargl at gcc dot gnu dot org 2008-01-31 01:46 --- (In reply to comment #0) E8.0 is an illegal format descriptor, Can you cite from the Fortran 95 standard why this is illegal? -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35036
[Bug fortran/35036] illegal E format descriptor produces wrong output
--- Comment #3 from furue at hawaii dot edu 2008-01-31 02:00 --- Subject: Re: illegal E format descriptor produces wrong output Hi, | --- Comment #2 from kargl at gcc dot gnu dot org 2008-01-31 01:46 --- | (In reply to comment #0) | E8.0 is an illegal format descriptor, | | Can you cite from the Fortran 95 standard why this is illegal? Good question :-) Unfortunately, I don't have a Fortran 95 reference at hand, and so let me refer to the F77 standard: http://www.fortran.com/fortran/F77_std/rjcnf.html QUOTE 13.5.9.2.2 E and D Editing. The Ew.d, Dw.d, and Ew.dEe edit descriptors indicate that the external field occupies w positions, the fractional part of which consists of d digits, unless a scale factor greater than one is in effect, and the exponent part consists of e digits. The e has no effect on input. [. . .] The scale factor k controls the decimal normalization (13.5.7). If -d k = 0, the output field contains exactly |k| leading zeros and d - |k| significant digits after the decimal point. If 0 k d + 2, the output field contains exactly k significant digits to the left of the decimal point and d - k + 1 significant digits to the right of the decimal point. Other values of k are not permitted. /QUOTE When d = 0, the only possible value for the scaling factor k is 1. Since Other values of k are not permitted, you *must* use 1P with d = 0, as 1PE8.0. Q.E.D. . . . I know this is a rather roundabout logic, and I'm not 100% sure, actually. I'm curious. Now, *if* E8.0 is legal, what output should be generated for a value of 1e5 ? 0.E5 ? Cheers, Ryo -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35036
[Bug fortran/35036] illegal E format descriptor produces wrong output
--- Comment #4 from kargl at gcc dot gnu dot org 2008-01-31 02:24 --- (In reply to comment #3) Subject: Re: illegal E format descriptor produces wrong output Hi, | --- Comment #2 from kargl at gcc dot gnu dot org 2008-01-31 01:46 --- | (In reply to comment #0) | E8.0 is an illegal format descriptor, | | Can you cite from the Fortran 95 standard why this is illegal? Good question :-) Unfortunately, I don't have a Fortran 95 reference at hand, and so let me refer to the F77 standard: http://www.fortran.com/fortran/F77_std/rjcnf.html QUOTE 13.5.9.2.2 E and D Editing. The Ew.d, Dw.d, and Ew.dEe edit descriptors indicate that the external field occupies w positions, the fractional part of which consists of d digits, unless a scale factor greater than one is in effect, and the exponent part consists of e digits. The e has no effect on input. [. . .] The scale factor k controls the decimal normalization (13.5.7). If -d k = 0, the output field contains exactly |k| leading zeros and d - |k| significant digits after the decimal point. If 0 k d + 2, the output field contains exactly k significant digits to the left of the decimal point and d - k + 1 significant digits to the right of the decimal point. Other values of k are not permitted. /QUOTE When d = 0, the only possible value for the scaling factor k is 1. Since Other values of k are not permitted, you *must* use 1P with d = 0, as 1PE8.0. Q.E.D. . . . I know this is a rather roundabout logic, and I'm not 100% sure, actually. I'm curious. Now, *if* E8.0 is legal, what output should be generated for a value of 1e5 ? 0.E5 ? Actually, I think the 'correct' output might be 0.E6. There is no restriction in F95 that d must be positive in Ew.d. In 10.6.5.1, it clearly states that k = 0 at the beginning of execution of an input/output statement. The wording you quote above is (almost) identical to F95 language, so one could argue that the -d k = 0 is true when d = 0 and k = 0. Yes, it might be a stupid interpretation, but then again the standard sometime defies logic. In any event, gfortran is definitely giving a bogus answer of 0E+1, and your desired output of *** is probably the right thing to do. jerry, any comments? -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35036
[Bug fortran/35036] illegal E format descriptor produces wrong output
--- Comment #5 from furue at hawaii dot edu 2008-01-31 02:45 --- Subject: Re: illegal E format descriptor produces wrong output | There is no restriction in F95 that d must be positive in Ew.d. | In 10.6.5.1, it clearly states that k = 0 at the beginning of | execution of an input/output statement. The wording you quote | above is (almost) identical to F95 language, so one could argue | that the -d k = 0 is true when d = 0 and k = 0. I may be missing something, but -d k = 0 doesn't hold when d = 0 and k = 0. Notice the inequality . So, when k = 0, how should we read the part we quote? | In any event, gfortran is definitely giving a bogus answer | of 0E+1, and your desired output of *** is probably the | right thing to do. I like that. But, for the sake of curiosity, how does the Fortran standard describe the process that leads to ***? I mean, suppose E8.0 is legal, but still can we emit ***? Ryo -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35036
[Bug fortran/35036] illegal E format descriptor produces wrong output
--- Comment #6 from kargl at gcc dot gnu dot org 2008-01-31 04:09 --- (In reply to comment #5) Subject: Re: illegal E format descriptor produces wrong output | There is no restriction in F95 that d must be positive in Ew.d. | In 10.6.5.1, it clearly states that k = 0 at the beginning of | execution of an input/output statement. The wording you quote | above is (almost) identical to F95 language, so one could argue | that the -d k = 0 is true when d = 0 and k = 0. I may be missing something, but -d k = 0 doesn't hold when d = 0 and k = 0. Notice the inequality . So, when k = 0, how should we read the part we quote? Notice the =. -d k = 0 goes to -(d=0) (k=0) = 0 -- -0 0 = 0. Zero is certainly less than or equal to zero. This case is probably covered in some murky, musty corner of the standard, but I haven't found it, yet. Jerry and Thomas are the IO gurus. | In any event, gfortran is definitely giving a bogus answer | of 0E+1, and your desired output of *** is probably the | right thing to do. I like that. But, for the sake of curiosity, how does the Fortran standard describe the process that leads to ***? I mean, suppose E8.0 is legal, but still can we emit ***? The *** are emitted when the result can't fit into the requested field. Off the top of my head, the easiest example is E8.1E1 for x = 1e25. The exponent field is too small, or I2 and i = 100. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35036
[Bug fortran/35036] illegal E format descriptor produces wrong output
--- Comment #7 from jvdelisle at gcc dot gnu dot org 2008-01-31 05:45 --- I will have to study the Standard some more as well. Off the top of my head I have a vague recollection of working a bug like this before and we fixed it. I will check into this. -- jvdelisle at gcc dot gnu dot org changed: What|Removed |Added AssignedTo|unassigned at gcc dot gnu |jvdelisle at gcc dot gnu dot |dot org |org Status|UNCONFIRMED |ASSIGNED Ever Confirmed|0 |1 Last reconfirmed|-00-00 00:00:00 |2008-01-31 05:45:32 date|| http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35036
[Bug fortran/35036] illegal E format descriptor produces wrong output
--- Comment #8 from furue at hawaii dot edu 2008-01-31 06:16 --- Subject: Re: illegal E format descriptor produces wrong output | I may be missing something, but -d k = 0 doesn't hold | when d = 0 and k = 0. Notice the inequality . So, when k = 0, | how should we read the part we quote? | | Notice the =. -d k = 0 goes to -(d=0) (k=0) = 0 -- -0 0 = 0. | Zero is certainly less than or equal to zero. But, what about -0 0? Do you mean that this inequality holds? Do you mean to say minus integer zero is smaller than plus integer zero? | I like that. But, for the sake of curiosity, how does the Fortran | standard describe the process that leads to ***? I mean, suppose | E8.0 is legal, but still can we emit ***? | | The *** are emitted when the result can't fit into the requested field. | Off the top of my head, the easiest example is E8.1E1 for x = 1e25. | The exponent field is too small, or I2 and i = 100. Yes, but do you claim that the result can't fit into the requested field for write(*, '(E8.0)') 1e5 supposing that E8.0 be legal? As you suggested, one correct output is 0.E+06, which would certainly fit in eight columns. Then why reject an output of 0.E+06 and replace it with ? What I'm getting at is that *if* E8.0 be legal and if you plan to emit for 1e5, you need a reason for that decision. Ryo -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35036
[Bug fortran/35036] illegal E format descriptor produces wrong output
--- Comment #9 from jvdelisle at gcc dot gnu dot org 2008-01-31 06:27 --- Sun f95 gives: ** FORTRAN RUN-TIME SYSTEM ** Error 1078: scale factor out of range Location: the WRITE statement at line 2 of pr35036.f Unit: * File: standard output Aborted ifort gives: $ ifort pr35036.f90 $ ./a.out -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35036