File: fold-nearest.f90

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (88 lines) | stat: -rw-r--r-- 4,893 bytes parent folder | download | duplicates (5)
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
86
87
88
! RUN: %python %S/test_folding.py %s %flang_fc1
! Tests folding of NEAREST() and its relatives
module m1
  real, parameter :: minSubnormal = 1.e-45
  logical, parameter :: test_1 = nearest(0., 1.) == minSubnormal
  logical, parameter :: test_2 = nearest(minSubnormal, -1.) == 0
  logical, parameter :: test_3 = nearest(1., 1.) == 1.0000001
  logical, parameter :: test_4 = nearest(1.0000001, -1.) == 1
  !WARN: warning: NEAREST intrinsic folding overflow
  real, parameter :: inf = nearest(huge(1.), 1.)
  !WARN: warning: NEAREST intrinsic folding: bad argument
  logical, parameter :: test_5 = nearest(inf, 1.) == inf
  !WARN: warning: NEAREST intrinsic folding: bad argument
  logical, parameter :: test_6 = nearest(-inf, -1.) == -inf
  logical, parameter :: test_7 = nearest(1.9999999, 1.) == 2.
  logical, parameter :: test_8 = nearest(2., -1.) == 1.9999999
  logical, parameter :: test_9 = nearest(1.9999999999999999999_10, 1.) == 2._10
  logical, parameter :: test_10 = nearest(-1., 1.) == -.99999994
  logical, parameter :: test_11 = nearest(-1., -2.) == -1.0000001
  real, parameter :: negZero = sign(0., -1.)
  logical, parameter :: test_12 = nearest(negZero, 1.) == minSubnormal
  logical, parameter :: test_13 = nearest(negZero, -1.) == -minSubnormal
  !WARN: warning: NEAREST: S argument is zero
  logical, parameter :: test_14 = nearest(0., negZero) == -minSubnormal
  !WARN: warning: NEAREST: S argument is zero
  logical, parameter :: test_15 = nearest(negZero, 0.) == minSubnormal
end module

module m2
  use ieee_arithmetic, only: ieee_next_after
  real, parameter :: minSubnormal = 1.e-45
  logical, parameter :: test_0 = ieee_next_after(0., 0.) == 0.
  logical, parameter :: test_1 = ieee_next_after(0., 1.) == minSubnormal
  logical, parameter :: test_2 = ieee_next_after(minSubnormal, -1.) == 0
  logical, parameter :: test_3 = ieee_next_after(1., 2.) == 1.0000001
  logical, parameter :: test_4 = ieee_next_after(1.0000001, -1.) == 1
  !WARN: warning: division by zero
  real, parameter :: inf = 1. / 0.
  logical, parameter :: test_5 = ieee_next_after(inf, inf) == inf
  logical, parameter :: test_6 = ieee_next_after(inf, -inf) == inf
  logical, parameter :: test_7 = ieee_next_after(-inf, inf) == -inf
  logical, parameter :: test_8 = ieee_next_after(-inf, -1.) == -inf
  logical, parameter :: test_9 = ieee_next_after(1.9999999, 3.) == 2.
  logical, parameter :: test_10 = ieee_next_after(2., 1.) == 1.9999999
  logical, parameter :: test_11 = ieee_next_after(1.9999999999999999999_10, 3.) == 2._10
  logical, parameter :: test_12 = ieee_next_after(1., 1.) == 1.
  !WARN: warning: invalid argument on division
  real, parameter :: nan = 0. / 0.
  !WARN: warning: IEEE_NEXT_AFTER intrinsic folding: bad argument
  real, parameter :: x13 = ieee_next_after(nan, nan)
  logical, parameter :: test_13 = .not. (x13 == x13)
  !WARN: warning: IEEE_NEXT_AFTER intrinsic folding: bad argument
  real, parameter :: x14 = ieee_next_after(nan, 0.)
  logical, parameter :: test_14 = .not. (x14 == x14)
end module

module m3
  use ieee_arithmetic, only: ieee_next_up, ieee_next_down
  real(kind(0.d0)), parameter :: minSubnormal = 5.d-324
  logical, parameter :: test_1 = ieee_next_up(0.d0) == minSubnormal
  logical, parameter :: test_2 = ieee_next_down(0.d0) == -minSubnormal
  logical, parameter :: test_3 = ieee_next_up(1.d0) == 1.0000000000000002d0
  logical, parameter :: test_4 = ieee_next_down(1.0000000000000002d0) == 1.d0
  !WARN: warning: division by zero
  real(kind(0.d0)), parameter :: inf = 1.d0 / 0.d0
  !WARN: warning: IEEE_NEXT_UP intrinsic folding overflow
  logical, parameter :: test_5 = ieee_next_up(huge(0.d0)) == inf
  !WARN: warning: IEEE_NEXT_DOWN intrinsic folding overflow
  logical, parameter :: test_6 = ieee_next_down(-huge(0.d0)) == -inf
  !WARN: warning: IEEE_NEXT_UP intrinsic folding: bad argument
  logical, parameter :: test_7 = ieee_next_up(inf) == inf
  !WARN: warning: IEEE_NEXT_DOWN intrinsic folding: bad argument
  logical, parameter :: test_8 = ieee_next_down(inf) == inf
  !WARN: warning: IEEE_NEXT_UP intrinsic folding: bad argument
  logical, parameter :: test_9 = ieee_next_up(-inf) == -inf
  !WARN: warning: IEEE_NEXT_DOWN intrinsic folding: bad argument
  logical, parameter :: test_10 = ieee_next_down(-inf) == -inf
  logical, parameter :: test_11 = ieee_next_up(1.9999999999999997d0) == 2.d0
  logical, parameter :: test_12 = ieee_next_down(2.d0) == 1.9999999999999997d0
  !WARN: warning: invalid argument on division
  real(kind(0.d0)), parameter :: nan = 0.d0 / 0.d0
  !WARN: warning: IEEE_NEXT_UP intrinsic folding: bad argument
  real(kind(0.d0)), parameter :: x13 = ieee_next_up(nan)
  logical, parameter :: test_13 = .not. (x13 == x13)
  !WARN: warning: IEEE_NEXT_DOWN intrinsic folding: bad argument
  real(kind(0.d0)), parameter :: x14 = ieee_next_down(nan)
  logical, parameter :: test_14 = .not. (x14 == x14)
end module