1 | #Region "Microsoft.VisualBasic::86f1301294429c5c3046d67efcb2b35e, Microsoft.VisualBasic.Core\Extensions\Math\Math.vb" |
2 | |
3 | ' Author: |
4 | ' |
5 | ' asuka (amethyst.asuka@gcmodeller.org) |
6 | ' xie (genetics@smrucc.org) |
7 | ' xieguigang (xie.guigang@live.com) |
8 | ' |
9 | ' Copyright (c) 2018 GPL3 Licensed |
10 | ' |
11 | ' |
12 | ' GNU GENERAL PUBLIC LICENSE (GPL3) |
13 | ' |
14 | ' |
15 | ' This program is free software: you can redistribute it and/or modify |
16 | ' it under the terms of the GNU General Public License as published by |
17 | ' the Free Software Foundation, either version 3 of the License, or |
18 | ' (at your option) any later version. |
19 | ' |
20 | ' This program is distributed in the hope that it will be useful, |
21 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | ' GNU General Public License for more details. |
24 | ' |
25 | ' You should have received a copy of the GNU General Public License |
26 | ' along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 | |
28 | |
29 | |
30 | ' /********************************************************************************/ |
31 | |
32 | ' Summaries: |
33 | |
34 | ' Module VBMath |
35 | ' |
36 | ' Function: (+7 Overloads) Abs, Acos, Asin, Atan, Atan2 |
37 | ' BigMul, (+2 Overloads) Ceiling, Cos, Cosh, Covariance |
38 | ' Distance, (+2 Overloads) DivRem, (+6 Overloads) EuclideanDistance, Exp, Factorial |
39 | ' FactorialSequence, (+2 Overloads) Floor, FormatNumeric, Hypot, IEEERemainder |
40 | ' IsPowerOf2, (+2 Overloads) Log, Log10, Log2, LogN |
41 | ' (+12 Overloads) Max, (+11 Overloads) Min, PoissonPDF, Pow, Pow2 |
42 | ' (+2 Overloads) ProductALL, (+3 Overloads) RangesAt, RMS, (+8 Overloads) Round, RSD |
43 | ' (+4 Overloads) SD, (+2 Overloads) seq, (+7 Overloads) Sign, Sin, Sinh |
44 | ' Sqrt, Sum, Tan, Tanh, (+2 Overloads) Truncate |
45 | ' WeighedAverage |
46 | ' |
47 | ' |
48 | ' /********************************************************************************/ |
49 | |
50 | #End Region |
51 | |
52 | Imports System.Runtime.CompilerServices |
53 | Imports System.Runtime.ConstrainedExecution |
54 | Imports System.Security |
55 | Imports Microsoft.VisualBasic.CommandLine.Reflection |
56 | Imports Microsoft.VisualBasic.ComponentModel.Ranges.Model |
57 | Imports Microsoft.VisualBasic.Language |
58 | Imports Microsoft.VisualBasic.Linq |
59 | Imports Microsoft.VisualBasic.Scripting.MetaData |
60 | Imports sys = System.Math |
61 | |
62 | Namespace Math |
63 | |
64 | ''' <summary> |
65 | ''' Provides constants and static methods for trigonometric, logarithmic, and other |
66 | ''' common mathematical functions.To browse the .NET Framework source code for this |
67 | ''' type, see the Reference Source. |
68 | ''' </summary> |
69 | <Package("VBMath", Publisher:="xie.guigang@gmail.com")> |
70 | Public Module VBMath |
71 | |
72 | ''' <summary> |
73 | ''' Represents the ratio of the circumference of a circle to its diameter, specified |
74 | ''' by the constant, π. |
75 | ''' </summary> |
76 | Public Const PI# = sys.PI |
77 | ''' <summary> |
78 | ''' Represents the natural logarithmic base, specified by the constant, e. |
79 | ''' </summary> |
80 | Public Const E# = sys.E |
81 | |
82 | #Region "Imports System.Math" |
83 | |
84 | ''' <summary> |
85 | ''' Returns the smaller of two 8-bit unsigned integers. |
86 | ''' </summary> |
87 | ''' <param name="val1">The first of two 8-bit unsigned integers to compare.</param> |
88 | ''' <param name="val2">The second of two 8-bit unsigned integers to compare.</param> |
89 | ''' <returns>Parameter val1 or val2, whichever is smaller.</returns> |
90 | <ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)> |
91 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
92 | Public Function Min(val1 As Byte, val2 As Byte) As Byte |
93 | If val1 < val2 Then |
94 | Return val1 |
95 | Else |
96 | Return val2 |
97 | End If |
98 | End Function |
99 | |
100 | ''' <summary> |
101 | ''' Returns the smaller of two 8-bit signed integers. |
102 | ''' </summary> |
103 | ''' <param name="val1">The first of two 8-bit signed integers to compare.</param> |
104 | ''' <param name="val2">The second of two 8-bit signed integers to compare.</param> |
105 | ''' <returns>Parameter val1 or val2, whichever is smaller.</returns> |
106 | <CLSCompliant(False)> <ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)> |
107 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
108 | Public Function Min(val1 As SByte, val2 As SByte) As SByte |
109 | If val1 < val2 Then |
110 | Return val1 |
111 | Else |
112 | Return val2 |
113 | End If |
114 | End Function |
115 | |
116 | ''' <summary> |
117 | ''' Returns the larger of two decimal numbers. |
118 | ''' </summary> |
119 | ''' <param name="val1">The first of two decimal numbers to compare.</param> |
120 | ''' <param name="val2">The second of two decimal numbers to compare.</param> |
121 | ''' <returns>Parameter val1 or val2, whichever is larger.</returns> |
122 | <ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)> |
123 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
124 | Public Function Max(val1 As Decimal, val2 As Decimal) As Decimal |
125 | If val1 > val2 Then |
126 | Return val1 |
127 | Else |
128 | Return val2 |
129 | End If |
130 | End Function |
131 | |
132 | ''' <summary> |
133 | ''' Returns the larger of two double-precision floating-point numbers. |
134 | ''' </summary> |
135 | ''' <param name="val1">The first of two double-precision floating-point numbers to compare.</param> |
136 | ''' <param name="val2">The second of two double-precision floating-point numbers to compare.</param> |
137 | ''' <returns>Parameter val1 or val2, whichever is larger. If val1, val2, or both val1 and |
138 | ''' val2 are equal to System.Double.NaN, System.Double.NaN is returned.</returns> |
139 | <ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)> |
140 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
141 | Public Function Max(val1 As Double, val2 As Double) As Double |
142 | If val1 > val2 Then |
143 | Return val1 |
144 | Else |
145 | Return val2 |
146 | End If |
147 | End Function |
148 | |
149 | ''' <summary> |
150 | ''' Returns the larger of two single-precision floating-point numbers. |
151 | ''' </summary> |
152 | ''' <param name="val1">The first of two single-precision floating-point numbers to compare.</param> |
153 | ''' <param name="val2">The second of two single-precision floating-point numbers to compare.</param> |
154 | ''' <returns>Parameter val1 or val2, whichever is larger. If val1, or val2, or both val1 and |
155 | ''' val2 are equal to System.Single.NaN, System.Single.NaN is returned.</returns> |
156 | <ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)> |
157 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
158 | Public Function Max(val1 As Single, val2 As Single) As Single |
159 | If val1 > val2 Then |
160 | Return val1 |
161 | Else |
162 | Return val2 |
163 | End If |
164 | End Function |
165 | |
166 | ''' <summary> |
167 | ''' Returns the larger of two 64-bit unsigned integers. |
168 | ''' </summary> |
169 | ''' <param name="val1">The first of two 64-bit unsigned integers to compare.</param> |
170 | ''' <param name="val2">The second of two 64-bit unsigned integers to compare.</param> |
171 | ''' <returns>Parameter val1 or val2, whichever is larger.</returns> |
172 | <CLSCompliant(False)> <ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)> |
173 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
174 | Public Function Max(val1 As ULong, val2 As ULong) As ULong |
175 | If val1 > val2 Then |
176 | Return val1 |
177 | Else |
178 | Return val2 |
179 | End If |
180 | End Function |
181 | |
182 | ''' <summary> |
183 | ''' Returns the larger of two 64-bit signed integers. |
184 | ''' </summary> |
185 | ''' <param name="val1">The first of two 64-bit signed integers to compare.</param> |
186 | ''' <param name="val2">The second of two 64-bit signed integers to compare.</param> |
187 | ''' <returns>Parameter val1 or val2, whichever is larger.</returns> |
188 | <ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)> |
189 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
190 | Public Function Max(val1 As Long, val2 As Long) As Long |
191 | If val1 > val2 Then |
192 | Return val1 |
193 | Else |
194 | Return val2 |
195 | End If |
196 | End Function |
197 | |
198 | ''' <summary> |
199 | ''' Returns the larger of two 32-bit unsigned integers. |
200 | ''' </summary> |
201 | ''' <param name="val1">The first of two 32-bit unsigned integers to compare.</param> |
202 | ''' <param name="val2">The second of two 32-bit unsigned integers to compare.</param> |
203 | ''' <returns>Parameter val1 or val2, whichever is larger.</returns> |
204 | <CLSCompliant(False)> <ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)> |
205 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
206 | Public Function Max(val1 As UInteger, val2 As UInteger) As UInteger |
207 | If val1 > val2 Then |
208 | Return val1 |
209 | Else |
210 | Return val2 |
211 | End If |
212 | End Function |
213 | ' ' Summary: |
214 | ' Returns the larger of two 32-bit signed integers. |
215 | ' ' Parameters: |
216 | ' val1: |
217 | ' The first of two 32-bit signed integers to compare. |
218 | ' ' val2: |
219 | ' The second of two 32-bit signed integers to compare. |
220 | ' ' Returns: |
221 | ' Parameter val1 or val2, whichever is larger. |
222 | <ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)> |
223 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
224 | Public Function Max(val1 As Integer, val2 As Integer) As Integer |
225 | If val1 > val2 Then |
226 | Return val1 |
227 | Else |
228 | Return val2 |
229 | End If |
230 | End Function |
231 | ' ' Summary: |
232 | ' Returns the larger of two 16-bit unsigned integers. |
233 | ' ' Parameters: |
234 | ' val1: |
235 | ' The first of two 16-bit unsigned integers to compare. |
236 | ' ' val2: |
237 | ' The second of two 16-bit unsigned integers to compare. |
238 | ' ' Returns: |
239 | ' Parameter val1 or val2, whichever is larger. |
240 | <CLSCompliant(False)> <ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)> |
241 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
242 | Public Function Max(val1 As UShort, val2 As UShort) As UShort |
243 | If val1 > val2 Then |
244 | Return val1 |
245 | Else |
246 | Return val2 |
247 | End If |
248 | End Function |
249 | ' ' Summary: |
250 | ' Returns the larger of two 16-bit signed integers. |
251 | ' ' Parameters: |
252 | ' val1: |
253 | ' The first of two 16-bit signed integers to compare. |
254 | ' ' val2: |
255 | ' The second of two 16-bit signed integers to compare. |
256 | ' ' Returns: |
257 | ' Parameter val1 or val2, whichever is larger. |
258 | <ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)> |
259 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
260 | Public Function Max(val1 As Short, val2 As Short) As Short |
261 | If val1 > val2 Then |
262 | Return val1 |
263 | Else |
264 | Return val2 |
265 | End If |
266 | End Function |
267 | ' ' Summary: |
268 | ' Returns the larger of two 8-bit unsigned integers. |
269 | ' ' Parameters: |
270 | ' val1: |
271 | ' The first of two 8-bit unsigned integers to compare. |
272 | ' ' val2: |
273 | ' The second of two 8-bit unsigned integers to compare. |
274 | ' ' Returns: |
275 | ' Parameter val1 or val2, whichever is larger. |
276 | <ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)> |
277 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
278 | Public Function Max(val1 As Byte, val2 As Byte) As Byte |
279 | If val1 > val2 Then |
280 | Return val1 |
281 | Else |
282 | Return val2 |
283 | End If |
284 | End Function |
285 | ' ' Summary: |
286 | ' Returns the larger of two 8-bit signed integers. |
287 | ' ' Parameters: |
288 | ' val1: |
289 | ' The first of two 8-bit signed integers to compare. |
290 | ' ' val2: |
291 | ' The second of two 8-bit signed integers to compare. |
292 | ' ' Returns: |
293 | ' Parameter val1 or val2, whichever is larger. |
294 | <CLSCompliant(False)> <ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)> |
295 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
296 | Public Function Max(val1 As SByte, val2 As SByte) As SByte |
297 | If val1 > val2 Then |
298 | Return val1 |
299 | Else |
300 | Return val2 |
301 | End If |
302 | End Function |
303 | ' ' Summary: |
304 | ' Returns the absolute value of a System.Decimal number. |
305 | ' ' Parameters: |
306 | ' value: |
307 | ' A number that is greater than or equal to System.Decimal.MinValue, but less than |
308 | ' or equal to System.Decimal.MaxValue. |
309 | ' ' Returns: |
310 | ' A decimal number, x, such that 0 ≤ x ≤System.Decimal.MaxValue. |
311 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
312 | Public Function Abs(value As Decimal) As Decimal |
313 | If value < 0 Then |
314 | Return -value |
315 | Else |
316 | Return value |
317 | End If |
318 | End Function |
319 | ' ' Summary: |
320 | ' Returns the smaller of two 16-bit signed integers. |
321 | ' ' Parameters: |
322 | ' val1: |
323 | ' The first of two 16-bit signed integers to compare. |
324 | ' ' val2: |
325 | ' The second of two 16-bit signed integers to compare. |
326 | ' ' Returns: |
327 | ' Parameter val1 or val2, whichever is smaller. |
328 | <ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)> |
329 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
330 | Public Function Min(val1 As Short, val2 As Short) As Short |
331 | If val1 < val2 Then |
332 | Return val1 |
333 | Else |
334 | Return val2 |
335 | End If |
336 | End Function |
337 | ' ' Summary: |
338 | ' Returns the smaller of two 16-bit unsigned integers. |
339 | ' ' Parameters: |
340 | ' val1: |
341 | ' The first of two 16-bit unsigned integers to compare. |
342 | ' ' val2: |
343 | ' The second of two 16-bit unsigned integers to compare. |
344 | ' ' Returns: |
345 | ' Parameter val1 or val2, whichever is smaller. |
346 | <CLSCompliant(False)> <ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)> |
347 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
348 | Public Function Min(val1 As UShort, val2 As UShort) As UShort |
349 | If val1 < val2 Then |
350 | Return val1 |
351 | Else |
352 | Return val2 |
353 | End If |
354 | End Function |
355 | ' ' Summary: |
356 | ' Returns the smaller of two 32-bit signed integers. |
357 | ' ' Parameters: |
358 | ' val1: |
359 | ' The first of two 32-bit signed integers to compare. |
360 | ' ' val2: |
361 | ' The second of two 32-bit signed integers to compare. |
362 | ' ' Returns: |
363 | ' Parameter val1 or val2, whichever is smaller. |
364 | <ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)> |
365 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
366 | Public Function Min(val1 As Integer, val2 As Integer) As Integer |
367 | If val1 < val2 Then |
368 | Return val1 |
369 | Else |
370 | Return val2 |
371 | End If |
372 | End Function |
373 | ' ' Summary: |
374 | ' Returns the smaller of two 32-bit unsigned integers. |
375 | ' ' Parameters: |
376 | ' val1: |
377 | ' The first of two 32-bit unsigned integers to compare. |
378 | ' ' val2: |
379 | ' The second of two 32-bit unsigned integers to compare. |
380 | ' ' Returns: |
381 | ' Parameter val1 or val2, whichever is smaller. |
382 | <CLSCompliant(False)> <ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)> |
383 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
384 | Public Function Min(val1 As UInteger, val2 As UInteger) As UInteger |
385 | If val1 < val2 Then |
386 | Return val1 |
387 | Else |
388 | Return val2 |
389 | End If |
390 | End Function |
391 | ' ' Summary: |
392 | ' Produces the full product of two 32-bit numbers. |
393 | ' ' Parameters: |
394 | ' a: |
395 | ' The first number to multiply. |
396 | ' ' b: |
397 | ' The second number to multiply. |
398 | ' ' Returns: |
399 | ' The number containing the product of the specified numbers. |
400 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
401 | Public Function BigMul(a As Integer, b As Integer) As Long |
402 | Return sys.BigMul(a, b) |
403 | End Function |
404 | ' ' Summary: |
405 | ' Returns an integer that indicates the sign of a decimal number. |
406 | ' ' Parameters: |
407 | ' value: |
408 | ' A signed decimal number. |
409 | ' ' Returns: |
410 | ' A number that indicates the sign of value, as shown in the following table.Return |
411 | ' value Meaning -1 value is less than zero. 0 value is equal to zero. 1 value is |
412 | ' greater than zero. |
413 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
414 | Public Function Sign(value As Decimal) As Integer |
415 | If value > 0 Then |
416 | Return 1 |
417 | ElseIf value < 0 Then |
418 | Return -1 |
419 | Else |
420 | Return 0 |
421 | End If |
422 | End Function |
423 | ' ' Summary: |
424 | ' Returns an integer that indicates the sign of a double-precision floating-point |
425 | ' number. |
426 | ' ' Parameters: |
427 | ' value: |
428 | ' A signed number. |
429 | ' ' Returns: |
430 | ' A number that indicates the sign of value, as shown in the following table.Return |
431 | ' value Meaning -1 value is less than zero. 0 value is equal to zero. 1 value is |
432 | ' greater than zero. |
433 | ' ' Exceptions: |
434 | ' T:System.ArithmeticException: |
435 | ' value is equal to System.Double.NaN. |
436 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
437 | Public Function Sign(value As Double) As Integer |
438 | If value > 0 Then |
439 | Return 1 |
440 | ElseIf value < 0 Then |
441 | Return -1 |
442 | Else |
443 | Return 0 |
444 | End If |
445 | End Function |
446 | ' ' Summary: |
447 | ' Returns an integer that indicates the sign of a single-precision floating-point |
448 | ' number. |
449 | ' ' Parameters: |
450 | ' value: |
451 | ' A signed number. |
452 | ' ' Returns: |
453 | ' A number that indicates the sign of value, as shown in the following table.Return |
454 | ' value Meaning -1 value is less than zero. 0 value is equal to zero. 1 value is |
455 | ' greater than zero. |
456 | ' ' Exceptions: |
457 | ' T:System.ArithmeticException: |
458 | ' value is equal to System.Single.NaN. |
459 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
460 | Public Function Sign(value As Single) As Integer |
461 | If value > 0 Then |
462 | Return 1 |
463 | ElseIf value < 0 Then |
464 | Return -1 |
465 | Else |
466 | Return 0 |
467 | End If |
468 | End Function |
469 | ' ' Summary: |
470 | ' Returns an integer that indicates the sign of a 64-bit signed integer. |
471 | ' ' Parameters: |
472 | ' value: |
473 | ' A signed number. |
474 | ' ' Returns: |
475 | ' A number that indicates the sign of value, as shown in the following table.Return |
476 | ' value Meaning -1 value is less than zero. 0 value is equal to zero. 1 value is |
477 | ' greater than zero. |
478 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
479 | Public Function Sign(value As Long) As Integer |
480 | If value > 0 Then |
481 | Return 1 |
482 | ElseIf value < 0 Then |
483 | Return -1 |
484 | Else |
485 | Return 0 |
486 | End If |
487 | End Function |
488 | ' ' Summary: |
489 | ' Returns an integer that indicates the sign of a 32-bit signed integer. |
490 | ' ' Parameters: |
491 | ' value: |
492 | ' A signed number. |
493 | ' ' Returns: |
494 | ' A number that indicates the sign of value, as shown in the following table.Return |
495 | ' value Meaning -1 value is less than zero. 0 value is equal to zero. 1 value is |
496 | ' greater than zero. |
497 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
498 | Public Function Sign(value As Integer) As Integer |
499 | If value > 0 Then |
500 | Return 1 |
501 | ElseIf value < 0 Then |
502 | Return -1 |
503 | Else |
504 | Return 0 |
505 | End If |
506 | End Function |
507 | |
508 | ''' <summary> |
509 | ''' Returns the absolute value of a double-precision floating-point number. |
510 | ''' </summary> |
511 | ''' <param name="value">A number that is greater than or equal to System.Double.MinValue, but less than |
512 | ''' or equal to System.Double.MaxValue.</param> |
513 | ''' <returns>A double-precision floating-point number, x, such that 0 ≤ x ≤System.Double.MaxValue.</returns> |
514 | <SecuritySafeCritical> |
515 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
516 | Public Function Abs(value As Double) As Double |
517 | If value < 0 Then |
518 | Return -value |
519 | Else |
520 | Return value |
521 | End If |
522 | End Function |
523 | ' ' Summary: |
524 | ' Returns an integer that indicates the sign of a 16-bit signed integer. |
525 | ' ' Parameters: |
526 | ' value: |
527 | ' A signed number. |
528 | ' ' Returns: |
529 | ' A number that indicates the sign of value, as shown in the following table.Return |
530 | ' value Meaning -1 value is less than zero. 0 value is equal to zero. 1 value is |
531 | ' greater than zero. |
532 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
533 | Public Function Sign(value As Short) As Integer |
534 | If value < 0 Then |
535 | Return -value |
536 | Else |
537 | Return value |
538 | End If |
539 | End Function |
540 | |
541 | ' Returns: |
542 | ' One of the values in the following table. (+Infinity denotes System.Double.PositiveInfinity, |
543 | ' -Infinity denotes System.Double.NegativeInfinity, and NaN denotes System.Double.NaN.)anewBaseReturn |
544 | ' valuea> 0(0 <newBase< 1) -or-(newBase> 1)lognewBase(a)a< 0(any value)NaN(any |
545 | ' value)newBase< 0NaNa != 1newBase = 0NaNa != 1newBase = +InfinityNaNa = NaN(any |
546 | ' value)NaN(any value)newBase = NaNNaN(any value)newBase = 1NaNa = 00 <newBase< |
547 | ' 1 +Infinitya = 0newBase> 1-Infinitya = +Infinity0 <newBase< 1-Infinitya = +InfinitynewBase> |
548 | ' 1+Infinitya = 1newBase = 00a = 1newBase = +Infinity0 |
549 | ''' <summary> |
550 | ''' Returns the logarithm of a specified number in a specified base. |
551 | ''' </summary> |
552 | ''' <param name="a">The number whose logarithm is to be found.</param> |
553 | ''' <param name="newBase">The base of the logarithm.</param> |
554 | ''' <returns></returns> |
555 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
556 | Public Function Log(a#, newBase#) As Double |
557 | Return sys.Log(a, newBase) |
558 | End Function |
559 | |
560 | ''' <summary> |
561 | ''' Returns the smaller of two decimal numbers. |
562 | ''' </summary> |
563 | ''' <param name="val1">The first of two decimal numbers to compare.</param> |
564 | ''' <param name="val2">The second of two decimal numbers to compare.</param> |
565 | ''' <returns>Parameter val1 or val2, whichever is smaller.</returns> |
566 | <ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)> |
567 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
568 | Public Function Min(val1 As Decimal, val2 As Decimal) As Decimal |
569 | If val1 < val2 Then |
570 | Return val1 |
571 | Else |
572 | Return val2 |
573 | End If |
574 | End Function |
575 | ' ' Summary: |
576 | ' Returns the smaller of two double-precision floating-point numbers. |
577 | ' ' Parameters: |
578 | ' val1: |
579 | ' The first of two double-precision floating-point numbers to compare. |
580 | ' ' val2: |
581 | ' The second of two double-precision floating-point numbers to compare. |
582 | ' ' Returns: |
583 | ' Parameter val1 or val2, whichever is smaller. If val1, val2, or both val1 and |
584 | ' val2 are equal to System.Double.NaN, System.Double.NaN is returned. |
585 | <ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)> |
586 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
587 | Public Function Min(val1 As Double, val2 As Double) As Double |
588 | If val1 < val2 Then |
589 | Return val1 |
590 | Else |
591 | Return val2 |
592 | End If |
593 | End Function |
594 | |
595 | ' ' Summary: |
596 | ' Returns the smaller of two single-precision floating-point numbers. |
597 | ' ' Parameters: |
598 | ' val1: |
599 | ' The first of two single-precision floating-point numbers to compare. |
600 | ' ' val2: |
601 | ' The second of two single-precision floating-point numbers to compare. |
602 | ' ' Returns: |
603 | ' Parameter val1 or val2, whichever is smaller. If val1, val2, or both val1 and |
604 | ' val2 are equal to System.Single.NaN, System.Single.NaN is returned. |
605 | <ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)> |
606 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
607 | Public Function Min(val1 As Single, val2 As Single) As Single |
608 | If val1 < val2 Then |
609 | Return val1 |
610 | Else |
611 | Return val2 |
612 | End If |
613 | End Function |
614 | ' ' Summary: |
615 | ' Returns the smaller of two 64-bit unsigned integers. |
616 | ' ' Parameters: |
617 | ' val1: |
618 | ' The first of two 64-bit unsigned integers to compare. |
619 | ' ' val2: |
620 | ' The second of two 64-bit unsigned integers to compare. |
621 | ' ' Returns: |
622 | ' Parameter val1 or val2, whichever is smaller. |
623 | <CLSCompliant(False)> <ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)> |
624 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
625 | Public Function Min(val1 As ULong, val2 As ULong) As ULong |
626 | If val1 < val2 Then |
627 | Return val1 |
628 | Else |
629 | Return val2 |
630 | End If |
631 | End Function |
632 | ' ' Summary: |
633 | ' Returns the smaller of two 64-bit signed integers. |
634 | ' ' Parameters: |
635 | ' val1: |
636 | ' The first of two 64-bit signed integers to compare. |
637 | ' ' val2: |
638 | ' The second of two 64-bit signed integers to compare. |
639 | ' ' Returns: |
640 | ' Parameter val1 or val2, whichever is smaller. |
641 | <ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)> |
642 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
643 | Public Function Min(val1 As Long, val2 As Long) As Long |
644 | If val1 < val2 Then |
645 | Return val1 |
646 | Else |
647 | Return val2 |
648 | End If |
649 | End Function |
650 | ' ' Summary: |
651 | ' Returns an integer that indicates the sign of an 8-bit signed integer. |
652 | ' ' Parameters: |
653 | ' value: |
654 | ' A signed number. |
655 | ' ' Returns: |
656 | ' A number that indicates the sign of value, as shown in the following table.Return |
657 | ' value Meaning -1 value is less than zero. 0 value is equal to zero. 1 value is |
658 | ' greater than zero. |
659 | <CLSCompliant(False)> |
660 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
661 | Public Function Sign(value As SByte) As Integer |
662 | If value > 0 Then |
663 | Return 1 |
664 | ElseIf value < 0 Then |
665 | Return -1 |
666 | Else |
667 | Return 0 |
668 | End If |
669 | End Function |
670 | |
671 | ''' <summary> |
672 | ''' Returns the absolute value of a single-precision floating-point number. |
673 | ''' </summary> |
674 | ''' <param name="value">A number that is greater than or equal to System.Single.MinValue, but less than |
675 | ''' or equal to System.Single.MaxValue.</param> |
676 | ''' <returns> |
677 | ''' A single-precision floating-point number, x, such that 0 ≤ x ≤System.Single.MaxValue. |
678 | ''' </returns> |
679 | <SecuritySafeCritical> |
680 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
681 | Public Function Abs(value As Single) As Single |
682 | If value < 0 Then |
683 | Return -value |
684 | Else |
685 | Return value |
686 | End If |
687 | End Function |
688 | |
689 | ''' <summary> |
690 | ''' Returns the absolute value of a 64-bit signed integer. |
691 | ''' </summary> |
692 | ''' <param name="value"> |
693 | ''' A number that is greater than System.Int64.MinValue, but less than or equal to |
694 | ''' System.Int64.MaxValue.</param> |
695 | ''' <returns>A 64-bit signed integer, x, such that 0 ≤ x ≤System.Int64.MaxValue.</returns> |
696 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
697 | Public Function Abs(value As Long) As Long |
698 | If value < 0 Then |
699 | Return -value |
700 | Else |
701 | Return value |
702 | End If |
703 | End Function |
704 | |
705 | ''' <summary> |
706 | ''' Returns the absolute value of a 32-bit signed integer. |
707 | ''' </summary> |
708 | ''' <param name="value"> |
709 | ''' A number that is greater than System.Int32.MinValue, but less than or equal to |
710 | ''' System.Int32.MaxValue. |
711 | ''' </param> |
712 | ''' <returns>A 32-bit signed integer, x, such that 0 ≤ x ≤System.Int32.MaxValue.</returns> |
713 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
714 | Public Function Abs(value As Integer) As Integer |
715 | If value < 0 Then |
716 | Return -value |
717 | Else |
718 | Return value |
719 | End If |
720 | End Function |
721 | ' ' Summary: |
722 | ' Returns the hyperbolic tangent of the specified angle. |
723 | ' ' Parameters: |
724 | ' value: |
725 | ' An angle, measured in radians. |
726 | ' ' Returns: |
727 | ' The hyperbolic tangent of value. If value is equal to System.Double.NegativeInfinity, |
728 | ' this method returns -1. If value is equal to System.Double.PositiveInfinity, |
729 | ' this method returns 1. If value is equal to System.Double.NaN, this method returns |
730 | ' System.Double.NaN. |
731 | <SecuritySafeCritical> |
732 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
733 | Public Function Tanh(value As Double) As Double |
734 | Return sys.Tanh(value) |
735 | End Function |
736 | ' ' Summary: |
737 | ' Returns the hyperbolic sine of the specified angle. |
738 | ' ' Parameters: |
739 | ' value: |
740 | ' An angle, measured in radians. |
741 | ' ' Returns: |
742 | ' The hyperbolic sine of value. If value is equal to System.Double.NegativeInfinity, |
743 | ' System.Double.PositiveInfinity, or System.Double.NaN, this method returns a System.Double |
744 | ' equal to value. |
745 | <SecuritySafeCritical> |
746 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
747 | Public Function Sinh(value As Double) As Double |
748 | Return sys.Sinh(value) |
749 | End Function |
750 | ' ' Summary: |
751 | ' Returns the tangent of the specified angle. |
752 | ' ' Parameters: |
753 | ' a: |
754 | ' An angle, measured in radians. |
755 | ' ' Returns: |
756 | ' The tangent of a. If a is equal to System.Double.NaN, System.Double.NegativeInfinity, |
757 | ' or System.Double.PositiveInfinity, this method returns System.Double.NaN. |
758 | <SecuritySafeCritical> |
759 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
760 | Public Function Tan(a As Double) As Double |
761 | Return sys.Tan(a) |
762 | End Function |
763 | ' ' Summary: |
764 | ' Returns the sine of the specified angle. |
765 | ' ' Parameters: |
766 | ' a: |
767 | ' An angle, measured in radians. |
768 | ' ' Returns: |
769 | ' The sine of a. If a is equal to System.Double.NaN, System.Double.NegativeInfinity, |
770 | ' or System.Double.PositiveInfinity, this method returns System.Double.NaN. |
771 | <SecuritySafeCritical> |
772 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
773 | Public Function Sin(a As Double) As Double |
774 | Return sys.Sin(a) |
775 | End Function |
776 | ' ' Summary: |
777 | ' Returns the largest integer less than or equal to the specified double-precision |
778 | ' floating-point number. |
779 | ' ' Parameters: |
780 | ' d: |
781 | ' A double-precision floating-point number. |
782 | ' ' Returns: |
783 | ' The largest integer less than or equal to d. If d is equal to System.Double.NaN, |
784 | ' System.Double.NegativeInfinity, or System.Double.PositiveInfinity, that value |
785 | ' is returned. |
786 | <SecuritySafeCritical> |
787 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
788 | Public Function Floor(d As Double) As Double |
789 | Return sys.Floor(d) |
790 | End Function |
791 | |
792 | |
793 | ' ' Summary: |
794 | ' Returns the largest integer less than or equal to the specified decimal number. |
795 | ' ' Parameters: |
796 | ' d: |
797 | ' A decimal number. |
798 | ' ' Returns: |
799 | ' The largest integer less than or equal to d. Note that the method returns an |
800 | ' integral value of type System.Math. |
801 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
802 | Public Function Floor(d As Decimal) As Decimal |
803 | Return sys.Floor(d) |
804 | End Function |
805 | |
806 | ' ' Summary: |
807 | ' Rounds a double-precision floating-point value to the nearest integral value. |
808 | ' ' Parameters: |
809 | ' a: |
810 | ' A double-precision floating-point number to be rounded. |
811 | ' ' Returns: |
812 | ' The integer nearest a. If the fractional component of a is halfway between two |
813 | ' integers, one of which is even and the other odd, then the even number is returned. |
814 | ' Note that this method returns a System.Double instead of an integral type. |
815 | <SecuritySafeCritical> |
816 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
817 | Public Function Round(a As Double) As Double |
818 | Return sys.Round(a) |
819 | End Function |
820 | ' ' Summary: |
821 | ' Returns the hyperbolic cosine of the specified angle. |
822 | ' ' Parameters: |
823 | ' value: |
824 | ' An angle, measured in radians. |
825 | ' ' Returns: |
826 | ' The hyperbolic cosine of value. If value is equal to System.Double.NegativeInfinity |
827 | ' or System.Double.PositiveInfinity, System.Double.PositiveInfinity is returned. |
828 | ' If value is equal to System.Double.NaN, System.Double.NaN is returned. |
829 | <SecuritySafeCritical> |
830 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
831 | Public Function Cosh(value As Double) As Double |
832 | Return sys.Cosh(value) |
833 | End Function |
834 | ' ' Summary: |
835 | ' Returns the smallest integral value that is greater than or equal to the specified |
836 | ' double-precision floating-point number. |
837 | ' ' Parameters: |
838 | ' a: |
839 | ' A double-precision floating-point number. |
840 | ' ' Returns: |
841 | ' The smallest integral value that is greater than or equal to a. If a is equal |
842 | ' to System.Double.NaN, System.Double.NegativeInfinity, or System.Double.PositiveInfinity, |
843 | ' that value is returned. Note that this method returns a System.Double instead |
844 | ' of an integral type. |
845 | <SecuritySafeCritical> |
846 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
847 | Public Function Ceiling(a As Double) As Double |
848 | Return sys.Ceiling(a) |
849 | End Function |
850 | ' ' Summary: |
851 | ' Returns the smallest integral value that is greater than or equal to the specified |
852 | ' decimal number. |
853 | ' ' Parameters: |
854 | ' d: |
855 | ' A decimal number. |
856 | ' ' Returns: |
857 | ' The smallest integral value that is greater than or equal to d. Note that this |
858 | ' method returns a System.Decimal instead of an integral type. |
859 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
860 | Public Function Ceiling(d As Decimal) As Decimal |
861 | Return sys.Ceiling(d) |
862 | End Function |
863 | ' ' Summary: |
864 | ' Returns the angle whose tangent is the quotient of two specified numbers. |
865 | ' ' Parameters: |
866 | ' y: |
867 | ' The y coordinate of a point. |
868 | ' ' x: |
869 | ' The x coordinate of a point. |
870 | ' ' Returns: |
871 | ' An angle, θ, measured in radians, such that -π≤θ≤π, and tan(θ) = y / x, where |
872 | ' (x, y) is a point in the Cartesian plane. Observe the following: For (x, y) in |
873 | ' quadrant 1, 0 < θ < π/2.For (x, y) in quadrant 2, π/2 < θ≤π.For (x, y) in quadrant |
874 | ' 3, -π < θ < -π/2.For (x, y) in quadrant 4, -π/2 < θ < 0.For points on the boundaries |
875 | ' of the quadrants, the return value is the following:If y is 0 and x is not negative, |
876 | ' θ = 0.If y is 0 and x is negative, θ = π.If y is positive and x is 0, θ = π/2.If |
877 | ' y is negative and x is 0, θ = -π/2.If y is 0 and x is 0, θ = 0. If x or y is |
878 | ' System.Double.NaN, or if x and y are either System.Double.PositiveInfinity or |
879 | ' System.Double.NegativeInfinity, the method returns System.Double.NaN. |
880 | <SecuritySafeCritical> |
881 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
882 | Public Function Atan2(y As Double, x As Double) As Double |
883 | Return sys.Atan2(y, x) |
884 | End Function |
885 | ' ' Summary: |
886 | ' Returns the angle whose tangent is the specified number. |
887 | ' ' Parameters: |
888 | ' d: |
889 | ' A number representing a tangent. |
890 | ' ' Returns: |
891 | ' An angle, θ, measured in radians, such that -π/2 ≤θ≤π/2.-or- System.Double.NaN |
892 | ' if d equals System.Double.NaN, -π/2 rounded to double precision (-1.5707963267949) |
893 | ' if d equals System.Double.NegativeInfinity, or π/2 rounded to double precision |
894 | ' (1.5707963267949) if d equals System.Double.PositiveInfinity. |
895 | <SecuritySafeCritical> |
896 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
897 | Public Function Atan(d As Double) As Double |
898 | Return sys.Atan(d) |
899 | End Function |
900 | ' ' Summary: |
901 | ' Returns the angle whose sine is the specified number. |
902 | ' ' Parameters: |
903 | ' d: |
904 | ' A number representing a sine, where d must be greater than or equal to -1, but |
905 | ' less than or equal to 1. |
906 | ' ' Returns: |
907 | ' An angle, θ, measured in radians, such that -π/2 ≤θ≤π/2 -or- System.Double.NaN |
908 | ' if d < -1 or d > 1 or d equals System.Double.NaN. |
909 | <SecuritySafeCritical> |
910 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
911 | Public Function Asin(d As Double) As Double |
912 | Return sys.Asin(d) |
913 | End Function |
914 | ' ' Summary: |
915 | ' Returns the angle whose cosine is the specified number. |
916 | ' ' Parameters: |
917 | ' d: |
918 | ' A number representing a cosine, where d must be greater than or equal to -1, |
919 | ' but less than or equal to 1. |
920 | ' ' Returns: |
921 | ' An angle, θ, measured in radians, such that 0 ≤θ≤π-or- System.Double.NaN if d |
922 | ' < -1 or d > 1 or d equals System.Double.NaN. |
923 | <SecuritySafeCritical> |
924 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
925 | Public Function Acos(d As Double) As Double |
926 | Return sys.Acos(d) |
927 | End Function |
928 | ' ' Summary: |
929 | ' Returns the cosine of the specified angle. |
930 | ' ' Parameters: |
931 | ' d: |
932 | ' An angle, measured in radians. |
933 | ' ' Returns: |
934 | ' The cosine of d. If d is equal to System.Double.NaN, System.Double.NegativeInfinity, |
935 | ' or System.Double.PositiveInfinity, this method returns System.Double.NaN. |
936 | <SecuritySafeCritical> |
937 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
938 | Public Function Cos(d As Double) As Double |
939 | Return sys.Cos(d) |
940 | End Function |
941 | ' ' Summary: |
942 | ' Calculates the quotient of two 32-bit signed integers and also returns the remainder |
943 | ' in an output parameter. |
944 | ' ' Parameters: |
945 | ' a: |
946 | ' The dividend. |
947 | ' ' b: |
948 | ' The divisor. |
949 | ' ' result: |
950 | ' The remainder. |
951 | ' ' Returns: |
952 | ' The quotient of the specified numbers. |
953 | ' ' Exceptions: |
954 | ' T:System.DivideByZeroException: |
955 | ' b is zero. |
956 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
957 | Public Function DivRem(a As Integer, b As Integer, ByRef result As Integer) As Integer |
958 | Return sys.DivRem(a, b, result) |
959 | End Function |
960 | |
961 | ''' <summary> |
962 | ''' Rounds a double-precision floating-point value to a specified number of fractional |
963 | ''' digits. |
964 | ''' </summary> |
965 | ''' <param name="value">A double-precision floating-point number to be rounded.</param> |
966 | ''' <param name="digits">The number of fractional digits in the return value.</param> |
967 | ''' <returns>The number nearest to value that contains a number of fractional digits equal |
968 | ''' to digits.</returns> |
969 | ''' |
970 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
971 | Public Function Round(value As Double, digits As Integer) As Double |
972 | Return sys.Round(value, digits) |
973 | End Function |
974 | ' ' Summary: |
975 | ' Rounds a double-precision floating-point value to a specified number of fractional |
976 | ' digits. A parameter specifies how to round the value if it is midway between |
977 | ' two numbers. |
978 | ' ' Parameters: |
979 | ' value: |
980 | ' A double-precision floating-point number to be rounded. |
981 | ' ' digits: |
982 | ' The number of fractional digits in the return value. |
983 | ' ' mode: |
984 | ' Specification for how to round value if it is midway between two other numbers. |
985 | ' ' Returns: |
986 | ' The number nearest to value that has a number of fractional digits equal to digits. |
987 | ' If value has fewer fractional digits than digits, value is returned unchanged. |
988 | ' ' Exceptions: |
989 | ' T:System.ArgumentOutOfRangeException: |
990 | ' digits is less than 0 or greater than 15. |
991 | ' ' T:System.ArgumentException: |
992 | ' mode is not a valid value of System.MidpointRounding. |
993 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
994 | Public Function Round(value As Double, digits As Integer, mode As MidpointRounding) As Double |
995 | Return sys.Round(value, digits, mode) |
996 | End Function |
997 | ' ' Summary: |
998 | ' Returns the absolute value of a 16-bit signed integer. |
999 | ' ' Parameters: |
1000 | ' value: |
1001 | ' A number that is greater than System.Int16.MinValue, but less than or equal to |
1002 | ' System.Int16.MaxValue. |
1003 | ' ' Returns: |
1004 | ' A 16-bit signed integer, x, such that 0 ≤ x ≤System.Int16.MaxValue. |
1005 | ' ' Exceptions: |
1006 | ' T:System.OverflowException: |
1007 | ' value equals System.Int16.MinValue. |
1008 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1009 | Public Function Abs(value As Short) As Short |
1010 | If value < 0 Then |
1011 | Return -value |
1012 | Else |
1013 | Return value |
1014 | End If |
1015 | End Function |
1016 | ' ' Summary: |
1017 | ' Returns the absolute value of an 8-bit signed integer. |
1018 | ' ' Parameters: |
1019 | ' value: |
1020 | ' A number that is greater than System.SByte.MinValue, but less than or equal to |
1021 | ' System.SByte.MaxValue. |
1022 | ' ' Returns: |
1023 | ' An 8-bit signed integer, x, such that 0 ≤ x ≤System.SByte.MaxValue. |
1024 | ' ' Exceptions: |
1025 | ' T:System.OverflowException: |
1026 | ' value equals System.SByte.MinValue. |
1027 | <CLSCompliant(False)> |
1028 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1029 | Public Function Abs(value As SByte) As SByte |
1030 | If value < 0 Then |
1031 | Return -value |
1032 | Else |
1033 | Return value |
1034 | End If |
1035 | End Function |
1036 | ' ' Summary: |
1037 | ' Returns the remainder resulting from the division of a specified number by another |
1038 | ' specified number. |
1039 | ' ' Parameters: |
1040 | ' x: |
1041 | ' A dividend. |
1042 | ' |
1043 | ' y: |
1044 | ' A divisor. |
1045 | ' ' Returns: |
1046 | ' A number equal to x - (y Q), where Q is the quotient of x / y rounded to the |
1047 | ' nearest integer (if x / y falls halfway between two integers, the even integer |
1048 | ' is returned).If x - (y Q) is zero, the value +0 is returned if x is positive, |
1049 | ' or -0 if x is negative.If y = 0, System.Double.NaN is returned. |
1050 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1051 | Public Function IEEERemainder(x As Double, y As Double) As Double |
1052 | Return sys.IEEERemainder(x, y) |
1053 | End Function |
1054 | |
1055 | ''' <summary> |
1056 | ''' Returns a specified number raised to the specified power. |
1057 | ''' </summary> |
1058 | ''' <param name="x">A double-precision floating-point number to be raised to a power.</param> |
1059 | ''' <param name="y">A double-precision floating-point number that specifies a power.</param> |
1060 | ''' <returns>The number x raised to the power y.</returns> |
1061 | <SecuritySafeCritical> |
1062 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1063 | Public Function Pow(x As Double, y As Double) As Double |
1064 | Return x ^ y |
1065 | End Function |
1066 | |
1067 | ''' <summary> |
1068 | ''' Returns e raised to the specified power. |
1069 | ''' </summary> |
1070 | ''' <param name="d">A number specifying a power.</param> |
1071 | ''' <returns>The number e raised to the power d. If d equals System.Double.NaN or System.Double.PositiveInfinity, |
1072 | ''' that value is returned. If d equals System.Double.NegativeInfinity, 0 is returned.</returns> |
1073 | <SecuritySafeCritical> |
1074 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1075 | Public Function Exp(d As Double) As Double |
1076 | Return sys.Exp(d) |
1077 | End Function |
1078 | ' ' Summary: |
1079 | ' Returns the base 10 logarithm of a specified number. |
1080 | ' ' Parameters: |
1081 | ' d: |
1082 | ' A number whose logarithm is to be found. |
1083 | ' ' Returns: |
1084 | ' One of the values in the following table. d parameter Return value Positive The |
1085 | ' base 10 log of d; that is, log 10d. Zero System.Double.NegativeInfinityNegative |
1086 | ' System.Double.NaNEqual to System.Double.NaNSystem.Double.NaNEqual to System.Double.PositiveInfinitySystem.Double.PositiveInfinity |
1087 | <SecuritySafeCritical> |
1088 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1089 | Public Function Log10(d As Double) As Double |
1090 | Return sys.Log10(d) |
1091 | End Function |
1092 | ' ' Summary: |
1093 | ' Rounds a double-precision floating-point value to the nearest integer. A parameter |
1094 | ' specifies how to round the value if it is midway between two numbers. |
1095 | ' ' Parameters: |
1096 | ' value: |
1097 | ' A double-precision floating-point number to be rounded. |
1098 | ' ' mode: |
1099 | ' Specification for how to round value if it is midway between two other numbers. |
1100 | ' ' Returns: |
1101 | ' The integer nearest value. If value is halfway between two integers, one of which |
1102 | ' is even and the other odd, then mode determines which of the two is returned. |
1103 | ' ' Exceptions: |
1104 | ' T:System.ArgumentException: |
1105 | ' mode is not a valid value of System.MidpointRounding. |
1106 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1107 | Public Function Round(value As Double, mode As MidpointRounding) As Double |
1108 | Return sys.Round(value, mode) |
1109 | End Function |
1110 | ' ' Summary: |
1111 | ' Returns the natural (base e) logarithm of a specified number. |
1112 | ' ' Parameters: |
1113 | ' d: |
1114 | ' The number whose logarithm is to be found. |
1115 | ' ' Returns: |
1116 | ' One of the values in the following table. d parameterReturn value Positive The |
1117 | ' natural logarithm of d; that is, ln d, or log edZero System.Double.NegativeInfinityNegative |
1118 | ' System.Double.NaNEqual to System.Double.NaNSystem.Double.NaNEqual to System.Double.PositiveInfinitySystem.Double.PositiveInfinity |
1119 | <SecuritySafeCritical> |
1120 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1121 | Public Function Log(d As Double) As Double |
1122 | Return sys.Log(d) |
1123 | End Function |
1124 | |
1125 | ''' <summary> |
1126 | ''' Calculates the integral part of a specified double-precision floating-point number. |
1127 | ''' </summary> |
1128 | ''' <param name="d">A number to truncate.</param> |
1129 | ''' <returns>The integral part of d; that is, the number that remains after any fractional |
1130 | ''' digits have been discarded, or one of the values listed in the following table. |
1131 | ''' |<paramref name="d"/> |Return value | |
1132 | ''' |------------------------------|------------------------------| |
1133 | ''' |System.Double.NaN |System.Double.NaN | |
1134 | ''' |System.Double.NegativeInfinity|System.Double.NegativeInfinity| |
1135 | ''' |System.Double.PositiveInfinity|System.Double.PositiveInfinity| |
1136 | ''' </returns> |
1137 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1138 | Public Function Truncate(d As Double) As Double |
1139 | Return sys.Truncate(d) |
1140 | End Function |
1141 | ' ' Summary: |
1142 | ' Calculates the integral part of a specified decimal number. |
1143 | ' ' Parameters: |
1144 | ' d: |
1145 | ' A number to truncate. |
1146 | ' ' Returns: |
1147 | ' The integral part of d; that is, the number that remains after any fractional |
1148 | ' digits have been discarded. |
1149 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1150 | Public Function Truncate(d As Decimal) As Decimal |
1151 | Return sys.Truncate(d) |
1152 | End Function |
1153 | ' ' Summary: |
1154 | ' Rounds a decimal value to a specified number of fractional digits. A parameter |
1155 | ' specifies how to round the value if it is midway between two numbers. |
1156 | ' ' Parameters: |
1157 | ' d: |
1158 | ' A decimal number to be rounded. |
1159 | ' ' decimals: |
1160 | ' The number of decimal places in the return value. |
1161 | ' ' mode: |
1162 | ' Specification for how to round d if it is midway between two other numbers. |
1163 | ' ' Returns: |
1164 | ' The number nearest to d that contains a number of fractional digits equal to |
1165 | ' decimals. If d has fewer fractional digits than decimals, d is returned unchanged. |
1166 | ' ' Exceptions: |
1167 | ' T:System.ArgumentOutOfRangeException: |
1168 | ' decimals is less than 0 or greater than 28. |
1169 | ' ' T:System.ArgumentException: |
1170 | ' mode is not a valid value of System.MidpointRounding. |
1171 | ' |
1172 | ' T:System.OverflowException: |
1173 | ' The result is outside the range of a System.Decimal. |
1174 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1175 | Public Function Round(d As Decimal, decimals As Integer, mode As MidpointRounding) As Decimal |
1176 | Return sys.Round(d, decimals, mode) |
1177 | End Function |
1178 | ' ' Summary: |
1179 | ' Rounds a decimal value to the nearest integer. A parameter specifies how to round |
1180 | ' the value if it is midway between two numbers. |
1181 | ' ' Parameters: |
1182 | ' d: |
1183 | ' A decimal number to be rounded. |
1184 | ' ' mode: |
1185 | ' Specification for how to round d if it is midway between two other numbers. |
1186 | ' ' Returns: |
1187 | ' The integer nearest d. If d is halfway between two numbers, one of which is even |
1188 | ' and the other odd, then mode determines which of the two is returned. |
1189 | ' ' Exceptions: |
1190 | ' T:System.ArgumentException: |
1191 | ' mode is not a valid value of System.MidpointRounding. |
1192 | ' |
1193 | ' T:System.OverflowException: |
1194 | ' The result is outside the range of a System.Decimal. |
1195 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1196 | Public Function Round(d As Decimal, mode As MidpointRounding) As Decimal |
1197 | Return sys.Round(d, mode) |
1198 | End Function |
1199 | ' ' Summary: |
1200 | ' Rounds a decimal value to a specified number of fractional digits. |
1201 | ' ' Parameters: |
1202 | ' d: |
1203 | ' A decimal number to be rounded. |
1204 | ' ' decimals: |
1205 | ' The number of decimal places in the return value. |
1206 | ' ' Returns: |
1207 | ' The number nearest to d that contains a number of fractional digits equal to |
1208 | ' decimals. |
1209 | ' ' Exceptions: |
1210 | ' T:System.ArgumentOutOfRangeException: |
1211 | ' decimals is less than 0 or greater than 28. |
1212 | ' |
1213 | ' T:System.OverflowException: |
1214 | ' The result is outside the range of a System.Decimal. |
1215 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1216 | Public Function Round(d As Decimal, decimals As Integer) As Decimal |
1217 | Return sys.Round(d, decimals) |
1218 | End Function |
1219 | ' ' Summary: |
1220 | ' Rounds a decimal value to the nearest integral value. |
1221 | ' ' Parameters: |
1222 | ' d: |
1223 | ' A decimal number to be rounded. |
1224 | ' ' Returns: |
1225 | ' The integer nearest parameter d. If the fractional component of d is halfway |
1226 | ' between two integers, one of which is even and the other odd, the even number |
1227 | ' is returned. Note that this method returns a System.Decimal instead of an integral |
1228 | ' type. |
1229 | ' ' Exceptions: |
1230 | ' T:System.OverflowException: |
1231 | ' The result is outside the range of a System.Decimal. |
1232 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1233 | Public Function Round(d As Decimal) As Decimal |
1234 | Return sys.Round(d) |
1235 | End Function |
1236 | |
1237 | ''' <summary> |
1238 | ''' Returns the square root of a specified number. |
1239 | ''' </summary> |
1240 | ''' <param name="d">The number whose square root is to be found.</param> |
1241 | ''' <returns>One of the values in the following table. d parameter Return value Zero or positive |
1242 | ''' The positive square root of d. Negative System.Double.NaNEquals System.Double.NaNSystem.Double.NaNEquals |
1243 | ''' System.Double.PositiveInfinitySystem.Double.PositiveInfinity</returns> |
1244 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1245 | <ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)> <SecuritySafeCritical> |
1246 | Public Function Sqrt(d As Double) As Double |
1247 | Return sys.Sqrt(d) |
1248 | End Function |
1249 | ' ' Summary: |
1250 | ' Calculates the quotient of two 64-bit signed integers and also returns the remainder |
1251 | ' in an output parameter. |
1252 | ' ' Parameters: |
1253 | ' a: |
1254 | ' The dividend. |
1255 | ' ' b: |
1256 | ' The divisor. |
1257 | ' ' result: |
1258 | ' The remainder. |
1259 | ' ' Returns: |
1260 | ' The quotient of the specified numbers. |
1261 | ' ' Exceptions: |
1262 | ' T:System.DivideByZeroException: |
1263 | ' b is zero. |
1264 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1265 | Public Function DivRem(a As Long, b As Long, ByRef result As Long) As Long |
1266 | Return sys.DivRem(a, b, result) |
1267 | End Function |
1268 | #End Region |
1269 | |
1270 | ''' <summary> |
1271 | ''' 阶乘 |
1272 | ''' </summary> |
1273 | ''' <param name="a"></param> |
1274 | ''' <returns></returns> |
1275 | Public Function Factorial(a As Integer) As Double |
1276 | If a <= 1 Then |
1277 | Return 1 |
1278 | Else |
1279 | Dim n As Double = a |
1280 | |
1281 | For i As Integer = a - 1 To 1 Step -1 |
1282 | n *= i |
1283 | Next |
1284 | |
1285 | Return n |
1286 | End If |
1287 | End Function |
1288 | |
1289 | Public Iterator Function FactorialSequence(a As Integer) As IEnumerable(Of Integer) |
1290 | If a <= 1 Then |
1291 | Yield 1 |
1292 | Else |
1293 | For i As Integer = a To 1 Step -1 |
1294 | Yield i |
1295 | Next |
1296 | End If |
1297 | End Function |
1298 | |
1299 | ''' <summary> |
1300 | ''' Returns the covariance of two data vectors. </summary> |
1301 | ''' <param name="a"> double[] of data </param> |
1302 | ''' <param name="b"> double[] of data |
1303 | ''' @return the covariance of a and b, cov(a,b) </param> |
1304 | Public Function Covariance(a As Double(), b As Double()) As Double |
1305 | If a.Length <> b.Length Then |
1306 | Throw New ArgumentException("Cannot take covariance of different dimension vectors.") |
1307 | End If |
1308 | |
1309 | Dim divisor As Double = a.Length - 1 |
1310 | Dim sum As Double = 0 |
1311 | Dim aMean As Double = a.Average |
1312 | Dim bMean As Double = b.Average |
1313 | |
1314 | For i As Integer = 0 To a.Length - 1 |
1315 | sum += (a(i) - aMean) * (b(i) - bMean) |
1316 | Next |
1317 | |
1318 | Return sum / divisor |
1319 | End Function |
1320 | |
1321 | ''' <summary> |
1322 | ''' 请注意,<paramref name="data"/>的元素数量必须要和<paramref name="weights"/>的长度相等 |
1323 | ''' </summary> |
1324 | ''' <param name="data"></param> |
1325 | ''' <param name="weights">这个数组里面的值的和必须要等于1</param> |
1326 | ''' <returns></returns> |
1327 | <Extension> |
1328 | Public Function WeighedAverage(data As IEnumerable(Of Double), ParamArray weights As Double()) As Double |
1329 | Dim avg# |
1330 | |
1331 | For Each x As SeqValue(Of Double) In data.SeqIterator |
1332 | avg += (x.value * weights(x)) |
1333 | Next |
1334 | |
1335 | Return avg |
1336 | End Function |
1337 | |
1338 | ''' <summary> |
1339 | ''' [Sequence Generation] Generate regular sequences. seq is a standard generic with a default method. |
1340 | ''' </summary> |
1341 | ''' <param name="From"> |
1342 | ''' the starting and (maximal) end values of the sequence. Of length 1 unless just from is supplied as an unnamed argument. |
1343 | ''' </param> |
1344 | ''' <param name="To"> |
1345 | ''' the starting and (maximal) end values of the sequence. Of length 1 unless just from is supplied as an unnamed argument. |
1346 | ''' </param> |
1347 | ''' <param name="By">number: increment of the sequence</param> |
1348 | ''' <returns></returns> |
1349 | ''' <remarks></remarks> |
1350 | ''' |
1351 | <Extension> |
1352 | Public Iterator Function seq([from] As Value(Of Double), [to] As Double, Optional by As Double = 0.1) As IEnumerable(Of Double) |
1353 | Yield from |
1354 | |
1355 | Do While (from = from.Value + by) <= [to] |
1356 | Yield from |
1357 | Loop |
1358 | End Function |
1359 | |
1360 | <Extension> |
1361 | Public Iterator Function seq(range As DoubleRange, Optional steps# = 0.1) As IEnumerable(Of Double) |
1362 | For Each x# In seq(range.Min, range.Max, steps) |
1363 | Yield x# |
1364 | Next |
1365 | End Function |
1366 | |
1367 | ''' <summary> |
1368 | ''' 以 N 为底的对数 ``LogN(X) = Log(X) / Log(N)`` |
1369 | ''' </summary> |
1370 | ''' <param name="x"></param> |
1371 | ''' <param name="N"></param> |
1372 | ''' <returns></returns> |
1373 | ''' |
1374 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1375 | Public Function LogN(x As Double, N As Double) As Double |
1376 | Return sys.Log(x) / sys.Log(N) |
1377 | End Function |
1378 | |
1379 | ''' <summary> |
1380 | ''' return the maximum of a, b and c </summary> |
1381 | ''' <param name="a"> </param> |
1382 | ''' <param name="b"> </param> |
1383 | ''' <param name="c"> |
1384 | ''' @return </param> |
1385 | ''' |
1386 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1387 | Public Function Max(a As Integer, b As Integer, c As Integer) As Integer |
1388 | Return sys.Max(a, sys.Max(b, c)) |
1389 | End Function |
1390 | |
1391 | ''' <summary> |
1392 | ''' sqrt(a^2 + b^2) without under/overflow. |
1393 | ''' </summary> |
1394 | ''' <param name="a"></param> |
1395 | ''' <param name="b"></param> |
1396 | ''' <returns></returns> |
1397 | |
1398 | Public Function Hypot(a As Double, b As Double) As Double |
1399 | Dim r As Double |
1400 | |
1401 | If sys.Abs(a) > sys.Abs(b) Then |
1402 | r = b / a |
1403 | r = sys.Abs(a) * sys.Sqrt(1 + r * r) |
1404 | ElseIf b <> 0 Then |
1405 | r = a / b |
1406 | r = sys.Abs(b) * sys.Sqrt(1 + r * r) |
1407 | Else |
1408 | r = 0.0 |
1409 | End If |
1410 | |
1411 | Return r |
1412 | End Function |
1413 | |
1414 | ''' <summary> |
1415 | ''' Calculates power of 2. |
1416 | ''' </summary> |
1417 | ''' |
1418 | ''' <param name="power">Power to raise in.</param> |
1419 | ''' |
1420 | ''' <returns>Returns specified power of 2 in the case if power is in the range of |
1421 | ''' [0, 30]. Otherwise returns 0.</returns> |
1422 | ''' |
1423 | Public Function Pow2(power As Integer) As Integer |
1424 | Return If(((power >= 0) AndAlso (power <= 30)), (1 << power), 0) |
1425 | End Function |
1426 | |
1427 | ''' <summary> |
1428 | ''' Get base of binary logarithm. |
1429 | ''' </summary> |
1430 | ''' |
1431 | ''' <param name="x">Source integer number.</param> |
1432 | ''' |
1433 | ''' <returns>Power of the number (base of binary logarithm).</returns> |
1434 | ''' |
1435 | Public Function Log2(x As Integer) As Integer |
1436 | If x <= 65536 Then |
1437 | If x <= 256 Then |
1438 | If x <= 16 Then |
1439 | If x <= 4 Then |
1440 | If x <= 2 Then |
1441 | If x <= 1 Then |
1442 | Return 0 |
1443 | End If |
1444 | Return 1 |
1445 | End If |
1446 | Return 2 |
1447 | End If |
1448 | If x <= 8 Then |
1449 | Return 3 |
1450 | End If |
1451 | Return 4 |
1452 | End If |
1453 | If x <= 64 Then |
1454 | If x <= 32 Then |
1455 | Return 5 |
1456 | End If |
1457 | Return 6 |
1458 | End If |
1459 | If x <= 128 Then |
1460 | Return 7 |
1461 | End If |
1462 | Return 8 |
1463 | End If |
1464 | If x <= 4096 Then |
1465 | If x <= 1024 Then |
1466 | If x <= 512 Then |
1467 | Return 9 |
1468 | End If |
1469 | Return 10 |
1470 | End If |
1471 | If x <= 2048 Then |
1472 | Return 11 |
1473 | End If |
1474 | Return 12 |
1475 | End If |
1476 | If x <= 16384 Then |
1477 | If x <= 8192 Then |
1478 | Return 13 |
1479 | End If |
1480 | Return 14 |
1481 | End If |
1482 | If x <= 32768 Then |
1483 | Return 15 |
1484 | End If |
1485 | Return 16 |
1486 | End If |
1487 | |
1488 | If x <= 16777216 Then |
1489 | If x <= 1048576 Then |
1490 | If x <= 262144 Then |
1491 | If x <= 131072 Then |
1492 | Return 17 |
1493 | End If |
1494 | Return 18 |
1495 | End If |
1496 | If x <= 524288 Then |
1497 | Return 19 |
1498 | End If |
1499 | Return 20 |
1500 | End If |
1501 | If x <= 4194304 Then |
1502 | If x <= 2097152 Then |
1503 | Return 21 |
1504 | End If |
1505 | Return 22 |
1506 | End If |
1507 | If x <= 8388608 Then |
1508 | Return 23 |
1509 | End If |
1510 | Return 24 |
1511 | End If |
1512 | If x <= 268435456 Then |
1513 | If x <= 67108864 Then |
1514 | If x <= 33554432 Then |
1515 | Return 25 |
1516 | End If |
1517 | Return 26 |
1518 | End If |
1519 | If x <= 134217728 Then |
1520 | Return 27 |
1521 | End If |
1522 | Return 28 |
1523 | End If |
1524 | If x <= 1073741824 Then |
1525 | If x <= 536870912 Then |
1526 | Return 29 |
1527 | End If |
1528 | Return 30 |
1529 | End If |
1530 | Return 31 |
1531 | End Function |
1532 | |
1533 | ''' <summary> |
1534 | ''' Checks if the specified integer is power of 2. |
1535 | ''' </summary> |
1536 | ''' |
1537 | ''' <param name="x">Integer number to check.</param> |
1538 | ''' |
1539 | ''' <returns>Returns <b>true</b> if the specified number is power of 2. |
1540 | ''' Otherwise returns <b>false</b>.</returns> |
1541 | ''' |
1542 | <Extension> |
1543 | Public Function IsPowerOf2(x As Integer) As Boolean |
1544 | Return If((x > 0), ((x And (x - 1)) = 0), False) |
1545 | End Function |
1546 | |
1547 | ''' <summary> |
1548 | ''' Logical true values are regarded as one, false values as zero. For historical reasons, NULL is accepted and treated as if it were integer(0). |
1549 | ''' </summary> |
1550 | ''' <param name="bc"></param> |
1551 | ''' <returns></returns> |
1552 | ''' <remarks></remarks> |
1553 | ''' |
1554 | <ExportAPI("Sum")> |
1555 | <Extension> Public Function Sum(bc As IEnumerable(Of Boolean)) As Double |
1556 | If bc Is Nothing Then |
1557 | Return 0 |
1558 | Else |
1559 | Return bc _ |
1560 | .Select(Function(b) If(True = b, 1.0R, 0R)) _ |
1561 | .Sum |
1562 | End If |
1563 | End Function |
1564 | |
1565 | ''' <summary> |
1566 | ''' 计算出所有的数的乘积 |
1567 | ''' </summary> |
1568 | ''' <param name="[in]"></param> |
1569 | ''' <returns></returns> |
1570 | <Extension> |
1571 | Public Function ProductALL([in] As IEnumerable(Of Double)) As Double |
1572 | Dim product# = 1 |
1573 | |
1574 | For Each x As Double In [in] |
1575 | product *= x |
1576 | Next |
1577 | |
1578 | Return product |
1579 | End Function |
1580 | |
1581 | ''' <summary> |
1582 | ''' 计算出所有的数的乘积 |
1583 | ''' </summary> |
1584 | ''' <param name="[in]"></param> |
1585 | ''' <returns></returns> |
1586 | ''' |
1587 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1588 | <Extension> |
1589 | Public Function ProductALL([in] As IEnumerable(Of Integer)) As Double |
1590 | Return [in].Select(Function(x) CDbl(x)).ProductALL |
1591 | End Function |
1592 | |
1593 | ''' <summary> |
1594 | ''' ## Standard Deviation |
1595 | ''' |
1596 | ''' In statistics, the standard deviation (SD, also represented by the Greek letter sigma σ or the Latin letter s) |
1597 | ''' is a measure that is used to quantify the amount of variation or dispersion of a set of data values. A low |
1598 | ''' standard deviation indicates that the data points tend to be close to the mean (also called the expected value) |
1599 | ''' of the set, while a high standard deviation indicates that the data points are spread out over a wider range of |
1600 | ''' values. |
1601 | ''' |
1602 | ''' > https://en.wikipedia.org/wiki/Standard_deviation |
1603 | ''' </summary> |
1604 | ''' <returns></returns> |
1605 | ''' <remarks></remarks> |
1606 | ''' |
1607 | <ExportAPI("STD", Info:="Standard Deviation")> |
1608 | <Extension> Public Function SD(values As IEnumerable(Of Double)) As Double |
1609 | Dim data#() = values.ToArray |
1610 | Dim avg# = data.Average |
1611 | Dim sumValue# = Aggregate n As Double In data Into Sum((n - avg) ^ 2) |
1612 | Return sys.Sqrt(sumValue / data.Length) |
1613 | End Function |
1614 | |
1615 | ''' <summary> |
1616 | ''' Standard Deviation |
1617 | ''' </summary> |
1618 | ''' <returns></returns> |
1619 | ''' <remarks></remarks> |
1620 | ''' |
1621 | <ExportAPI("STD", Info:="Standard Deviation")> |
1622 | <Extension> Public Function SD(values As IEnumerable(Of Integer)) As Double |
1623 | Return values.Select(Function(x) CDbl(x)).SD |
1624 | End Function |
1625 | |
1626 | ''' <summary> |
1627 | ''' Standard Deviation |
1628 | ''' </summary> |
1629 | ''' <returns></returns> |
1630 | ''' <remarks></remarks> |
1631 | ''' |
1632 | <ExportAPI("STD", Info:="Standard Deviation")> |
1633 | <Extension> Public Function SD(values As IEnumerable(Of Long)) As Double |
1634 | Return values.Select(Function(x) CDbl(x)).SD |
1635 | End Function |
1636 | |
1637 | ''' <summary> |
1638 | ''' Standard Deviation |
1639 | ''' </summary> |
1640 | ''' <returns></returns> |
1641 | ''' <remarks></remarks> |
1642 | ''' |
1643 | <ExportAPI("STD", Info:="Standard Deviation")> |
1644 | <Extension> Public Function SD(values As IEnumerable(Of Single)) As Double |
1645 | Return values.Select(Function(x) CDbl(x)).SD |
1646 | End Function |
1647 | |
1648 | ''' <summary> |
1649 | ''' 多位坐标的欧几里得距离,与坐标点0进行比较 |
1650 | ''' </summary> |
1651 | ''' <param name="vector"></param> |
1652 | ''' <returns></returns> |
1653 | ''' <remarks></remarks> |
1654 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1655 | <ExportAPI("Euclidean", Info:="Euclidean Distance")> |
1656 | <Extension> Public Function EuclideanDistance(vector As IEnumerable(Of Double)) As Double |
1657 | ' 由于是和令进行比较,减零仍然为原来的数,所以这里直接使用n^2了 |
1658 | Return sys.Sqrt((From n In vector Select n ^ 2).Sum) |
1659 | End Function |
1660 | |
1661 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1662 | <ExportAPI("Euclidean", Info:="Euclidean Distance")> |
1663 | <Extension> Public Function EuclideanDistance(Vector As IEnumerable(Of Integer)) As Double |
1664 | Return sys.Sqrt((From n In Vector Select n ^ 2).Sum) |
1665 | End Function |
1666 | |
1667 | <ExportAPI("Euclidean", Info:="Euclidean Distance")> |
1668 | <Extension> Public Function EuclideanDistance(a As IEnumerable(Of Integer), b As IEnumerable(Of Integer)) As Double |
1669 | If a.Count <> b.Count Then |
1670 | Return -1 |
1671 | Else |
1672 | Return sys.Sqrt((From i As Integer In a.Sequence Select (a(i) - b(i)) ^ 2).Sum) |
1673 | End If |
1674 | End Function |
1675 | |
1676 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1677 | <ExportAPI("Euclidean", Info:="Euclidean Distance")> |
1678 | <Extension> Public Function EuclideanDistance(a As IEnumerable(Of Double), b As IEnumerable(Of Double)) As Double |
1679 | Return EuclideanDistance(a.ToArray, b.ToArray) |
1680 | End Function |
1681 | |
1682 | ''' <summary> |
1683 | ''' |
1684 | ''' </summary> |
1685 | ''' <param name="a">Point A</param> |
1686 | ''' <param name="b">Point B</param> |
1687 | ''' <returns></returns> |
1688 | <ExportAPI("Euclidean", Info:="Euclidean Distance")> |
1689 | <Extension> Public Function EuclideanDistance(a As Byte(), b As Byte()) As Double |
1690 | If a.Length <> b.Length Then |
1691 | Return -1.0R |
1692 | Else |
1693 | Return sys.Sqrt((From i As Integer In a.Sequence Select (CInt(a(i)) - CInt(b(i))) ^ 2).Sum) |
1694 | End If |
1695 | End Function |
1696 | |
1697 | ''' <summary> |
1698 | ''' 计算两个向量之间的欧氏距离,请注意,这两个向量的长度必须要相等 |
1699 | ''' </summary> |
1700 | ''' <param name="a">Point A</param> |
1701 | ''' <param name="b">Point B</param> |
1702 | ''' <returns></returns> |
1703 | <ExportAPI("Euclidean", Info:="Euclidean Distance")> |
1704 | <Extension> Public Function EuclideanDistance(a As Double(), b As Double()) As Double |
1705 | If a.Length <> b.Length Then |
1706 | Return -1.0R |
1707 | Else |
1708 | Return sys.Sqrt((From i As Integer In a.Sequence Select (a(i) - b(i)) ^ 2).Sum) |
1709 | End If |
1710 | End Function |
1711 | |
1712 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1713 | <Extension> |
1714 | Public Function Distance(pt As (X#, Y#), x#, y#) As Double |
1715 | Return {pt.X, pt.Y}.EuclideanDistance({x, y}) |
1716 | End Function |
1717 | |
1718 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1719 | <ExportAPI("RangesAt")> |
1720 | <Extension> Public Function RangesAt(n As Double, LowerBound As Double, UpBound As Double) As Boolean |
1721 | Return n <= UpBound AndAlso n > LowerBound |
1722 | End Function |
1723 | |
1724 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1725 | <ExportAPI("RangesAt")> |
1726 | <Extension> Public Function RangesAt(n As Integer, LowerBound As Double, UpBound As Double) As Boolean |
1727 | Return n <= UpBound AndAlso n > LowerBound |
1728 | End Function |
1729 | |
1730 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1731 | <ExportAPI("RangesAt")> |
1732 | <Extension> Public Function RangesAt(n As Long, LowerBound As Double, UpBound As Double) As Boolean |
1733 | Return n <= UpBound AndAlso n > LowerBound |
1734 | End Function |
1735 | |
1736 | ''' <summary> |
1737 | ''' Root mean square.(均方根) |
1738 | ''' </summary> |
1739 | ''' <returns></returns> |
1740 | ''' |
1741 | <ExportAPI("RMS", Info:="Root mean square")> |
1742 | <Extension> Public Function RMS(data As IEnumerable(Of Double)) As Double |
1743 | With (From n In data Select n ^ 2).ToArray |
1744 | Return sys.Sqrt(.Sum / .Length) |
1745 | End With |
1746 | End Function |
1747 | |
1748 | ''' <summary> |
1749 | ''' ``相对标准偏差(RSD)= 标准偏差(SD)/ 计算结果的算术平均值(X)* 100%`` |
1750 | ''' </summary> |
1751 | ''' <param name="data"></param> |
1752 | ''' <returns></returns> |
1753 | <Extension> |
1754 | Public Function RSD(data As IEnumerable(Of Double)) As Double |
1755 | Return data.SD / data.Average |
1756 | End Function |
1757 | |
1758 | ''' <summary> |
1759 | ''' Returns the PDF value at x for the specified Poisson distribution. |
1760 | ''' </summary> |
1761 | ''' |
1762 | <ExportAPI("Poisson.PDF", Info:="Returns the PDF value at x for the specified Poisson distribution.")> |
1763 | Public Function PoissonPDF(x As Integer, lambda As Double) As Double |
1764 | Dim result As Double = sys.Exp(-lambda) |
1765 | Dim k As Integer = x |
1766 | |
1767 | While k >= 1 |
1768 | result *= lambda / k |
1769 | k -= 1 |
1770 | End While |
1771 | |
1772 | Return result |
1773 | End Function |
1774 | |
1775 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
1776 | <Extension> |
1777 | Public Function FormatNumeric(v As IEnumerable(Of Double), Optional digitals% = 2) As String() |
1778 | Return v.Select(Function(x) x.ToString("F" & digitals)).ToArray |
1779 | End Function |
1780 | End Module |
1781 | End Namespace |