-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathMathHelper.bas
More file actions
83 lines (49 loc) · 1.77 KB
/
MathHelper.bas
File metadata and controls
83 lines (49 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
Attribute VB_Name = "MathHelper"
'--------------------------------------------------------------------------------
' Component : MathHelper
' Project : ViDock
'
' Description: Contains Math helper functions
'
'--------------------------------------------------------------------------------
Option Explicit
Public Function RoundIt(ByVal lngSrcNumber As Integer, ByVal lngByNumber As Integer)
'Round(12, 5)
Dim lngModResult As Long
lngModResult = (lngSrcNumber Mod lngByNumber)
If lngModResult >= lngByNumber Then
RoundIt = CLng(SymArith(lngSrcNumber / lngByNumber, 0) * lngByNumber + 1)
Else
RoundIt = CLng(SymArith(lngSrcNumber / lngByNumber, 0) * lngByNumber)
End If
End Function
Public Function SymArith(ByVal X As Double, _
Optional ByVal DecimalPlaces As Double = 1) As Double
SymArith = Fix(X * (10 ^ DecimalPlaces) + 0.5 * Sgn(X)) / (10 ^ DecimalPlaces)
End Function
Public Function Floor(ByVal Number) As Long
Floor = Fix(Number)
If Number >= 0 Then
If Number = Int(Number) Then
Floor = Number
Else
Floor = Int(Number)
End If
ElseIf Number < 0 Then
Floor = Int(Number) - 1
End If
End Function
Public Function Ceiling(ByVal Number) As Long
If Number >= 0 Then
If Number = Int(Number) Then
Ceiling = Number
Else
Ceiling = Int(Number) + 1
End If
ElseIf Number < 0 Then
Ceiling = Int(Number)
End If
End Function
Public Function Sqrt(X As Double) As Double
Sqrt = X ^ (1 / 2)
End Function