source: Include/com/decimal.ab@ 211

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

Decimalを追加、OAIdl.abの一応の完成など

File size: 4.4 KB
Line 
1' com/decimal.ab
2
3#require <oleauto.ab>
4#require <com/variant.ab>
5
6Class Decimal
7Public
8 Sub Decimal(ByRef d As Decimal)
9 dec = d
10 End Sub
11
12 Const Function Operator +() As Decimal
13 Return New Decimal(dec)
14 End Function
15
16 Const Function Operator -() As Decimal
17 Dim ret = New Decimal
18 VarDecNeg(This.dec, ret.dec)
19 Return ret
20 End Function
21
22 Const Function Operator *(y As Decimal) As Decimal
23 Dim ret = New Decimal
24 VarDecMul(This.dec, y.dec, ret.dec)
25 Return ret
26 End Function
27
28 Const Function Operator *(y As Long) As Decimal
29 Dim ret = New Decimal
30 VarDecMulI4(This.dec, y, ret.dec)
31 Return ret
32 End Function
33
34 Const Function Operator *(y As Int64) As Decimal
35 Dim ret = New Decimal
36 VarDecMulI8(This.dec, y, ret.dec)
37 Return ret
38 End Function
39
40 Const Function Operator /(y As Decimal) As Decimal
41 Dim ret = New Decimal
42 VarDecDiv(This.dec, y.dec, ret.dec)
43 Return ret
44 End Function
45
46 Const Function Operator +(y As Decimal) As Decimal
47 Dim ret = New Decimal
48 VarDecAdd(This.dec, y.dec, ret.dec)
49 Return ret
50 End Function
51
52 Const Function Operator -(y As Decimal) As Decimal
53 Dim ret = New Decimal
54 VarDecSub(This.dec, y.dec, ret.dec)
55 Return ret
56 End Function
57
58 Static Function Compare(x As Decimal, y As Decimal) As HRESULT
59 Return VarDecCmp(x, y)
60 End Function
61
62 Static Function Compare(x As Decimal, y As Double) As HRESULT
63 Return VarDecCmpR8(x, y)
64 End Function
65
66 Static Function Compare(x As Double, y As Decimal) As HRESULT
67 Dim ret = VarDecCmpR8(y, x)
68 Select Case ret
69 Case VARCMP_LT
70 Return VARCMP_GT
71 Case VARCMP_GT
72 Return VARCMP_LT
73 Case Else
74 Return ret
75 End Select
76 End Function
77
78 Const Function Operator ==(y As Decimal) As Boolean
79 Dim c = Compare(This, y)
80 Return c = VARCMP_EQ
81 End Function
82
83 Const Function Operator ==(y As Double) As Boolean
84 Dim c = Compare(This, y)
85 Return c = VARCMP_EQ
86 End Function
87
88 Const Function Operator <>(y As Decimal) As Boolean
89 Dim c = Compare(This, y)
90 Return c <> VARCMP_EQ
91 End Function
92
93 Const Function Operator <>(y As Double) As Boolean
94 Dim c = Compare(This, y)
95 Return c <> VARCMP_EQ
96 End Function
97
98 Const Function Operator <(y As Decimal) As Boolean
99 Dim c = Compare(This, y)
100 Return c = VARCMP_LT
101 End Function
102
103 Const Function Operator <(y As Double) As Boolean
104 Dim c = Compare(This, y)
105 Return c = VARCMP_LT
106 End Function
107/*
108 Const Function Operator >(y As Decimal) As Boolean
109 Dim c = Compare(This, y)
110 Return c = VARCMP_GT
111 End Function
112
113 Const Function Operator >(y As Double) As Boolean
114 Dim c = Compare(This, y)
115 Return c = VARCMP_GT
116 End Function
117*/
118 Const Function Operator <=(y As Decimal) As Boolean
119 Dim c = Compare(This, y)
120 Return result = VARCMP_LT Or result = VARCMP_EQ
121 End Function
122
123 Const Function Operator <=(y As Double) As Boolean
124 Dim c = Compare(This, y)
125 Return result = VARCMP_LT Or result = VARCMP_EQ
126 End Function
127
128 Const Function Operator >=(y As Decimal) As Boolean
129 Dim c = Compare(This, y)
130 Return result = VARCMP_GT Or result = VARCMP_EQ
131 End Function
132
133 Const Function Operator >=(y As Double) As Boolean
134 Dim c = Compare(This, y)
135 Return result = VARCMP_GT Or result = VARCMP_EQ
136 End Function
137
138 Const Function Abs() As Decimal
139 Abs = New Decimal
140 VarDecAbs(This.dec, Abs.dec)
141 End Function
142
143 Const Function Fix() As Decimal
144 Fix = New Decimal
145 VarDecFix(This.dec, Fix.dec)
146 End Function
147
148 Const Function Int() As Decimal
149 Int = New Decimal
150 VarDecInt(This.dec, Int.dec)
151 End Function
152
153 Const Function Round(c = 0 As Long) As Decimal
154 Round = New Decimal
155 VarDecRound(This.dec, c, Round.dec)
156 End Function
157
158 Const Function Dec() As DECIMAL
159 Return dec
160 End Function
161
162 Sub Dec(ByRef d As DECIMAL)
163 dec = d
164 End Sub
165
166 Const Function ToVariant() As Variant
167 Return New Variant(dec)
168 End Function
169
170 Override Function ToString() As String
171 Dim bs As BSTR
172 VarBstrFromDec(dec, LOCALE_USER_DEFAULT, LOCALE_USE_NLS, bs)
173 ToString = New String(bs As PCWSTR, SysStringLen(bs) As Long)
174 SysFreeString(bs)
175 End Function
176
177 Override Function GetHashCode() As Long
178 Dim p = VarPtr(dec) As *DWord
179 Return (p[0] Xor p[1] Xor p[2] Xor p[3]) As Long
180 End Function
181
182 Function Equals(y As Decimal) As Boolean
183 Dim c = Compare(This, y)
184 Return c = VARCMP_EQ
185 End Function
186Private
187 dec As DECIMAL
188End Class
Note: See TracBrowser for help on using the repository browser.