source: trunk/ab5.0/ablib/src/Classes/System/Math.ab@ 589

Last change on this file since 589 was 589, checked in by イグトランス (egtra), 16 years ago

数学関数をActiveBasic.Mathへ統合

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