OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [testsuite/] [gfortran.dg/] [int_1.f90] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 149 jeremybenn
! { dg-do run }
2
!
3
! 13.7.53    INT(A [, KIND])
4
!
5
! Description.  Convert to integer type.
6
! Class.       Elemental function.
7
! Arguments.
8
!    A               shall be of type integer, real, or complex,
9
!                    or a boz-literal-constant .
10
!    KIND (optional) shall be a scalar integer initialization expression.
11
!
12
! Result Characteristics. Integer. If KIND is present, the kind type
13
!    parameter is that specified by the value of KIND; otherwise, the
14
!    kind type parameter is that of default integer type.
15
!
16
! Result Value.
17
!
18
!    Case (1):  If A is of type integer, INT (A) = A.
19
!
20
!    Case (2):  If A is of type real, there are two cases:
21
!      (a) if |A| < 1, INT (A) has the value 0
22
!      (b) if |A| .ge. 1, INT (A) is the integer whose magnitude is the
23
!          largest integer that does not exceed the magnitude of A and
24
!          whose sign is the same as the sign of A.
25
!
26
!    Case (3):  If A is of type complex, INT(A) = INT(REAL(A, KIND(A))).
27
!
28
!    Case (4):  If A is a boz-literal-constant, it is treated as if it were
29
!               an int-literal-constant with a kind-param that specifies the
30
!               representation method with the largest decimal exponent range
31
!               supported by the processor.
32
!
33
!    Example. INT (­3.7) has the value ­3.
34
!
35
module mykinds
36
   integer, parameter :: ik1 = selected_int_kind(2)
37
   integer, parameter :: ik2 = selected_int_kind(4)
38
   integer, parameter :: ik4 = selected_int_kind(9)
39
   integer, parameter :: ik8 = selected_int_kind(18)
40
   integer, parameter :: sp = selected_real_kind(6,30)
41
   integer, parameter :: dp = selected_real_kind(15,300)
42
   integer, parameter :: ck = kind('a')
43
end module mykinds
44
 
45
program test_int
46
 
47
   use mykinds
48
 
49
   integer(ik1) i1
50
   integer(ik2) i2
51
   integer(ik4) i4
52
   integer(ik8) i8
53
   real(sp) r4
54
   real(dp) r8
55
   complex(sp) c4
56
   complex(dp) c8
57
   !
58
   ! Case 1
59
   !
60
   i1 = int(-3)
61
   i2 = int(-3)
62
   i4 = int(-3)
63
   i8 = int(-3)
64
   if (i1 /= -3_ik1 .or. i2 /= -3_ik2) call abort
65
   if (i4 /= -3_ik4 .or. i8 /= -3_ik8) call abort
66
 
67
   i1 = int(5,  ik1)
68
   i2 = int(i1, ik2)
69
   i4 = int(i1, ik4)
70
   i8 = int(i1, ik8)
71
   if (i1 /= 5_ik1 .or. i2 /= 5_ik2) call abort
72
   if (i4 /= 5_ik4 .or. i8 /= 5_ik8) call abort
73
 
74
   i8 = int(10, ik8)
75
   i1 = int(i8, ik1)
76
   i2 = int(i8, ik2)
77
   i4 = int(i8, ik4)
78
   if (i1 /= 10_ik1 .or. i2 /= 10_ik2) call abort
79
   if (i4 /= 10_ik4 .or. i8 /= 10_ik8) call abort
80
   !
81
   ! case 2(b)
82
   !
83
   r4 = -3.7_sp
84
   i1 = int(r4,  ik1)
85
   i2 = int(r4, ik2)
86
   i4 = int(r4, ik4)
87
   i8 = int(r4, ik8)
88
   if (i1 /= -3_ik1 .or. i2 /= -3_ik2) call abort
89
   if (i4 /= -3_ik4 .or. i8 /= -3_ik8) call abort
90
 
91
   r8 = -3.7_dp
92
   i1 = int(r8,  ik1)
93
   i2 = int(r8, ik2)
94
   i4 = int(r8, ik4)
95
   i8 = int(r8, ik8)
