# E0.0E0 format valid F2018?

**URL:** <https://fortran-lang.discourse.group/t/e0-0e0-format-valid-f2018/6343>\
**Category:** Help\
**Created:** [August 16, 2023, 6:07am UTC](https://fortran-lang.discourse.group/t/e0-0e0-format-valid-f2018/6343 "2023-08-16T06:07:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harper](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@Harper](https://fortran-lang.discourse.group/u/Harper)\
**Post date:** [August 16, 2023, 6:07am UTC](https://fortran-lang.discourse.group/t/e0-0e0-format-valid-f2018/6343/1 "2023-08-16T06:07:10Z")

</div>

This 3-line program gives different results with two compilers, neither of them what I had hoped for. I suspect that the program is standard-conforming F2018 but the compilers are not, though both have implemented much of F2018, and one of them gave the output I had expected, `3.E0`, with format either `(ES0.0E0)` or `(EN0.0E0)`.

```auto
program teste0
  write(*,"(E0.0E0)") 3.14159
end program teste0

```

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [August 16, 2023, 11:21am UTC](https://fortran-lang.discourse.group/t/e0-0e0-format-valid-f2018/6343/2 "2023-08-16T11:21:45Z")

</div>

> [@Harper](#):
>
> ```auto
> program teste0
> write(*,"(E0.0E0)") 3.14159
> end program teste0
> 
> ```

Have not looked it up in the standard(s) yet, but ifx (IFX) 2023.2.0 20230622 gives this warning,  
which gives a specific reason to check.

```plaintext
remark #8577: The scale factor (k) and number of fractional digits (d) do not have the allowed combination of either -d < k <= 0 or 0 < k < d+2. Expect asterisks as output.
    write(*,"(E0.0E0)") 3.14159
-----------------^

```

---

<div class="post-metadata">

**Author:** ![Harper](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@Harper](https://fortran-lang.discourse.group/u/Harper)\
**Post date:** [August 16, 2023, 9:46pm UTC](https://fortran-lang.discourse.group/t/e0-0e0-format-valid-f2018/6343/3 "2023-08-16T21:46:53Z")

</div>

I think the trouble is that E0.0E0 is a F2018 feature not yet implemented in some compilers. I have sent a bug report to gfortran.

---

<div class="post-metadata">

**Author:** ![RonShepard](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@RonShepard](https://fortran-lang.discourse.group/u/RonShepard)\
**Post date:** [August 16, 2023, 11:12pm UTC](https://fortran-lang.discourse.group/t/e0-0e0-format-valid-f2018/6343/4 "2023-08-16T23:12:14Z")

</div>

> [@Harper](#):
>
> I have sent a bug report to gfortran.

Is this what is supposed to happen?

```auto
$ gfortran --version teste0.f90 && a.out
GNU Fortran (Homebrew GCC 13.1.0) 13.1.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

0.314159012E+1

```

On the other hand…

```auto
$ nagfor teste0.f90 && a.out
NAG Fortran Compiler Release 7.1(Hanzomon) Build 7114
Error: teste0.f90, line 2: Zero field width invalid for E edit descriptor
[NAG Fortran Compiler error termination, 1 error]

```

---

<div class="post-metadata">

**Author:** ![Harper](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@Harper](https://fortran-lang.discourse.group/u/Harper)\
**Post date:** [August 16, 2023, 11:55pm UTC](https://fortran-lang.discourse.group/t/e0-0e0-format-valid-f2018/6343/5 "2023-08-16T23:55:39Z")

</div>

No. I think gfortran should have given 0.E+1 and I suspect that nagfor has  
also not yet implemented E0.0E0, which is a possible f2018 output format  
according to my reading of the f2018 (or f2023) standard 13.7.2.3.3.

---

<div class="post-metadata">

**Author:** ![sblionel](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/sblionel/32/853_2.png) [@sblionel](https://fortran-lang.discourse.group/u/sblionel)\
**Post date:** [August 17, 2023, 5:23pm UTC](https://fortran-lang.discourse.group/t/e0-0e0-format-valid-f2018/6343/6 "2023-08-17T17:23:05Z")

</div>

It took me a while, but the Intel “remark” pointed me at the proper language (emphasis mine).

F2018 13.7.2.3.3p5 (E editing)

> The scale factor k controls the decimal normalization (13.3.2, 13.8.5). If −d \< k ≤ 0, the output field contains exactly |k| leading zeros and d−|k| significant digits after the decimal symbol. If 0 \< k \< d+2, the output field contains exactly k significant digits to the left of the decimal symbol and d − k + 1 significant digits to the right of the decimal symbol. **Other values of k are not permitted.**

In this example, k=0 and d=0. The first test (-d \< k \<= 0) is not satisfied because -0 is not less than 0. The second test (0 \< k \< d+2) is not satisfied because 0 is not less than 0. Therefore, this program is nonconforming.

---

<div class="post-metadata">

**Author:** ![Harper](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@Harper](https://fortran-lang.discourse.group/u/Harper)\
**Post date:** [August 18, 2023, 5:55am UTC](https://fortran-lang.discourse.group/t/e0-0e0-format-valid-f2018/6343/7 "2023-08-18T05:55:38Z")

</div>

Thank you @sblionel. I had not realised the importance of the scale factor k in E output in a program that did not mention it explicitly. That raises the question of EN and ES output. For both of them the standard says `The scale factor has no effect on output.` That suggests that EN0.0E0 and ES0.0E0 are both valid f2018 formats for a real value. If so, ifort is right, gfortran prints the correct value in the wrong format, and I don’t have any other compiler.

---

<div class="post-metadata">

**Author:** ![sblionel](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/sblionel/32/853_2.png) [@sblionel](https://fortran-lang.discourse.group/u/sblionel)\
**Post date:** [August 18, 2023, 2:27pm UTC](https://fortran-lang.discourse.group/t/e0-0e0-format-valid-f2018/6343/8 "2023-08-18T14:27:36Z")

</div>

I agree - those formats are valid, and the Intel compiler does the right thing. I tried the NAG compiler, but it does not yet support zero widths for ES and EN.
