summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/ieee/ieee_6.f90
blob: 96ceaff09b00a8fc2da42e4f2cd1b05c479b98aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
! { dg-do run }
!
! This test will fail on older x86_64 glibc (< 2.20), due to this bug:
! https://sourceware.org/bugzilla/show_bug.cgi?id=16198
! We usually won't see it anyway, because on such systems x86_64 assembly
! (libgfortran/config/fpu-387.h) is used.
!
  use :: ieee_arithmetic
  implicit none

  type(ieee_status_type) :: s1, s2
  logical :: flags(5), halt(5), haltworks
  type(ieee_round_type) :: mode
  real :: x

  ! Test IEEE_GET_STATUS and IEEE_SET_STATUS

  call ieee_set_flag(ieee_all, .false.)
  call ieee_set_rounding_mode(ieee_down)
  call ieee_set_halting_mode(ieee_all, .false.)
  haltworks = ieee_support_halting(ieee_overflow)

  call ieee_get_status(s1)
  call ieee_set_status(s1)

  call ieee_get_flag(ieee_all, flags)
  if (any(flags)) STOP 1
  call ieee_get_rounding_mode(mode)
  if (mode /= ieee_down) STOP 2
  call ieee_get_halting_mode(ieee_all, halt)
  if (any(halt)) STOP 3

  call ieee_set_rounding_mode(ieee_to_zero)
  call ieee_set_flag(ieee_underflow, .true.)
  call ieee_set_halting_mode(ieee_overflow, .true.)
  x = -1
  x = sqrt(x)
  if (.not. ieee_is_nan(x)) STOP 4

  call ieee_get_status(s2)

  call ieee_get_flag(ieee_all, flags)
  if (.not. (all(flags .eqv. [.false.,.false.,.true.,.true.,.false.]) &
             .or. all(flags .eqv. [.false.,.false.,.true.,.true.,.true.]) &
             .or. all(flags .eqv. [.false.,.false.,.true.,.false.,.false.]) &
             .or. all(flags .eqv. [.false.,.false.,.true.,.false.,.true.]))) STOP 5
  call ieee_get_rounding_mode(mode)
  if (mode /= ieee_to_zero) STOP 6
  call ieee_get_halting_mode(ieee_all, halt)
  if ((haltworks .and. .not. halt(1)) .or. any(halt(2:))) STOP 7

  call ieee_set_status(s2)

  call ieee_get_flag(ieee_all, flags)
  if (.not. (all(flags .eqv. [.false.,.false.,.true.,.true.,.false.]) &
             .or. all(flags .eqv. [.false.,.false.,.true.,.true.,.true.]) &
             .or. all(flags .eqv. [.false.,.false.,.true.,.false.,.false.]) &
             .or. all(flags .eqv. [.false.,.false.,.true.,.false.,.true.]))) STOP 8
  call ieee_get_rounding_mode(mode)
  if (mode /= ieee_to_zero) STOP 9
  call ieee_get_halting_mode(ieee_all, halt)
  if ((haltworks .and. .not. halt(1)) .or. any(halt(2:))) STOP 10

  call ieee_set_status(s1)

  call ieee_get_flag(ieee_all, flags)
  if (any(flags)) STOP 11
  call ieee_get_rounding_mode(mode)
  if (mode /= ieee_down) STOP 12
  call ieee_get_halting_mode(ieee_all, halt)
  if (any(halt)) STOP 13

  call ieee_set_status(s2)

  call ieee_get_flag(ieee_all, flags)
  if (.not. (all(flags .eqv. [.false.,.false.,.true.,.true.,.false.]) &
             .or. all(flags .eqv. [.false.,.false.,.true.,.true.,.true.]) &
             .or. all(flags .eqv. [.false.,.false.,.true.,.false.,.false.]) &
             .or. all(flags .eqv. [.false.,.false.,.true.,.false.,.true.]))) STOP 14
  call ieee_get_rounding_mode(mode)
  if (mode /= ieee_to_zero) STOP 15
  call ieee_get_halting_mode(ieee_all, halt)
  if ((haltworks .and. .not. halt(1)) .or. any(halt(2:))) STOP 16

end