1 | ' Classes/System/Math.ab
|
---|
2 |
|
---|
3 | #require <Classes/ActiveBasic/Math/Math.ab>
|
---|
4 |
|
---|
5 | Namespace System
|
---|
6 |
|
---|
7 | Class Math
|
---|
8 | Public
|
---|
9 | Static Function E() As Double
|
---|
10 | return 2.7182818284590452354
|
---|
11 | End Function
|
---|
12 | /*
|
---|
13 | Static Function PI() As Double
|
---|
14 | return _System_PI
|
---|
15 | End Function
|
---|
16 | */
|
---|
17 | Static Function Abs(value As Double) As Double
|
---|
18 | SetQWord(VarPtr(Abs), GetQWord(VarPtr(value)) And &h7fffffffffffffff)
|
---|
19 | End Function
|
---|
20 |
|
---|
21 | Static Function Abs(value As Single) As Single
|
---|
22 | SetDWord(VarPtr(Abs), GetDWord(VarPtr(value)) And &h7fffffff)
|
---|
23 | End Function
|
---|
24 |
|
---|
25 | Static Function Abs(value As SByte) As SByte
|
---|
26 | If value<0 Then
|
---|
27 | return -value
|
---|
28 | Else
|
---|
29 | return value
|
---|
30 | End If
|
---|
31 | End Function
|
---|
32 |
|
---|
33 | Static Function Abs(value As Integer) As Integer
|
---|
34 | If value<0 Then
|
---|
35 | return -value
|
---|
36 | Else
|
---|
37 | return value
|
---|
38 | End If
|
---|
39 | End Function
|
---|
40 |
|
---|
41 | Static Function Abs(value As Long) As Long
|
---|
42 | If value<0 Then
|
---|
43 | return -value
|
---|
44 | Else
|
---|
45 | return value
|
---|
46 | End If
|
---|
47 | End Function
|
---|
48 |
|
---|
49 | Static Function Abs(value As Int64) As Int64
|
---|
50 | If value<0 Then
|
---|
51 | return -value
|
---|
52 | Else
|
---|
53 | return value
|
---|
54 | End If
|
---|
55 | End Function
|
---|
56 |
|
---|
57 | Static Function Acos(x As Double) As Double
|
---|
58 | Acos = ActiveBasic.Math.Acos(x)
|
---|
59 | End Function
|
---|
60 |
|
---|
61 | Static Function Asin(x As Double) As Double
|
---|
62 | Asin = ActiveBasic.Math.Asin(x)
|
---|
63 | End Function
|
---|
64 |
|
---|
65 | Static Function Atan(x As Double) As Double
|
---|
66 | Atan = ActiveBasic.Math.Atan(x)
|
---|
67 | End Function
|
---|
68 |
|
---|
69 | Static Function Atan2(y As Double, x As Double) As Double
|
---|
70 | Atan2 = ActiveBasic.Math.Atan2(y, x)
|
---|
71 | End Function
|
---|
72 |
|
---|
73 | Static Function BigMul(x As Long, y As Long) As Int64
|
---|
74 | Return (x As Int64) * y
|
---|
75 | End Function
|
---|
76 |
|
---|
77 | Static Function Ceiling(x As Double) As Long
|
---|
78 | Ceiling = Floor(x)
|
---|
79 | If Ceiling <> x Then
|
---|
80 | Ceiling++
|
---|
81 | End If
|
---|
82 | End Function
|
---|
83 |
|
---|
84 | Static Function Cos(x As Double) As Double
|
---|
85 | Cos = ActiveBasic.Math.Cos(x)
|
---|
86 | End Function
|
---|
87 |
|
---|
88 | Static Function Cosh(value As Double) As Double
|
---|
89 | Dim t = Math.Exp(value)
|
---|
90 | Return (t + 1 / t) * 0.5
|
---|
91 | End Function
|
---|
92 |
|
---|
93 | Static Function DivRem(x As Long, y As Long, ByRef ret As Long) As Long
|
---|
94 | ret = x Mod y
|
---|
95 | Return x \ y
|
---|
96 | End Function
|
---|
97 |
|
---|
98 | Static Function DivRem(x As Int64, y As Int64, ByRef ret As Int64) As Int64
|
---|
99 | DivRem = x \ y
|
---|
100 | ret = x - (DivRem) * y
|
---|
101 | End Function
|
---|
102 |
|
---|
103 | Static Function Exp(x As Double) As Double
|
---|
104 | Exp = ActiveBasic.Math.Exp(x)
|
---|
105 | End Function
|
---|
106 |
|
---|
107 | Static Function Floor(value As Double) As Long
|
---|
108 | Return Int(value)
|
---|
109 | End Function
|
---|
110 |
|
---|
111 | Static Function IEEERemainder(x As Double, y As Double) As Double
|
---|
112 | If y = 0 Then Return ActiveBasic.Math.Detail.GetNaN()
|
---|
113 | Dim q = x / y
|
---|
114 | If q <> Int(q) Then
|
---|
115 | If q + 0.5 <> Int(q + 0.5) Then
|
---|
116 | q = Int(q + 0.5)
|
---|
117 | ElseIf Int(q + 0.5) = Int(q * 2 + 1) / 2 Then
|
---|
118 | q = Int(q + 0.5)
|
---|
119 | Else
|
---|
120 | q = Int(q - 0.5)
|
---|
121 | End If
|
---|
122 | End If
|
---|
123 | If x - y * q = 0 Then
|
---|
124 | If x > 0 Then
|
---|
125 | Return +0
|
---|
126 | Else
|
---|
127 | Return -0
|
---|
128 | End If
|
---|
129 | Else
|
---|
130 | Return x-y*q
|
---|
131 | End If
|
---|
132 | End Function
|
---|
133 |
|
---|
134 | Static Function Log(x As Double) As Double
|
---|
135 | Log = ActiveBasic.Math.Log(x)
|
---|
136 | End Function
|
---|
137 |
|
---|
138 | Static Function Log10(x As Double) As Double
|
---|
139 | Log = ActiveBasic.Math.Log10(x)
|
---|
140 | End Function
|
---|
141 |
|
---|
142 | Static Function Max(value1 As Byte, value2 As Byte) As Byte
|
---|
143 | If value1>value2 Then
|
---|
144 | return value1
|
---|
145 | Else
|
---|
146 | return value2
|
---|
147 | End If
|
---|
148 | End Function
|
---|
149 |
|
---|
150 | Static Function Max(value1 As SByte, value2 As SByte) As SByte
|
---|
151 | If value1>value2 Then
|
---|
152 | return value1
|
---|
153 | Else
|
---|
154 | return value2
|
---|
155 | End If
|
---|
156 | End Function
|
---|
157 |
|
---|
158 | Static Function Max(value1 As Word, value2 As Word) As Word
|
---|
159 | If value1>value2 Then
|
---|
160 | return value1
|
---|
161 | Else
|
---|
162 | return value2
|
---|
163 | End If
|
---|
164 | End Function
|
---|
165 |
|
---|
166 | Static Function Max(value1 As Integer, value2 As Integer) As Integer
|
---|
167 | If value1>value2 Then
|
---|
168 | return value1
|
---|
169 | Else
|
---|
170 | return value2
|
---|
171 | End If
|
---|
172 | End Function
|
---|
173 |
|
---|
174 | Static Function Max(value1 As DWord, value2 As DWord) As DWord
|
---|
175 | If value1>value2 Then
|
---|
176 | return value1
|
---|
177 | Else
|
---|
178 | return value2
|
---|
179 | End If
|
---|
180 | End Function
|
---|
181 |
|
---|
182 | Static Function Max(value1 As Long, value2 As Long) As Long
|
---|
183 | If value1>value2 Then
|
---|
184 | return value1
|
---|
185 | Else
|
---|
186 | return value2
|
---|
187 | End If
|
---|
188 | End Function
|
---|
189 |
|
---|
190 | Static Function Max(value1 As QWord, value2 As QWord) As QWord
|
---|
191 | If value1>value2 Then
|
---|
192 | return value1
|
---|
193 | Else
|
---|
194 | return value2
|
---|
195 | End If
|
---|
196 | End Function
|
---|
197 |
|
---|
198 | Static Function Max(value1 As Int64, value2 As Int64) As Int64
|
---|
199 | If value1>value2 Then
|
---|
200 | return value1
|
---|
201 | Else
|
---|
202 | return value2
|
---|
203 | End If
|
---|
204 | End Function
|
---|
205 |
|
---|
206 | Static Function Max(value1 As Single, value2 As Single) As Single
|
---|
207 | If value1>value2 Then
|
---|
208 | return value1
|
---|
209 | Else
|
---|
210 | return value2
|
---|
211 | End If
|
---|
212 | End Function
|
---|
213 |
|
---|
214 | Static Function Max(value1 As Double, value2 As Double) As Double
|
---|
215 | If value1>value2 Then
|
---|
216 | return value1
|
---|
217 | Else
|
---|
218 | return value2
|
---|
219 | End If
|
---|
220 | End Function
|
---|
221 |
|
---|
222 | Static Function Min(value1 As Byte, value2 As Byte) As Byte
|
---|
223 | If value1<value2 Then
|
---|
224 | return value1
|
---|
225 | Else
|
---|
226 | return value2
|
---|
227 | End If
|
---|
228 | End Function
|
---|
229 |
|
---|
230 | Static Function Min(value1 As SByte, value2 As SByte) As SByte
|
---|
231 | If value1<value2 Then
|
---|
232 | return value1
|
---|
233 | Else
|
---|
234 | return value2
|
---|
235 | End If
|
---|
236 | End Function
|
---|
237 |
|
---|
238 | Static Function Min(value1 As Word, value2 As Word) As Word
|
---|
239 | If value1<value2 Then
|
---|
240 | return value1
|
---|
241 | Else
|
---|
242 | return value2
|
---|
243 | End If
|
---|
244 | End Function
|
---|
245 |
|
---|
246 | Static Function Min(value1 As Integer, value2 As Integer) As Integer
|
---|
247 | If value1<value2 Then
|
---|
248 | return value1
|
---|
249 | Else
|
---|
250 | return value2
|
---|
251 | End If
|
---|
252 | End Function
|
---|
253 |
|
---|
254 | Static Function Min(value1 As DWord, value2 As DWord) As DWord
|
---|
255 | If value1<value2 Then
|
---|
256 | return value1
|
---|
257 | Else
|
---|
258 | return value2
|
---|
259 | End If
|
---|
260 | End Function
|
---|
261 |
|
---|
262 | Static Function Min(value1 As Long, value2 As Long) As Long
|
---|
263 | If value1<value2 Then
|
---|
264 | return value1
|
---|
265 | Else
|
---|
266 | return value2
|
---|
267 | End If
|
---|
268 | End Function
|
---|
269 |
|
---|
270 | Static Function Min(value1 As QWord, value2 As QWord) As QWord
|
---|
271 | If value1<value2 Then
|
---|
272 | return value1
|
---|
273 | Else
|
---|
274 | return value2
|
---|
275 | End If
|
---|
276 | End Function
|
---|
277 |
|
---|
278 | Static Function Min(value1 As Int64, value2 As Int64) As Int64
|
---|
279 | If value1<value2 Then
|
---|
280 | return value1
|
---|
281 | Else
|
---|
282 | return value2
|
---|
283 | End If
|
---|
284 | End Function
|
---|
285 |
|
---|
286 | Static Function Min(value1 As Single, value2 As Single) As Single
|
---|
287 | If value1<value2 Then
|
---|
288 | return value1
|
---|
289 | Else
|
---|
290 | return value2
|
---|
291 | End If
|
---|
292 | End Function
|
---|
293 |
|
---|
294 | Static Function Min(value1 As Double, value2 As Double) As Double
|
---|
295 | If value1<value2 Then
|
---|
296 | return value1
|
---|
297 | Else
|
---|
298 | return value2
|
---|
299 | End If
|
---|
300 | End Function
|
---|
301 |
|
---|
302 | Static Function Pow(x As Double, y As Double) As Double
|
---|
303 | return pow(x, y)
|
---|
304 | End Function
|
---|
305 |
|
---|
306 | 'ReferenceEquals
|
---|
307 |
|
---|
308 | Static Function Round(value As Double) As Double'他のバージョン、誰か頼む。
|
---|
309 | If value+0.5<>Int(value+0.5) Then
|
---|
310 | value=Int(value+0.5)
|
---|
311 | ElseIf Int(value+0.5)=Int(value*2+1)/2 Then
|
---|
312 | value=Int(value+0.5)
|
---|
313 | Else
|
---|
314 | value=Int(value-0.5)
|
---|
315 | End If
|
---|
316 | End Function
|
---|
317 |
|
---|
318 | Static Function Sign(value As Double) As Long
|
---|
319 | If value = 0 Then
|
---|
320 | return 0
|
---|
321 | ElseIf value > 0 Then
|
---|
322 | return 1
|
---|
323 | Else
|
---|
324 | return -1
|
---|
325 | End If
|
---|
326 | End Function
|
---|
327 | /*
|
---|
328 | Static Function Sign(value As SByte) As Long
|
---|
329 | If value = 0 Then
|
---|
330 | return 0
|
---|
331 | ElseIf value > 0 Then
|
---|
332 | return 1
|
---|
333 | Else
|
---|
334 | return -1
|
---|
335 | End If
|
---|
336 | End Function
|
---|
337 |
|
---|
338 | Static Function Sign(value As Integer) As Long
|
---|
339 | If value = 0 Then
|
---|
340 | return 0
|
---|
341 | ElseIf value > 0 Then
|
---|
342 | return 1
|
---|
343 | Else
|
---|
344 | return -1
|
---|
345 | End If
|
---|
346 | End Function
|
---|
347 |
|
---|
348 | Static Function Sign(value As Long) As Long
|
---|
349 | If value = 0 Then
|
---|
350 | return 0
|
---|
351 | ElseIf value > 0 Then
|
---|
352 | return 1
|
---|
353 | Else
|
---|
354 | return -1
|
---|
355 | End If
|
---|
356 | End Function
|
---|
357 |
|
---|
358 | Static Function Sign(value As Int64) As Long
|
---|
359 | If value = 0 Then
|
---|
360 | return 0
|
---|
361 | ElseIf value > 0 Then
|
---|
362 | return 1
|
---|
363 | Else
|
---|
364 | return -1
|
---|
365 | End If
|
---|
366 | End Function
|
---|
367 |
|
---|
368 | Static Function Sign(value As Single) As Long
|
---|
369 | If value = 0 Then
|
---|
370 | return 0
|
---|
371 | ElseIf value > 0 Then
|
---|
372 | return 1
|
---|
373 | Else
|
---|
374 | return -1
|
---|
375 | End If
|
---|
376 | End Function
|
---|
377 | */
|
---|
378 | Static Function Sin(x As Double) As Double
|
---|
379 | Sin = ActiveBasic.Math.Sin(x)
|
---|
380 | End Function
|
---|
381 |
|
---|
382 | Static Function Sinh(x As Double) As Double
|
---|
383 | Sinh = ActiveBasic.Math.Sinh(x)
|
---|
384 | End Function
|
---|
385 |
|
---|
386 | Static Function Sqrt(x As Double) As Double
|
---|
387 | Sqrt = ActiveBasic.Math.Sqrt(x)
|
---|
388 | End Function
|
---|
389 |
|
---|
390 | Static Function Tan(x As Double) As Double
|
---|
391 | Tan = ActiveBasic.Math.Tan(x)
|
---|
392 | End Function
|
---|
393 |
|
---|
394 | Static Function Tanh(x As Double) As Double
|
---|
395 | Tanh = ActiveBasic.Math.Tanh(x)
|
---|
396 | End Function
|
---|
397 |
|
---|
398 | Static Function Truncate(x As Double) As Double
|
---|
399 | Return Fix(x)
|
---|
400 | End Function
|
---|
401 | End Class
|
---|
402 |
|
---|
403 | End Namespace
|
---|