1 |
#Region "Microsoft.VisualBasic::05e59390398e54608cf7ea8de00ebadf, Microsoft.VisualBasic.Core\Language\Value\Numeric\int.vb"
|
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 |
#End Region
|
45 |
|
46 |
Imports System.Runtime.CompilerServices
|
47 |
Imports Microsoft.VisualBasic.ApplicationServices
|
48 |
Imports Microsoft.VisualBasic.Language.UnixBash.FileSystem
|
49 |
|
50 |
Namespace Language
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
Public Class int : Inherits Value(Of Integer)
|
56 |
Implements IComparable
|
57 |
Implements IComparable(Of Integer)
|
58 |
Implements IEquatable(Of Integer)
|
59 |
Implements IFormattable
|
60 |
|
61 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
62 |
Sub New(Optional x% = Scan0)
|
63 |
Value = x
|
64 |
End Sub
|
65 |
|
66 |
Sub New()
|
67 |
Call Me.New(0)
|
68 |
End Sub
|
69 |
|
70 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
71 |
Public Overrides Function ToString() As String
|
72 |
Return Value
|
73 |
End Function
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
Public Function CompareTo(obj As Object) As Integer Implements IComparable.CompareTo
|
81 |
Dim type As Type = obj.GetType
|
82 |
|
83 |
If type.Equals(GetType(Integer)) Then
|
84 |
Return Value.CompareTo(DirectCast(obj, Integer))
|
85 |
ElseIf type.Equals(GetType(int)) Then
|
86 |
Return Value.CompareTo(DirectCast(obj, int).Value)
|
87 |
Else
|
88 |
Throw New Exception($"Miss-match of type: {GetType(int).FullName} --> {type.FullName}")
|
89 |
End If
|
90 |
End Function
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
Public Shared Operator <(n As Integer, x As int) As int
|
100 |
If n >= x.Value Then
|
101 |
Return New int(Integer.MaxValue)
|
102 |
Else
|
103 |
Return x
|
104 |
End If
|
105 |
End Operator
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
114 |
Public Shared Operator <(x As int, n As Integer) As Boolean
|
115 |
Return x.Value < n
|
116 |
End Operator
|
117 |
|
118 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
119 |
Public Shared Operator <(n As Double, x As int) As Boolean
|
120 |
Return n < x.Value
|
121 |
End Operator
|
122 |
|
123 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
124 |
Public Shared Operator >(n As Double, x As int) As Boolean
|
125 |
Return n > x.Value
|
126 |
End Operator
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
135 |
Public Shared Operator >(x As int, n As Integer) As Boolean
|
136 |
Return x.Value > n
|
137 |
End Operator
|
138 |
|
139 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
140 |
Public Overloads Shared Operator <=(x As int, n As Integer) As Boolean
|
141 |
Return x.Value <= n
|
142 |
End Operator
|
143 |
|
144 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
145 |
Public Overloads Shared Operator >=(x As int, n As Integer) As Boolean
|
146 |
Return x.Value >= n
|
147 |
End Operator
|
148 |
|
149 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
150 |
Public Shared Operator >(n As Integer, x As int) As int
|
151 |
Return x
|
152 |
End Operator
|
153 |
|
154 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
155 |
Public Overloads Shared Operator -(x As int, n As Integer) As int
|
156 |
x.Value -= n
|
157 |
Return x
|
158 |
End Operator
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
167 |
Public Overloads Shared Operator -(x%, n As int) As Integer
|
168 |
Return x - n.Value
|
169 |
End Operator
|
170 |
|
171 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
172 |
Public Shared Operator /(x As int, b As Integer) As Double
|
173 |
Return x.Value / b
|
174 |
End Operator
|
175 |
|
176 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
177 |
Public Shared Operator /(x As Integer, b As int) As Double
|
178 |
Return x / b.Value
|
179 |
End Operator
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
187 |
Public Overloads Shared Widening Operator CType(n As Integer) As int
|
188 |
Return New int(n)
|
189 |
End Operator
|
190 |
|
191 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
192 |
Public Overloads Shared Narrowing Operator CType(n As int) As Double
|
193 |
Return CDbl(n.Value)
|
194 |
End Operator
|
195 |
|
196 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
197 |
Public Overloads Shared Narrowing Operator CType(n As int) As Integer
|
198 |
Return n.Value
|
199 |
End Operator
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
Public Overloads Shared Operator +(x As int) As Integer
|
208 |
Dim i As Integer = x.Value
|
209 |
x.Value += 1
|
210 |
Return i
|
211 |
End Operator
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
对于<see cref="int"/>类型而言,其更加侧重于迭代器中的位移,所以这个加法运算是符合
|
217 |
```vbnet
|
218 |
x += n
|
219 |
```
|
220 |
|
221 |
但是对于<see cref="float"/>类型而言,其更加侧重于模型计算,所以其加法不符合上述的语法,
|
222 |
不会修改源变量的值,返回的是一个单纯的<see cref="Double"/>值类型
|
223 |
|
224 |
|
225 |
<param name="n%"></param>
|
226 |
|
227 |
Public Overloads Shared Operator +(x As int, n%) As int
|
228 |
x.Value += n
|
229 |
Return x
|
230 |
End Operator
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
Public Shared Operator >(source As IEnumerable, handle As int) As Boolean
|
237 |
Dim file As FileHandle = FileHandles.__getHandle(handle.Value)
|
238 |
Return IOHandler.DefaultHandle()(source, file.FileName, file.encoding)
|
239 |
End Operator
|
240 |
|
241 |
Public Shared Operator <(source As IEnumerable, handle As int) As Boolean
|
242 |
Throw New NotSupportedException
|
243 |
End Operator
|
244 |
|
245 |
|
246 |
p的值增加x,然后返回之前的值
|
247 |
|
248 |
<param name="p"></param>
|
249 |
|
250 |
|
251 |
Public Shared Operator <<(p As int, x%) As Integer
|
252 |
Dim i As Integer = p.Value
|
253 |
p.Value += x
|
254 |
Return i
|
255 |
End Operator
|
256 |
|
257 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
258 |
Public Function CompareTo(other As Integer) As Integer Implements IComparable(Of Integer).CompareTo
|
259 |
Return Value.CompareTo(other)
|
260 |
End Function
|
261 |
|
262 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
263 |
Public Overloads Function Equals(other As Integer) As Boolean Implements IEquatable(Of Integer).Equals
|
264 |
Return Value.Equals(other)
|
265 |
End Function
|
266 |
|
267 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
268 |
Public Overloads Function ToString(format As String, formatProvider As IFormatProvider) As String Implements IFormattable.ToString
|
269 |
Return Value.ToString(format, formatProvider)
|
270 |
End Function
|
271 |
End Class
|
272 |
End Namespace
|