1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package apd
16
17
18 func MakeErrDecimal(c *Context) ErrDecimal {
19 return ErrDecimal{
20 Ctx: c,
21 }
22 }
23
24
25
26
27 type ErrDecimal struct {
28 err error
29 Ctx *Context
30
31 Flags Condition
32 }
33
34
35
36 func (e *ErrDecimal) Err() error {
37 if e.err != nil {
38 return e.err
39 }
40 if e.Ctx != nil {
41 _, e.err = e.Ctx.goError(e.Flags)
42 return e.err
43 }
44 return nil
45 }
46
47
48 func (e *ErrDecimal) update(res Condition, err error) {
49 e.Flags |= res
50 e.err = err
51 }
52
53
54 func (e *ErrDecimal) Abs(d, x *Decimal) *Decimal {
55 if e.Err() != nil {
56 return d
57 }
58 e.update(e.Ctx.Abs(d, x))
59 return d
60 }
61
62
63 func (e *ErrDecimal) Add(d, x, y *Decimal) *Decimal {
64 if e.Err() != nil {
65 return d
66 }
67 e.update(e.Ctx.Add(d, x, y))
68 return d
69 }
70
71
72 func (e *ErrDecimal) Ceil(d, x *Decimal) *Decimal {
73 if e.Err() != nil {
74 return d
75 }
76 e.update(e.Ctx.Ceil(d, x))
77 return d
78 }
79
80
81 func (e *ErrDecimal) Exp(d, x *Decimal) *Decimal {
82 if e.Err() != nil {
83 return d
84 }
85 e.update(e.Ctx.Exp(d, x))
86 return d
87 }
88
89
90 func (e *ErrDecimal) Floor(d, x *Decimal) *Decimal {
91 if e.Err() != nil {
92 return d
93 }
94 e.update(e.Ctx.Floor(d, x))
95 return d
96 }
97
98
99 func (e *ErrDecimal) Int64(d *Decimal) int64 {
100 if e.Err() != nil {
101 return 0
102 }
103 var r int64
104 r, e.err = d.Int64()
105 return r
106 }
107
108
109 func (e *ErrDecimal) Ln(d, x *Decimal) *Decimal {
110 if e.Err() != nil {
111 return d
112 }
113 e.update(e.Ctx.Ln(d, x))
114 return d
115 }
116
117
118 func (e *ErrDecimal) Log10(d, x *Decimal) *Decimal {
119 if e.Err() != nil {
120 return d
121 }
122 e.update(e.Ctx.Log10(d, x))
123 return d
124 }
125
126
127 func (e *ErrDecimal) Mul(d, x, y *Decimal) *Decimal {
128 if e.Err() != nil {
129 return d
130 }
131 e.update(e.Ctx.Mul(d, x, y))
132 return d
133 }
134
135
136 func (e *ErrDecimal) Neg(d, x *Decimal) *Decimal {
137 if e.Err() != nil {
138 return d
139 }
140 e.update(e.Ctx.Neg(d, x))
141 return d
142 }
143
144
145 func (e *ErrDecimal) Pow(d, x, y *Decimal) *Decimal {
146 if e.Err() != nil {
147 return d
148 }
149 e.update(e.Ctx.Pow(d, x, y))
150 return d
151 }
152
153
154 func (e *ErrDecimal) Quantize(d, v *Decimal, exp int32) *Decimal {
155 if e.Err() != nil {
156 return d
157 }
158 e.update(e.Ctx.Quantize(d, v, exp))
159 return d
160 }
161
162
163 func (e *ErrDecimal) Quo(d, x, y *Decimal) *Decimal {
164 if e.Err() != nil {
165 return d
166 }
167 e.update(e.Ctx.Quo(d, x, y))
168 return d
169 }
170
171
172 func (e *ErrDecimal) QuoInteger(d, x, y *Decimal) *Decimal {
173 if e.Err() != nil {
174 return d
175 }
176 e.update(e.Ctx.QuoInteger(d, x, y))
177 return d
178 }
179
180
181
182 func (e *ErrDecimal) Reduce(d, x *Decimal) (int, *Decimal) {
183 if e.Err() != nil {
184 return 0, d
185 }
186 n, res, err := e.Ctx.Reduce(d, x)
187 e.update(res, err)
188 return n, d
189 }
190
191
192 func (e *ErrDecimal) Rem(d, x, y *Decimal) *Decimal {
193 if e.Err() != nil {
194 return d
195 }
196 e.update(e.Ctx.Rem(d, x, y))
197 return d
198 }
199
200
201 func (e *ErrDecimal) Round(d, x *Decimal) *Decimal {
202 if e.Err() != nil {
203 return d
204 }
205 e.update(e.Ctx.Round(d, x))
206 return d
207 }
208
209
210 func (e *ErrDecimal) Sqrt(d, x *Decimal) *Decimal {
211 if e.Err() != nil {
212 return d
213 }
214 e.update(e.Ctx.Sqrt(d, x))
215 return d
216 }
217
218
219 func (e *ErrDecimal) Sub(d, x, y *Decimal) *Decimal {
220 if e.Err() != nil {
221 return d
222 }
223 e.update(e.Ctx.Sub(d, x, y))
224 return d
225 }
226
227
228 func (e *ErrDecimal) RoundToIntegralValue(d, x *Decimal) *Decimal {
229 if e.Err() != nil {
230 return d
231 }
232 e.update(e.Ctx.RoundToIntegralValue(d, x))
233 return d
234 }
235
236
237 func (e *ErrDecimal) RoundToIntegralExact(d, x *Decimal) *Decimal {
238 if e.Err() != nil {
239 return d
240 }
241 e.update(e.Ctx.RoundToIntegralExact(d, x))
242 return d
243 }
244
View as plain text