Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29236 Discussões

formatting numbers with an exponent greater than 99

ximoteo
Principiante
2.712 Visualizações
Hi,
I've found an annoying problem when writing numbers with exponent (in absolute value) greater than 99 (e.g. 1d-120 or 1d170)

To test it I've compiled this short program
[fortran]write(*,'(E11.3)') 1d10
write(*,'(E11.3)') 1d177
write(*,'(E11.3)') 1d-10
write(*,'(E11.3)') 1d-177[/fortran]
with IFORT 11.1 20100414 and with this compiling options -check all -fpe0 -O0 -warn all
The output is
[bash]0.100E+11
0.100+178
0.100E-09
0.100-176
[/bash]
(same problem if you write to file).
Googling the problem I found some warning about this issue, but there is an intel compiler option to avoid this?
I can add a workaround such as
[fortran]write(*,'(E11.3)') max(my_double, 1e-99)[/fortran]
but (i) it is really annoying, and (ii) it is not correct [it is ok when you can approximate all the number less than 1e-100 to 1e-99, but it is not always true, and moreover you cannot do the same with min(my_double, 1e99)]
Thank you in advance!!
0 Kudos
4 Respostas
TimP
Colaborador honorário III
2.712 Visualizações
If you wish to allocate more than 4 characters to the exponent field, so as to display numbers such as 0.100e-176, you must specify the exponent width in your format (and allow for the additional total field width), e.g. e13.3e5. This should be covered in any Fortran textbook written in the last 30 years.
ximoteo
Principiante
2.712 Visualizações
Thank you Tim!
This means that it is better to use alwaysEw.dEe when real*8 are involved?
mecej4
Colaborador honorário III
2.712 Visualizações
You have not stated what it is that you find annoying. The standard allows the output shown, even if it is annoying to you.

There is the Ew.dEe format descriptor available, and it may do what you want (which is not yet clear!):

[fortran]write(*,'(E11.3e3)') 1d10
write(*,'(E11.3e3)') 1d177
write(*,'(E11.3e3)') 1d-10
write(*,'(E11.3e3)') 1d-177
[/fortran]
will result in the printout

[bash] 0.100E+011
 0.100E+178
 0.100E-009
 0.100E-176
[/bash]
Steven_L_Intel1
Funcionário
2.712 Visualizações
The standard not only "allows" the "annoying" output, it requires it. Use the explicit Ee form if you want more than two digits and the E letter to appear. Note that if you have the Ee form you will get an error if you exceed the allotted width.
Responder