fortran66のブログ

fortran について書きます。

IEEE がらみの INTRINSIC MODULE の機能。
イマイチよく分からん。

PRGRAM test
USE, INTRINSIC :: IEEE_ARITHMETIC
USE, INTRINSIC :: IEEE_FEATURES
USE, INTRINSIC :: IEEE_EXCEPTIONS
TYPE (IEEE_FLAG_TYPE)   :: flag_value
TYPE (IEEE_CLASS_TYPE)  :: class_value
TYPE (IEEE_STATUS_TYPE) :: status_value
TYPE (IEEE_ROUND_TYPE)  :: round_value
REAL(4) :: a = -0.0e0
REAL(8) :: d = -0.0d0
REAL(16):: q = -0.0q0
LOGICAL :: Lgradual
!
PRINT *, IEEE_SUPPORT_DATATYPE(a)
PRINT *, IEEE_SUPPORT_DATATYPE(d)
PRINT *, IEEE_SUPPORT_DATATYPE(q)
PRINT *, IEEE_SUPPORT_DENORMAL()
PRINT *, IEEE_SUPPORT_DIVIDE()
PRINT *, IEEE_SUPPORT_INF()
PRINT *, IEEE_SUPPORT_NAN()
PRINT *, IEEE_SUPPORT_ROUNDING(IEEE_NEAREST)
PRINT *, IEEE_SUPPORT_ROUNDING(IEEE_TO_ZERO)
PRINT *, IEEE_SUPPORT_ROUNDING(IEEE_UP)
PRINT *, IEEE_SUPPORT_ROUNDING(IEEE_DOWN)
PRINT *, IEEE_SUPPORT_ROUNDING(IEEE_OTHER)
PRINT *, IEEE_SUPPORT_SQRT(a)
PRINT *, IEEE_SUPPORT_SQRT(d)
PRINT *, IEEE_SUPPORT_SQRT(q)
PRINT *, IEEE_SUPPORT_STANDARD(a)
PRINT *, IEEE_SUPPORT_STANDARD(d)
PRINT *, IEEE_SUPPORT_STANDARD(q)
PRINT *, IEEE_SUPPORT_UNDERFLOW_CONTROL(a)
PRINT *, IEEE_SUPPORT_UNDERFLOW_CONTROL(d)
PRINT *, IEEE_SUPPORT_UNDERFLOW_CONTROL(q)
!
class_value = IEEE_CLASS(a)
IF (class_value == IEEE_NEGATIVE_ZERO) PRINT *, 'NEGATIVE_ZERO'
class_value = IEEE_CLASS(d)
IF (class_value == IEEE_NEGATIVE_ZERO) PRINT *, 'NEGATIVE_ZERO'
class_value = IEEE_CLASS(q)
IF (class_value == IEEE_NEGATIVE_ZERO) PRINT *, 'NEGATIVE_ZERO'
!
CALL IEEE_GET_ROUNDING_MODE(round_value)
IF (round_value == IEEE_NEAREST) PRINT *, 'NEAREST'
CALL IEEE_SET_ROUNDING_MODE(IEEE_TO_ZERO)
CALL IEEE_GET_ROUNDING_MODE(round_value)
IF (round_value == IEEE_TO_ZERO) PRINT *, 'TO ZERO'
!
CALL IEEE_GET_UNDERFLOW_MODE(Lgradual)
PRINT *, 'Is gradual?', Lgradual
CALL IEEE_SET_UNDERFLOW_MODE(.FALSE.)
CALL IEEE_GET_UNDERFLOW_MODE(Lgradual)
PRINT *, 'Is gradual?', Lgradual
!
CALL IEEE_GET_STATUS(status_value)

STOP
END PROGRAM test

コンパイラ・オプションで IEEE Negative Zero を無効にしているのに、NEGATIVE ZERO が検知される。一方、非正規数の方はコンパイラ・オプションでフラッシュを選ぶと gradual は FALSE になる。