96
   if (i1 /= -3_ik1 .or. i2 /= -3_ik2) call abort
97
   if (i4 /= -3_ik4 .or. i8 /= -3_ik8) call abort
98
   !
99
   ! Case 2(a)
100
   !
101
   r4 = -3.7E-1_sp
102
   i1 = int(r4, ik1)
103
   i2 = int(r4, ik2)
104
   i4 = int(r4, ik4)
105
   i8 = int(r4, ik8)
106
   if (i1 /= 0_ik1 .or. i2 /= 0_ik2) call abort
107
   if (i4 /= 0_ik4 .or. i8 /= 0_ik8) call abort
108
 
109
   r8 = -3.7E-1_dp
110
   i1 = int(r8, ik1)
111
   i2 = int(r8, ik2)
112
   i4 = int(r8, ik4)
113
   i8 = int(r8, ik8)
114
   if (i1 /= 0_ik1 .or. i2 /= 0_ik2) call abort
115
   if (i4 /= 0_ik4 .or. i8 /= 0_ik8) call abort
116
   !
117
   ! Case 3
118
   !
119
   c4 = (-3.7E-1_sp,3.7E-1_sp)
120
   i1 = int(c4, ik1)
121
   i2 = int(c4, ik2)
122
   i4 = int(c4, ik4)
123
   i8 = int(c4, ik8)
124
   if (i1 /= 0_ik1 .or. i2 /= 0_ik2) call abort
125
   if (i4 /= 0_ik4 .or. i8 /= 0_ik8) call abort
126
 
127
   c8 = (-3.7E-1_dp,3.7E-1_dp)
128
   i1 = int(c8, ik1)
129
   i2 = int(c8, ik2)
130
   i4 = int(c8, ik4)
131
   i8 = int(c8, ik8)
132
   if (i1 /= 0_ik1 .or. i2 /= 0_ik2) call abort
133
   if (i4 /= 0_ik4 .or. i8 /= 0_ik8) call abort
134
 
135
   c4 = (-3.7_sp,3.7_sp)
136
   i1 = int(c4, ik1)
137
   i2 = int(c4, ik2)
138
   i4 = int(c4, ik4)
139
   i8 = int(c4, ik8)
140
   if (i1 /= -3_ik1 .or. i2 /= -3_ik2) call abort
141
   if (i4 /= -3_ik4 .or. i8 /= -3_ik8) call abort
142
 
143
   c8 = (3.7_dp,3.7_dp)
144
   i1 = int(c8, ik1)
145
   i2 = int(c8, ik2)
146
   i4 = int(c8, ik4)
147
   i8 = int(c8, ik8)
148
   if (i1 /= 3_ik1 .or. i2 /= 3_ik2) call abort
149
   if (i4 /= 3_ik4 .or. i8 /= 3_ik8) call abort
150
   !
151
   ! Case 4
152
   !
153
   i1 = int(b'0011', ik1)
154
   i2 = int(b'0011', ik2)
155
   i4 = int(b'0011', ik4)
156
   i8 = int(b'0011', ik8)
157
   if (i1 /= 3_ik1 .or. i2 /= 3_ik2) call abort
158
   if (i4 /= 3_ik4 .or. i8 /= 3_ik8) call abort
159
   i1 = int(o'0011', ik1)
160
   i2 = int(o'0011', ik2)
161
   i4 = int(o'0011', ik4)
162
   i8 = int(o'0011', ik8)
163
   if (i1 /= 9_ik1 .or. i2 /= 9_ik2) call abort
164
   if (i4 /= 9_ik4 .or. i8 /= 9_ik8) call abort
165
   i1 = int(z'0011', ik1)
166
   i2 = int(z'0011', ik2)
167
   i4 = int(z'0011', ik4)
168
   i8 = int(z'0011', ik8)
169
   if (i1 /= 17_ik1 .or. i2 /= 17_ik2) call abort
170
   if (i4 /= 17_ik4 .or. i8 /= 17_ik8) call abort
171
 
172
end program test_int
173
 
174
! { dg-final { cleanup-modules "mykinds" } }

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.