- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
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!!
- Marcas:
- Intel® Fortran Compiler
Link copiado
4 Respostas
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
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.
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Thank you Tim!
This means that it is better to use alwaysEw.dEe when real*8 are involved?
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
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!):
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]
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
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
Opções do tópico
- Subscrever fonte RSS
- Marcar tópico como novo
- Marcar tópico como lido
- Flutuar este Tópico para o utilizador atual
- Marcador
- Subscrever
- Página amigável para impressora