--- /dev/null
+! { dg-do run }
+! { dg-require-effective-target issignaling } */
+! { dg-additional-sources signaling_2_c.c }
+! { dg-additional-options "-w" }
+! the -w option is needed to make cc1 not report a warning for
+! the -fintrinsic-modules-path option passed by ieee.exp
+!
+program test
+ use, intrinsic :: iso_c_binding
+ use, intrinsic :: ieee_arithmetic
+ implicit none
+
+ interface
+ integer(kind=c_int) function isnansf (x) bind(c)
+ import :: c_float, c_int
+ real(kind=c_float), value :: x
+ end function
+
+ integer(kind=c_int) function isnans (x) bind(c)
+ import :: c_double, c_int
+ real(kind=c_double), value :: x
+ end function
+
+ integer(kind=c_int) function isnansl (x) bind(c)
+ import :: c_long_double, c_int
+ real(kind=c_long_double), value :: x
+ end function
+ end interface
+
+ real(kind=c_float) :: x
+ real(kind=c_double) :: y
+ real(kind=c_long_double) :: z
+
+ if (ieee_support_nan(x)) then
+ x = ieee_value(x, ieee_signaling_nan)
+ if (ieee_class(x) /= ieee_signaling_nan) stop 100
+ if (.not. ieee_is_nan(x)) stop 101
+ if (isnansf(x) /= 1) stop 102
+
+ x = ieee_value(x, ieee_quiet_nan)
+ if (ieee_class(x) /= ieee_quiet_nan) stop 103
+ if (.not. ieee_is_nan(x)) stop 104
+ if (isnansf(x) /= 0) stop 105
+ end if
+
+ if (ieee_support_nan(y)) then
+ y = ieee_value(y, ieee_signaling_nan)
+ if (ieee_class(y) /= ieee_signaling_nan) stop 100
+ if (.not. ieee_is_nan(y)) stop 101
+ if (isnans(y) /= 1) stop 102
+
+ y = ieee_value(y, ieee_quiet_nan)
+ if (ieee_class(y) /= ieee_quiet_nan) stop 103
+ if (.not. ieee_is_nan(y)) stop 104
+ if (isnans(y) /= 0) stop 105
+ end if
+
+ if (ieee_support_nan(z)) then
+ z = ieee_value(z, ieee_signaling_nan)
+ if (ieee_class(z) /= ieee_signaling_nan) stop 100
+ if (.not. ieee_is_nan(z)) stop 101
+ if (isnansl(z) /= 1) stop 102
+
+ z = ieee_value(z, ieee_quiet_nan)
+ if (ieee_class(z) /= ieee_quiet_nan) stop 103
+ if (.not. ieee_is_nan(z)) stop 104
+ if (isnansl(z) /= 0) stop 105
+ end if
+
+end program test
! IEEE_VALUE
elemental real(kind=4) function IEEE_VALUE_4(X, CLASS) result(res)
-
real(kind=4), intent(in) :: X
type(IEEE_CLASS_TYPE), intent(in) :: CLASS
- logical flag
-
- select case (CLASS%hidden)
- case (1) ! IEEE_SIGNALING_NAN
- if (ieee_support_halting(ieee_invalid)) then
- call ieee_get_halting_mode(ieee_invalid, flag)
- call ieee_set_halting_mode(ieee_invalid, .false.)
- end if
- res = -1
- res = sqrt(res)
- if (ieee_support_halting(ieee_invalid)) then
- call ieee_set_halting_mode(ieee_invalid, flag)
- end if
- case (2) ! IEEE_QUIET_NAN
- if (ieee_support_halting(ieee_invalid)) then
- call ieee_get_halting_mode(ieee_invalid, flag)
- call ieee_set_halting_mode(ieee_invalid, .false.)
- end if
- res = -1
- res = sqrt(res)
- if (ieee_support_halting(ieee_invalid)) then
- call ieee_set_halting_mode(ieee_invalid, flag)
- end if
- case (3) ! IEEE_NEGATIVE_INF
- if (ieee_support_halting(ieee_overflow)) then
- call ieee_get_halting_mode(ieee_overflow, flag)
- call ieee_set_halting_mode(ieee_overflow, .false.)
- end if
- res = huge(res)
- res = (-res) * res
- if (ieee_support_halting(ieee_overflow)) then
- call ieee_set_halting_mode(ieee_overflow, flag)
- end if
- case (4) ! IEEE_NEGATIVE_NORMAL
- res = -42
- case (5) ! IEEE_NEGATIVE_DENORMAL
- res = -tiny(res)
- res = res / 2
- case (6) ! IEEE_NEGATIVE_ZERO
- res = 0
- res = -res
- case (7) ! IEEE_POSITIVE_ZERO
- res = 0
- case (8) ! IEEE_POSITIVE_DENORMAL
- res = tiny(res)
- res = res / 2
- case (9) ! IEEE_POSITIVE_NORMAL
- res = 42
- case (10) ! IEEE_POSITIVE_INF
- if (ieee_support_halting(ieee_overflow)) then
- call ieee_get_halting_mode(ieee_overflow, flag)
- call ieee_set_halting_mode(ieee_overflow, .false.)
- end if
- res = huge(res)
- res = res * res
- if (ieee_support_halting(ieee_overflow)) then
- call ieee_set_halting_mode(ieee_overflow, flag)
- end if
- case default ! IEEE_OTHER_VALUE, should not happen
- res = 0
- end select
+
+ interface
+ pure real(kind=4) function _gfortrani_ieee_value_helper_4(x)
+ use ISO_C_BINDING, only: C_INT
+ integer(kind=C_INT), value :: x
+ end function
+ end interface
+
+ res = _gfortrani_ieee_value_helper_4(CLASS%hidden)
end function
elemental real(kind=8) function IEEE_VALUE_8(X, CLASS) result(res)
-
real(kind=8), intent(in) :: X
type(IEEE_CLASS_TYPE), intent(in) :: CLASS
- logical flag
-
- select case (CLASS%hidden)
- case (1) ! IEEE_SIGNALING_NAN
- if (ieee_support_halting(ieee_invalid)) then
- call ieee_get_halting_mode(ieee_invalid, flag)
- call ieee_set_halting_mode(ieee_invalid, .false.)
- end if
- res = -1
- res = sqrt(res)
- if (ieee_support_halting(ieee_invalid)) then
- call ieee_set_halting_mode(ieee_invalid, flag)
- end if
- case (2) ! IEEE_QUIET_NAN
- if (ieee_support_halting(ieee_invalid)) then
- call ieee_get_halting_mode(ieee_invalid, flag)
- call ieee_set_halting_mode(ieee_invalid, .false.)
- end if
- res = -1
- res = sqrt(res)
- if (ieee_support_halting(ieee_invalid)) then
- call ieee_set_halting_mode(ieee_invalid, flag)
- end if
- case (3) ! IEEE_NEGATIVE_INF
- if (ieee_support_halting(ieee_overflow)) then
- call ieee_get_halting_mode(ieee_overflow, flag)
- call ieee_set_halting_mode(ieee_overflow, .false.)
- end if
- res = huge(res)
- res = (-res) * res
- if (ieee_support_halting(ieee_overflow)) then
- call ieee_set_halting_mode(ieee_overflow, flag)
- end if
- case (4) ! IEEE_NEGATIVE_NORMAL
- res = -42
- case (5) ! IEEE_NEGATIVE_DENORMAL
- res = -tiny(res)
- res = res / 2
- case (6) ! IEEE_NEGATIVE_ZERO
- res = 0
- res = -res
- case (7) ! IEEE_POSITIVE_ZERO
- res = 0
- case (8) ! IEEE_POSITIVE_DENORMAL
- res = tiny(res)
- res = res / 2
- case (9) ! IEEE_POSITIVE_NORMAL
- res = 42
- case (10) ! IEEE_POSITIVE_INF
- if (ieee_support_halting(ieee_overflow)) then
- call ieee_get_halting_mode(ieee_overflow, flag)
- call ieee_set_halting_mode(ieee_overflow, .false.)
- end if
- res = huge(res)
- res = res * res
- if (ieee_support_halting(ieee_overflow)) then
- call ieee_set_halting_mode(ieee_overflow, flag)
- end if
- case default ! IEEE_OTHER_VALUE, should not happen
- res = 0
- end select
+
+ interface
+ pure real(kind=8) function _gfortrani_ieee_value_helper_8(x)
+ use ISO_C_BINDING, only: C_INT
+ integer(kind=C_INT), value :: x
+ end function
+ end interface
+
+ res = _gfortrani_ieee_value_helper_8(CLASS%hidden)
end function
#ifdef HAVE_GFC_REAL_10
elemental real(kind=10) function IEEE_VALUE_10(X, CLASS) result(res)
-
real(kind=10), intent(in) :: X
type(IEEE_CLASS_TYPE), intent(in) :: CLASS
- logical flag
-
- select case (CLASS%hidden)
- case (1) ! IEEE_SIGNALING_NAN
- if (ieee_support_halting(ieee_invalid)) then
- call ieee_get_halting_mode(ieee_invalid, flag)
- call ieee_set_halting_mode(ieee_invalid, .false.)
- end if
- res = -1
- res = sqrt(res)
- if (ieee_support_halting(ieee_invalid)) then
- call ieee_set_halting_mode(ieee_invalid, flag)
- end if
- case (2) ! IEEE_QUIET_NAN
- if (ieee_support_halting(ieee_invalid)) then
- call ieee_get_halting_mode(ieee_invalid, flag)
- call ieee_set_halting_mode(ieee_invalid, .false.)
- end if
- res = -1
- res = sqrt(res)
- if (ieee_support_halting(ieee_invalid)) then
- call ieee_set_halting_mode(ieee_invalid, flag)
- end if
- case (3) ! IEEE_NEGATIVE_INF
- if (ieee_support_halting(ieee_overflow)) then
- call ieee_get_halting_mode(ieee_overflow, flag)
- call ieee_set_halting_mode(ieee_overflow, .false.)
- end if
- res = huge(res)
- res = (-res) * res
- if (ieee_support_halting(ieee_overflow)) then
- call ieee_set_halting_mode(ieee_overflow, flag)
- end if
- case (4) ! IEEE_NEGATIVE_NORMAL
- res = -42
- case (5) ! IEEE_NEGATIVE_DENORMAL
- res = -tiny(res)
- res = res / 2
- case (6) ! IEEE_NEGATIVE_ZERO
- res = 0
- res = -res
- case (7) ! IEEE_POSITIVE_ZERO
- res = 0
- case (8) ! IEEE_POSITIVE_DENORMAL
- res = tiny(res)
- res = res / 2
- case (9) ! IEEE_POSITIVE_NORMAL
- res = 42
- case (10) ! IEEE_POSITIVE_INF
- if (ieee_support_halting(ieee_overflow)) then
- call ieee_get_halting_mode(ieee_overflow, flag)
- call ieee_set_halting_mode(ieee_overflow, .false.)
- end if
- res = huge(res)
- res = res * res
- if (ieee_support_halting(ieee_overflow)) then
- call ieee_set_halting_mode(ieee_overflow, flag)
- end if
- case default ! IEEE_OTHER_VALUE, should not happen
- res = 0
- end select
+
+ interface
+ pure real(kind=10) function _gfortrani_ieee_value_helper_10(x)
+ use ISO_C_BINDING, only: C_INT
+ integer(kind=C_INT), value :: x
+ end function
+ end interface
+
+ res = _gfortrani_ieee_value_helper_10(CLASS%hidden)
end function
#endif
#ifdef HAVE_GFC_REAL_16
elemental real(kind=16) function IEEE_VALUE_16(X, CLASS) result(res)
-
real(kind=16), intent(in) :: X
type(IEEE_CLASS_TYPE), intent(in) :: CLASS
- logical flag
-
- select case (CLASS%hidden)
- case (1) ! IEEE_SIGNALING_NAN
- if (ieee_support_halting(ieee_invalid)) then
- call ieee_get_halting_mode(ieee_invalid, flag)
- call ieee_set_halting_mode(ieee_invalid, .false.)
- end if
- res = -1
- res = sqrt(res)
- if (ieee_support_halting(ieee_invalid)) then
- call ieee_set_halting_mode(ieee_invalid, flag)
- end if
- case (2) ! IEEE_QUIET_NAN
- if (ieee_support_halting(ieee_invalid)) then
- call ieee_get_halting_mode(ieee_invalid, flag)
- call ieee_set_halting_mode(ieee_invalid, .false.)
- end if
- res = -1
- res = sqrt(res)
- if (ieee_support_halting(ieee_invalid)) then
- call ieee_set_halting_mode(ieee_invalid, flag)
- end if
- case (3) ! IEEE_NEGATIVE_INF
- if (ieee_support_halting(ieee_overflow)) then
- call ieee_get_halting_mode(ieee_overflow, flag)
- call ieee_set_halting_mode(ieee_overflow, .false.)
- end if
- res = huge(res)
- res = (-res) * res
- if (ieee_support_halting(ieee_overflow)) then
- call ieee_set_halting_mode(ieee_overflow, flag)
- end if
- case (4) ! IEEE_NEGATIVE_NORMAL
- res = -42
- case (5) ! IEEE_NEGATIVE_DENORMAL
- res = -tiny(res)
- res = res / 2
- case (6) ! IEEE_NEGATIVE_ZERO
- res = 0
- res = -res
- case (7) ! IEEE_POSITIVE_ZERO
- res = 0
- case (8) ! IEEE_POSITIVE_DENORMAL
- res = tiny(res)
- res = res / 2
- case (9) ! IEEE_POSITIVE_NORMAL
- res = 42
- case (10) ! IEEE_POSITIVE_INF
- if (ieee_support_halting(ieee_overflow)) then
- call ieee_get_halting_mode(ieee_overflow, flag)
- call ieee_set_halting_mode(ieee_overflow, .false.)
- end if
- res = huge(res)
- res = res * res
- if (ieee_support_halting(ieee_overflow)) then
- call ieee_set_halting_mode(ieee_overflow, flag)
- end if
- case default ! IEEE_OTHER_VALUE, should not happen
- res = 0
- end select
+
+ interface
+ pure real(kind=16) function _gfortrani_ieee_value_helper_16(x)
+ use ISO_C_BINDING, only: C_INT
+ integer(kind=C_INT), value :: x
+ end function
+ end interface
+
+ res = _gfortrani_ieee_value_helper_16(CLASS%hidden)
end function
#endif