- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
I have a subroutine which initializes an array of real numbers. At the end of this subroutine, I want to make sure that all elements of the array have been initialized. All real values are admissible initial values (including signed infinity numbers, etc).
Is is possible to force all values of my array to be NaNs at the beginning of the subroutine; then check at the end if there are any NaNs left (using ISNAN). How can I conveniently set my array elements to be NaNs?
Thanks,
Olivier
Is is possible to force all values of my array to be NaNs at the beginning of the subroutine; then check at the end if there are any NaNs left (using ISNAN). How can I conveniently set my array elements to be NaNs?
Thanks,
Olivier
- Etiquetas:
- Intel® Fortran Compiler
Enlace copiado
6 Respuestas
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
I think this should work:
use, intrinsic :: IEEE_ARITHMETIC
...
array = IEEE_VALUE(IEEE_QUIET_NAN)
You can then use IEEE_IS_NAN to do the test.
use, intrinsic :: IEEE_ARITHMETIC
...
array = IEEE_VALUE(IEEE_QUIET_NAN)
You can then use IEEE_IS_NAN to do the test.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
Thanks Steve - I just tried the sample program below:
PROGRAM TEST_NAN
USE,INTRINSIC :: IEEE_ARITHMETIC
IMPLICIT NONE
INTEGER,PARAMETER :: DP = SELECTED_REAL_KIND(10,100)
REAL(KIND=DP) R
R = IEEE_VALUE(IEEE_QUIET_NAN)
WRITE(*,*) R
END PROGRAM TEST_NAN
I get compiler errors. I am using IVF 10.1, so I suppose that your example works for higher versions of IVF.Do you think there mightbe a work around (manipulating the bits of R, for instance)?
Olivier
PROGRAM TEST_NAN
USE,INTRINSIC :: IEEE_ARITHMETIC
IMPLICIT NONE
INTEGER,PARAMETER :: DP = SELECTED_REAL_KIND(10,100)
REAL(KIND=DP) R
R = IEEE_VALUE(IEEE_QUIET_NAN)
WRITE(*,*) R
END PROGRAM TEST_NAN
I get compiler errors. I am using IVF 10.1, so I suppose that your example works for higher versions of IVF.Do you think there mightbe a work around (manipulating the bits of R, for instance)?
Olivier
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
If your compiler doesn't support IEEE_ARITHMETIC, this makes a good case for an upgrade.
For earlier compilers, you could generate a NaN by TRANSFERing a z'....' constant, or by calling a function (as quick and dirty as could be imagined) such as
function rnan(x)
!dir$ optimize:0
rnan = (x-x)/(x-x)
return
For earlier compilers, you could generate a NaN by TRANSFERing a z'....' constant, or by calling a function (as quick and dirty as could be imagined) such as
function rnan(x)
!dir$ optimize:0
rnan = (x-x)/(x-x)
return
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
Quoting - tim18
If your compiler doesn't support IEEE_ARITHMETIC, this makes a good case for an upgrade.
For earlier compilers, you could generate a NaN by TRANSFERing a z'....' constant, or by calling a function (as quick and dirty as could be imagined) such as
function rnan(x)
!dir$ optimize:0
rnan = (x-x)/(x-x)
return
For earlier compilers, you could generate a NaN by TRANSFERing a z'....' constant, or by calling a function (as quick and dirty as could be imagined) such as
function rnan(x)
!dir$ optimize:0
rnan = (x-x)/(x-x)
return
Thanks! This is the obvious way, and it works. It's not very elegant though, and possibly subject to how the compiler handles this. Steve's answer is more in line with what I was looking for; it just turns out that in IVF 10.1 declaring usage ofthe intrinsic module IEEE_ARITHMETIC (through USE,INTRINSIC :: IEEE_ARITHMETIC) does not trigger a compiler error, but the variables and functions Steve mentionned will. It seems they are not declared (or accessible) in this module.
Olivier
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
Version 10.1 included the module as a stub.
I do not recommend using the method here - the compiler is free to optimize that into something unexpected. Use this instead:
! Quiet NAN, double precision.
REAL(8), PARAMETER :: D_QNAN = &
TRANSFER((/ Z'00000000', Z'7FF80000' /),1.0_8)
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
Ah... this makes sense. That's exactly what I was looking for. Thanks!
Olivier
Olivier

Responder
Opciones de temas
- Suscribirse a un feed RSS
- Marcar tema como nuevo
- Marcar tema como leído
- Flotar este Tema para el usuario actual
- Favorito
- Suscribir
- Página de impresión sencilla