1 /*
2 * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28
29 #include "mpdecimal.h"
30
31 #include <stddef.h>
32 #include <stdint.h>
33
34
35 /* Signaling wrappers for the quiet functions in mpdecimal.c. */
36
37
38 char *
mpd_format(const mpd_t * dec,const char * fmt,mpd_context_t * ctx)39 mpd_format(const mpd_t *dec, const char *fmt, mpd_context_t *ctx)
40 {
41 char *ret;
42 uint32_t status = 0;
43 ret = mpd_qformat(dec, fmt, ctx, &status);
44 mpd_addstatus_raise(ctx, status);
45 return ret;
46 }
47
48 void
mpd_import_u16(mpd_t * result,const uint16_t * srcdata,size_t srclen,uint8_t srcsign,uint32_t base,mpd_context_t * ctx)49 mpd_import_u16(mpd_t *result, const uint16_t *srcdata, size_t srclen,
50 uint8_t srcsign, uint32_t base, mpd_context_t *ctx)
51 {
52 uint32_t status = 0;
53 mpd_qimport_u16(result, srcdata, srclen, srcsign, base, ctx, &status);
54 mpd_addstatus_raise(ctx, status);
55 }
56
57 void
mpd_import_u32(mpd_t * result,const uint32_t * srcdata,size_t srclen,uint8_t srcsign,uint32_t base,mpd_context_t * ctx)58 mpd_import_u32(mpd_t *result, const uint32_t *srcdata, size_t srclen,
59 uint8_t srcsign, uint32_t base, mpd_context_t *ctx)
60 {
61 uint32_t status = 0;
62 mpd_qimport_u32(result, srcdata, srclen, srcsign, base, ctx, &status);
63 mpd_addstatus_raise(ctx, status);
64 }
65
66 size_t
mpd_export_u16(uint16_t ** rdata,size_t rlen,uint32_t base,const mpd_t * src,mpd_context_t * ctx)67 mpd_export_u16(uint16_t **rdata, size_t rlen, uint32_t base, const mpd_t *src,
68 mpd_context_t *ctx)
69 {
70 size_t n;
71 uint32_t status = 0;
72 n = mpd_qexport_u16(rdata, rlen, base, src, &status);
73 mpd_addstatus_raise(ctx, status);
74 return n;
75 }
76
77 size_t
mpd_export_u32(uint32_t ** rdata,size_t rlen,uint32_t base,const mpd_t * src,mpd_context_t * ctx)78 mpd_export_u32(uint32_t **rdata, size_t rlen, uint32_t base, const mpd_t *src,
79 mpd_context_t *ctx)
80 {
81 size_t n;
82 uint32_t status = 0;
83 n = mpd_qexport_u32(rdata, rlen, base, src, &status);
84 mpd_addstatus_raise(ctx, status);
85 return n;
86 }
87
88 void
mpd_finalize(mpd_t * result,mpd_context_t * ctx)89 mpd_finalize(mpd_t *result, mpd_context_t *ctx)
90 {
91 uint32_t status = 0;
92 mpd_qfinalize(result, ctx, &status);
93 mpd_addstatus_raise(ctx, status);
94 }
95
96 int
mpd_check_nan(mpd_t * result,const mpd_t * a,mpd_context_t * ctx)97 mpd_check_nan(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
98 {
99 uint32_t status = 0;
100 if (mpd_qcheck_nan(result, a, ctx, &status)) {
101 mpd_addstatus_raise(ctx, status);
102 return 1;
103 }
104 return 0;
105 }
106
107 int
mpd_check_nans(mpd_t * result,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)108 mpd_check_nans(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
109 {
110 uint32_t status = 0;
111 if (mpd_qcheck_nans(result, a, b, ctx, &status)) {
112 mpd_addstatus_raise(ctx, status);
113 return 1;
114 }
115 return 0;
116 }
117
118 void
mpd_set_string(mpd_t * result,const char * s,mpd_context_t * ctx)119 mpd_set_string(mpd_t *result, const char *s, mpd_context_t *ctx)
120 {
121 uint32_t status = 0;
122 mpd_qset_string(result, s, ctx, &status);
123 mpd_addstatus_raise(ctx, status);
124 }
125
126 void
mpd_maxcoeff(mpd_t * result,mpd_context_t * ctx)127 mpd_maxcoeff(mpd_t *result, mpd_context_t *ctx)
128 {
129 uint32_t status = 0;
130 mpd_qmaxcoeff(result, ctx, &status);
131 mpd_addstatus_raise(ctx, status);
132 }
133
134 /* set static mpd from signed integer */
135 void
mpd_sset_ssize(mpd_t * result,mpd_ssize_t a,mpd_context_t * ctx)136 mpd_sset_ssize(mpd_t *result, mpd_ssize_t a, mpd_context_t *ctx)
137 {
138 uint32_t status = 0;
139 mpd_qsset_ssize(result, a, ctx, &status);
140 mpd_addstatus_raise(ctx, status);
141 }
142
143 void
mpd_sset_i32(mpd_t * result,int32_t a,mpd_context_t * ctx)144 mpd_sset_i32(mpd_t *result, int32_t a, mpd_context_t *ctx)
145 {
146 uint32_t status = 0;
147 mpd_qsset_i32(result, a, ctx, &status);
148 mpd_addstatus_raise(ctx, status);
149 }
150
151 #ifdef CONFIG_64
152 void
mpd_sset_i64(mpd_t * result,int64_t a,mpd_context_t * ctx)153 mpd_sset_i64(mpd_t *result, int64_t a, mpd_context_t *ctx)
154 {
155 uint32_t status = 0;
156 mpd_qsset_i64(result, a, ctx, &status);
157 mpd_addstatus_raise(ctx, status);
158 }
159 #endif
160
161 /* set static mpd from unsigned integer */
162 void
mpd_sset_uint(mpd_t * result,mpd_uint_t a,mpd_context_t * ctx)163 mpd_sset_uint(mpd_t *result, mpd_uint_t a, mpd_context_t *ctx)
164 {
165 uint32_t status = 0;
166 mpd_qsset_uint(result, a, ctx, &status);
167 mpd_addstatus_raise(ctx, status);
168 }
169
170 void
mpd_sset_u32(mpd_t * result,uint32_t a,mpd_context_t * ctx)171 mpd_sset_u32(mpd_t *result, uint32_t a, mpd_context_t *ctx)
172 {
173 uint32_t status = 0;
174 mpd_qsset_u32(result, a, ctx, &status);
175 mpd_addstatus_raise(ctx, status);
176 }
177
178 #ifdef CONFIG_64
179 void
mpd_sset_u64(mpd_t * result,uint64_t a,mpd_context_t * ctx)180 mpd_sset_u64(mpd_t *result, uint64_t a, mpd_context_t *ctx)
181 {
182 uint32_t status = 0;
183 mpd_qsset_u64(result, a, ctx, &status);
184 mpd_addstatus_raise(ctx, status);
185 }
186 #endif
187
188 /* set mpd from signed integer */
189 void
mpd_set_ssize(mpd_t * result,mpd_ssize_t a,mpd_context_t * ctx)190 mpd_set_ssize(mpd_t *result, mpd_ssize_t a, mpd_context_t *ctx)
191 {
192 uint32_t status = 0;
193 mpd_qset_ssize(result, a, ctx, &status);
194 mpd_addstatus_raise(ctx, status);
195 }
196
197 void
mpd_set_i32(mpd_t * result,int32_t a,mpd_context_t * ctx)198 mpd_set_i32(mpd_t *result, int32_t a, mpd_context_t *ctx)
199 {
200 uint32_t status = 0;
201 mpd_qset_i32(result, a, ctx, &status);
202 mpd_addstatus_raise(ctx, status);
203 }
204
205 #ifndef LEGACY_COMPILER
206 void
mpd_set_i64(mpd_t * result,int64_t a,mpd_context_t * ctx)207 mpd_set_i64(mpd_t *result, int64_t a, mpd_context_t *ctx)
208 {
209 uint32_t status = 0;
210 mpd_qset_i64(result, a, ctx, &status);
211 mpd_addstatus_raise(ctx, status);
212 }
213 #endif
214
215 /* set mpd from unsigned integer */
216 void
mpd_set_uint(mpd_t * result,mpd_uint_t a,mpd_context_t * ctx)217 mpd_set_uint(mpd_t *result, mpd_uint_t a, mpd_context_t *ctx)
218 {
219 uint32_t status = 0;
220 mpd_qset_uint(result, a, ctx, &status);
221 mpd_addstatus_raise(ctx, status);
222 }
223
224 void
mpd_set_u32(mpd_t * result,uint32_t a,mpd_context_t * ctx)225 mpd_set_u32(mpd_t *result, uint32_t a, mpd_context_t *ctx)
226 {
227 uint32_t status = 0;
228 mpd_qset_u32(result, a, ctx, &status);
229 mpd_addstatus_raise(ctx, status);
230 }
231
232 #ifndef LEGACY_COMPILER
233 void
mpd_set_u64(mpd_t * result,uint64_t a,mpd_context_t * ctx)234 mpd_set_u64(mpd_t *result, uint64_t a, mpd_context_t *ctx)
235 {
236 uint32_t status = 0;
237 mpd_qset_u64(result, a, ctx, &status);
238 mpd_addstatus_raise(ctx, status);
239 }
240 #endif
241
242 /* convert mpd to signed integer */
243 mpd_ssize_t
mpd_get_ssize(const mpd_t * a,mpd_context_t * ctx)244 mpd_get_ssize(const mpd_t *a, mpd_context_t *ctx)
245 {
246 uint32_t status = 0;
247 mpd_ssize_t ret;
248
249 ret = mpd_qget_ssize(a, &status);
250 mpd_addstatus_raise(ctx, status);
251 return ret;
252 }
253
254 int32_t
mpd_get_i32(const mpd_t * a,mpd_context_t * ctx)255 mpd_get_i32(const mpd_t *a, mpd_context_t *ctx)
256 {
257 uint32_t status = 0;
258 int32_t ret;
259
260 ret = mpd_qget_i32(a, &status);
261 mpd_addstatus_raise(ctx, status);
262 return ret;
263 }
264
265 #ifndef LEGACY_COMPILER
266 int64_t
mpd_get_i64(const mpd_t * a,mpd_context_t * ctx)267 mpd_get_i64(const mpd_t *a, mpd_context_t *ctx)
268 {
269 uint32_t status = 0;
270 int64_t ret;
271
272 ret = mpd_qget_i64(a, &status);
273 mpd_addstatus_raise(ctx, status);
274 return ret;
275 }
276 #endif
277
278 mpd_uint_t
mpd_get_uint(const mpd_t * a,mpd_context_t * ctx)279 mpd_get_uint(const mpd_t *a, mpd_context_t *ctx)
280 {
281 uint32_t status = 0;
282 mpd_uint_t ret;
283
284 ret = mpd_qget_uint(a, &status);
285 mpd_addstatus_raise(ctx, status);
286 return ret;
287 }
288
289 mpd_uint_t
mpd_abs_uint(const mpd_t * a,mpd_context_t * ctx)290 mpd_abs_uint(const mpd_t *a, mpd_context_t *ctx)
291 {
292 uint32_t status = 0;
293 mpd_uint_t ret;
294
295 ret = mpd_qabs_uint(a, &status);
296 mpd_addstatus_raise(ctx, status);
297 return ret;
298 }
299
300 uint32_t
mpd_get_u32(const mpd_t * a,mpd_context_t * ctx)301 mpd_get_u32(const mpd_t *a, mpd_context_t *ctx)
302 {
303 uint32_t status = 0;
304 uint32_t ret;
305
306 ret = mpd_qget_u32(a, &status);
307 mpd_addstatus_raise(ctx, status);
308 return ret;
309 }
310
311 #ifndef LEGACY_COMPILER
312 uint64_t
mpd_get_u64(const mpd_t * a,mpd_context_t * ctx)313 mpd_get_u64(const mpd_t *a, mpd_context_t *ctx)
314 {
315 uint32_t status = 0;
316 uint64_t ret;
317
318 ret = mpd_qget_u64(a, &status);
319 mpd_addstatus_raise(ctx, status);
320 return ret;
321 }
322 #endif
323
324 void
mpd_and(mpd_t * result,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)325 mpd_and(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
326 {
327 uint32_t status = 0;
328 mpd_qand(result, a, b, ctx, &status);
329 mpd_addstatus_raise(ctx, status);
330 }
331
332 void
mpd_copy(mpd_t * result,const mpd_t * a,mpd_context_t * ctx)333 mpd_copy(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
334 {
335 uint32_t status = 0;
336 if (!mpd_qcopy(result, a, &status)) {
337 mpd_addstatus_raise(ctx, status);
338 }
339 }
340
341 void
mpd_canonical(mpd_t * result,const mpd_t * a,mpd_context_t * ctx)342 mpd_canonical(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
343 {
344 mpd_copy(result, a, ctx);
345 }
346
347 void
mpd_copy_abs(mpd_t * result,const mpd_t * a,mpd_context_t * ctx)348 mpd_copy_abs(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
349 {
350 uint32_t status = 0;
351 if (!mpd_qcopy_abs(result, a, &status)) {
352 mpd_addstatus_raise(ctx, status);
353 }
354 }
355
356 void
mpd_copy_negate(mpd_t * result,const mpd_t * a,mpd_context_t * ctx)357 mpd_copy_negate(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
358 {
359 uint32_t status = 0;
360 if (!mpd_qcopy_negate(result, a, &status)) {
361 mpd_addstatus_raise(ctx, status);
362 }
363 }
364
365 void
mpd_copy_sign(mpd_t * result,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)366 mpd_copy_sign(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
367 {
368 uint32_t status = 0;
369 if (!mpd_qcopy_sign(result, a, b, &status)) {
370 mpd_addstatus_raise(ctx, status);
371 }
372 }
373
374 void
mpd_invert(mpd_t * result,const mpd_t * a,mpd_context_t * ctx)375 mpd_invert(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
376 {
377 uint32_t status = 0;
378 mpd_qinvert(result, a, ctx, &status);
379 mpd_addstatus_raise(ctx, status);
380 }
381
382 void
mpd_logb(mpd_t * result,const mpd_t * a,mpd_context_t * ctx)383 mpd_logb(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
384 {
385 uint32_t status = 0;
386 mpd_qlogb(result, a, ctx, &status);
387 mpd_addstatus_raise(ctx, status);
388 }
389
390 void
mpd_or(mpd_t * result,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)391 mpd_or(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
392 {
393 uint32_t status = 0;
394 mpd_qor(result, a, b, ctx, &status);
395 mpd_addstatus_raise(ctx, status);
396 }
397
398 void
mpd_rotate(mpd_t * result,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)399 mpd_rotate(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
400 {
401 uint32_t status = 0;
402 mpd_qrotate(result, a, b, ctx, &status);
403 mpd_addstatus_raise(ctx, status);
404 }
405
406 void
mpd_scaleb(mpd_t * result,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)407 mpd_scaleb(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
408 {
409 uint32_t status = 0;
410 mpd_qscaleb(result, a, b, ctx, &status);
411 mpd_addstatus_raise(ctx, status);
412 }
413
414 void
mpd_shiftl(mpd_t * result,const mpd_t * a,mpd_ssize_t n,mpd_context_t * ctx)415 mpd_shiftl(mpd_t *result, const mpd_t *a, mpd_ssize_t n, mpd_context_t *ctx)
416 {
417 uint32_t status = 0;
418 mpd_qshiftl(result, a, n, &status);
419 mpd_addstatus_raise(ctx, status);
420 }
421
422 mpd_uint_t
mpd_shiftr(mpd_t * result,const mpd_t * a,mpd_ssize_t n,mpd_context_t * ctx)423 mpd_shiftr(mpd_t *result, const mpd_t *a, mpd_ssize_t n, mpd_context_t *ctx)
424 {
425 uint32_t status = 0;
426 mpd_uint_t rnd;
427
428 rnd = mpd_qshiftr(result, a, n, &status);
429 mpd_addstatus_raise(ctx, status);
430 return rnd;
431 }
432
433 void
mpd_shiftn(mpd_t * result,const mpd_t * a,mpd_ssize_t n,mpd_context_t * ctx)434 mpd_shiftn(mpd_t *result, const mpd_t *a, mpd_ssize_t n, mpd_context_t *ctx)
435 {
436 uint32_t status = 0;
437 mpd_qshiftn(result, a, n, ctx, &status);
438 mpd_addstatus_raise(ctx, status);
439 }
440
441 void
mpd_shift(mpd_t * result,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)442 mpd_shift(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
443 {
444 uint32_t status = 0;
445 mpd_qshift(result, a, b, ctx, &status);
446 mpd_addstatus_raise(ctx, status);
447 }
448
449 void
mpd_xor(mpd_t * result,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)450 mpd_xor(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
451 {
452 uint32_t status = 0;
453 mpd_qxor(result, a, b, ctx, &status);
454 mpd_addstatus_raise(ctx, status);
455 }
456
457 void
mpd_abs(mpd_t * result,const mpd_t * a,mpd_context_t * ctx)458 mpd_abs(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
459 {
460 uint32_t status = 0;
461 mpd_qabs(result, a, ctx, &status);
462 mpd_addstatus_raise(ctx, status);
463 }
464
465 int
mpd_cmp(const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)466 mpd_cmp(const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
467 {
468 uint32_t status = 0;
469 int c;
470 c = mpd_qcmp(a, b, &status);
471 mpd_addstatus_raise(ctx, status);
472 return c;
473 }
474
475 int
mpd_compare(mpd_t * result,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)476 mpd_compare(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
477 {
478 uint32_t status = 0;
479 int c;
480 c = mpd_qcompare(result, a, b, ctx, &status);
481 mpd_addstatus_raise(ctx, status);
482 return c;
483 }
484
485 int
mpd_compare_signal(mpd_t * result,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)486 mpd_compare_signal(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
487 {
488 uint32_t status = 0;
489 int c;
490 c = mpd_qcompare_signal(result, a, b, ctx, &status);
491 mpd_addstatus_raise(ctx, status);
492 return c;
493 }
494
495 void
mpd_add(mpd_t * result,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)496 mpd_add(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
497 {
498 uint32_t status = 0;
499 mpd_qadd(result, a, b, ctx, &status);
500 mpd_addstatus_raise(ctx, status);
501 }
502
503 void
mpd_sub(mpd_t * result,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)504 mpd_sub(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
505 {
506 uint32_t status = 0;
507 mpd_qsub(result, a, b, ctx, &status);
508 mpd_addstatus_raise(ctx, status);
509 }
510
511 void
mpd_add_ssize(mpd_t * result,const mpd_t * a,mpd_ssize_t b,mpd_context_t * ctx)512 mpd_add_ssize(mpd_t *result, const mpd_t *a, mpd_ssize_t b, mpd_context_t *ctx)
513 {
514 uint32_t status = 0;
515 mpd_qadd_ssize(result, a, b, ctx, &status);
516 mpd_addstatus_raise(ctx, status);
517 }
518
519 void
mpd_add_i32(mpd_t * result,const mpd_t * a,int32_t b,mpd_context_t * ctx)520 mpd_add_i32(mpd_t *result, const mpd_t *a, int32_t b, mpd_context_t *ctx)
521 {
522 uint32_t status = 0;
523 mpd_qadd_i32(result, a, b, ctx, &status);
524 mpd_addstatus_raise(ctx, status);
525 }
526
527 #ifndef LEGACY_COMPILER
528 void
mpd_add_i64(mpd_t * result,const mpd_t * a,int64_t b,mpd_context_t * ctx)529 mpd_add_i64(mpd_t *result, const mpd_t *a, int64_t b, mpd_context_t *ctx)
530 {
531 uint32_t status = 0;
532 mpd_qadd_i64(result, a, b, ctx, &status);
533 mpd_addstatus_raise(ctx, status);
534 }
535 #endif
536
537 void
mpd_add_uint(mpd_t * result,const mpd_t * a,mpd_uint_t b,mpd_context_t * ctx)538 mpd_add_uint(mpd_t *result, const mpd_t *a, mpd_uint_t b, mpd_context_t *ctx)
539 {
540 uint32_t status = 0;
541 mpd_qadd_uint(result, a, b, ctx, &status);
542 mpd_addstatus_raise(ctx, status);
543 }
544
545 void
mpd_add_u32(mpd_t * result,const mpd_t * a,uint32_t b,mpd_context_t * ctx)546 mpd_add_u32(mpd_t *result, const mpd_t *a, uint32_t b, mpd_context_t *ctx)
547 {
548 uint32_t status = 0;
549 mpd_qadd_u32(result, a, b, ctx, &status);
550 mpd_addstatus_raise(ctx, status);
551 }
552
553 #ifndef LEGACY_COMPILER
554 void
mpd_add_u64(mpd_t * result,const mpd_t * a,uint64_t b,mpd_context_t * ctx)555 mpd_add_u64(mpd_t *result, const mpd_t *a, uint64_t b, mpd_context_t *ctx)
556 {
557 uint32_t status = 0;
558 mpd_qadd_u64(result, a, b, ctx, &status);
559 mpd_addstatus_raise(ctx, status);
560 }
561 #endif
562
563 void
mpd_sub_ssize(mpd_t * result,const mpd_t * a,mpd_ssize_t b,mpd_context_t * ctx)564 mpd_sub_ssize(mpd_t *result, const mpd_t *a, mpd_ssize_t b, mpd_context_t *ctx)
565 {
566 uint32_t status = 0;
567 mpd_qsub_ssize(result, a, b, ctx, &status);
568 mpd_addstatus_raise(ctx, status);
569 }
570
571 void
mpd_sub_i32(mpd_t * result,const mpd_t * a,int32_t b,mpd_context_t * ctx)572 mpd_sub_i32(mpd_t *result, const mpd_t *a, int32_t b, mpd_context_t *ctx)
573 {
574 uint32_t status = 0;
575 mpd_qsub_i32(result, a, b, ctx, &status);
576 mpd_addstatus_raise(ctx, status);
577 }
578
579 #ifndef LEGACY_COMPILER
580 void
mpd_sub_i64(mpd_t * result,const mpd_t * a,int64_t b,mpd_context_t * ctx)581 mpd_sub_i64(mpd_t *result, const mpd_t *a, int64_t b, mpd_context_t *ctx)
582 {
583 uint32_t status = 0;
584 mpd_qsub_i64(result, a, b, ctx, &status);
585 mpd_addstatus_raise(ctx, status);
586 }
587 #endif
588
589 void
mpd_sub_uint(mpd_t * result,const mpd_t * a,mpd_uint_t b,mpd_context_t * ctx)590 mpd_sub_uint(mpd_t *result, const mpd_t *a, mpd_uint_t b, mpd_context_t *ctx)
591 {
592 uint32_t status = 0;
593 mpd_qsub_uint(result, a, b, ctx, &status);
594 mpd_addstatus_raise(ctx, status);
595 }
596
597 void
mpd_sub_u32(mpd_t * result,const mpd_t * a,uint32_t b,mpd_context_t * ctx)598 mpd_sub_u32(mpd_t *result, const mpd_t *a, uint32_t b, mpd_context_t *ctx)
599 {
600 uint32_t status = 0;
601 mpd_qsub_u32(result, a, b, ctx, &status);
602 mpd_addstatus_raise(ctx, status);
603 }
604
605 #ifndef LEGACY_COMPILER
606 void
mpd_sub_u64(mpd_t * result,const mpd_t * a,uint64_t b,mpd_context_t * ctx)607 mpd_sub_u64(mpd_t *result, const mpd_t *a, uint64_t b, mpd_context_t *ctx)
608 {
609 uint32_t status = 0;
610 mpd_qsub_u64(result, a, b, ctx, &status);
611 mpd_addstatus_raise(ctx, status);
612 }
613 #endif
614
615 void
mpd_div(mpd_t * q,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)616 mpd_div(mpd_t *q, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
617 {
618 uint32_t status = 0;
619 mpd_qdiv(q, a, b, ctx, &status);
620 mpd_addstatus_raise(ctx, status);
621 }
622
623 void
mpd_div_ssize(mpd_t * result,const mpd_t * a,mpd_ssize_t b,mpd_context_t * ctx)624 mpd_div_ssize(mpd_t *result, const mpd_t *a, mpd_ssize_t b, mpd_context_t *ctx)
625 {
626 uint32_t status = 0;
627 mpd_qdiv_ssize(result, a, b, ctx, &status);
628 mpd_addstatus_raise(ctx, status);
629 }
630
631 void
mpd_div_i32(mpd_t * result,const mpd_t * a,int32_t b,mpd_context_t * ctx)632 mpd_div_i32(mpd_t *result, const mpd_t *a, int32_t b, mpd_context_t *ctx)
633 {
634 uint32_t status = 0;
635 mpd_qdiv_i32(result, a, b, ctx, &status);
636 mpd_addstatus_raise(ctx, status);
637 }
638
639 #ifndef LEGACY_COMPILER
640 void
mpd_div_i64(mpd_t * result,const mpd_t * a,int64_t b,mpd_context_t * ctx)641 mpd_div_i64(mpd_t *result, const mpd_t *a, int64_t b, mpd_context_t *ctx)
642 {
643 uint32_t status = 0;
644 mpd_qdiv_i64(result, a, b, ctx, &status);
645 mpd_addstatus_raise(ctx, status);
646 }
647 #endif
648
649 void
mpd_div_uint(mpd_t * result,const mpd_t * a,mpd_uint_t b,mpd_context_t * ctx)650 mpd_div_uint(mpd_t *result, const mpd_t *a, mpd_uint_t b, mpd_context_t *ctx)
651 {
652 uint32_t status = 0;
653 mpd_qdiv_uint(result, a, b, ctx, &status);
654 mpd_addstatus_raise(ctx, status);
655 }
656
657 void
mpd_div_u32(mpd_t * result,const mpd_t * a,uint32_t b,mpd_context_t * ctx)658 mpd_div_u32(mpd_t *result, const mpd_t *a, uint32_t b, mpd_context_t *ctx)
659 {
660 uint32_t status = 0;
661 mpd_qdiv_u32(result, a, b, ctx, &status);
662 mpd_addstatus_raise(ctx, status);
663 }
664
665 #ifndef LEGACY_COMPILER
666 void
mpd_div_u64(mpd_t * result,const mpd_t * a,uint64_t b,mpd_context_t * ctx)667 mpd_div_u64(mpd_t *result, const mpd_t *a, uint64_t b, mpd_context_t *ctx)
668 {
669 uint32_t status = 0;
670 mpd_qdiv_u64(result, a, b, ctx, &status);
671 mpd_addstatus_raise(ctx, status);
672 }
673 #endif
674
675 void
mpd_divmod(mpd_t * q,mpd_t * r,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)676 mpd_divmod(mpd_t *q, mpd_t *r, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
677 {
678 uint32_t status = 0;
679 mpd_qdivmod(q, r, a, b, ctx, &status);
680 mpd_addstatus_raise(ctx, status);
681 }
682
683 void
mpd_divint(mpd_t * q,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)684 mpd_divint(mpd_t *q, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
685 {
686 uint32_t status = 0;
687 mpd_qdivint(q, a, b, ctx, &status);
688 mpd_addstatus_raise(ctx, status);
689 }
690
691 void
mpd_exp(mpd_t * result,const mpd_t * a,mpd_context_t * ctx)692 mpd_exp(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
693 {
694 uint32_t status = 0;
695 mpd_qexp(result, a, ctx, &status);
696 mpd_addstatus_raise(ctx, status);
697 }
698
699 void
mpd_fma(mpd_t * result,const mpd_t * a,const mpd_t * b,const mpd_t * c,mpd_context_t * ctx)700 mpd_fma(mpd_t *result, const mpd_t *a, const mpd_t *b, const mpd_t *c,
701 mpd_context_t *ctx)
702 {
703 uint32_t status = 0;
704 mpd_qfma(result, a, b, c, ctx, &status);
705 mpd_addstatus_raise(ctx, status);
706 }
707
708 void
mpd_ln(mpd_t * result,const mpd_t * a,mpd_context_t * ctx)709 mpd_ln(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
710 {
711 uint32_t status = 0;
712 mpd_qln(result, a, ctx, &status);
713 mpd_addstatus_raise(ctx, status);
714 }
715
716 void
mpd_log10(mpd_t * result,const mpd_t * a,mpd_context_t * ctx)717 mpd_log10(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
718 {
719 uint32_t status = 0;
720 mpd_qlog10(result, a, ctx, &status);
721 mpd_addstatus_raise(ctx, status);
722 }
723
724 void
mpd_max(mpd_t * result,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)725 mpd_max(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
726 {
727 uint32_t status = 0;
728 mpd_qmax(result, a, b, ctx, &status);
729 mpd_addstatus_raise(ctx, status);
730 }
731
732 void
mpd_max_mag(mpd_t * result,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)733 mpd_max_mag(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
734 {
735 uint32_t status = 0;
736 mpd_qmax_mag(result, a, b, ctx, &status);
737 mpd_addstatus_raise(ctx, status);
738 }
739
740 void
mpd_min(mpd_t * result,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)741 mpd_min(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
742 {
743 uint32_t status = 0;
744 mpd_qmin(result, a, b, ctx, &status);
745 mpd_addstatus_raise(ctx, status);
746 }
747
748 void
mpd_min_mag(mpd_t * result,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)749 mpd_min_mag(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
750 {
751 uint32_t status = 0;
752 mpd_qmin_mag(result, a, b, ctx, &status);
753 mpd_addstatus_raise(ctx, status);
754 }
755
756 void
mpd_minus(mpd_t * result,const mpd_t * a,mpd_context_t * ctx)757 mpd_minus(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
758 {
759 uint32_t status = 0;
760 mpd_qminus(result, a, ctx, &status);
761 mpd_addstatus_raise(ctx, status);
762 }
763
764 void
mpd_mul(mpd_t * result,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)765 mpd_mul(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
766 {
767 uint32_t status = 0;
768 mpd_qmul(result, a, b, ctx, &status);
769 mpd_addstatus_raise(ctx, status);
770 }
771
772 void
mpd_mul_ssize(mpd_t * result,const mpd_t * a,mpd_ssize_t b,mpd_context_t * ctx)773 mpd_mul_ssize(mpd_t *result, const mpd_t *a, mpd_ssize_t b, mpd_context_t *ctx)
774 {
775 uint32_t status = 0;
776 mpd_qmul_ssize(result, a, b, ctx, &status);
777 mpd_addstatus_raise(ctx, status);
778 }
779
780 void
mpd_mul_i32(mpd_t * result,const mpd_t * a,int32_t b,mpd_context_t * ctx)781 mpd_mul_i32(mpd_t *result, const mpd_t *a, int32_t b, mpd_context_t *ctx)
782 {
783 uint32_t status = 0;
784 mpd_qmul_i32(result, a, b, ctx, &status);
785 mpd_addstatus_raise(ctx, status);
786 }
787
788 #ifndef LEGACY_COMPILER
789 void
mpd_mul_i64(mpd_t * result,const mpd_t * a,int64_t b,mpd_context_t * ctx)790 mpd_mul_i64(mpd_t *result, const mpd_t *a, int64_t b, mpd_context_t *ctx)
791 {
792 uint32_t status = 0;
793 mpd_qmul_i64(result, a, b, ctx, &status);
794 mpd_addstatus_raise(ctx, status);
795 }
796 #endif
797
798 void
mpd_mul_uint(mpd_t * result,const mpd_t * a,mpd_uint_t b,mpd_context_t * ctx)799 mpd_mul_uint(mpd_t *result, const mpd_t *a, mpd_uint_t b, mpd_context_t *ctx)
800 {
801 uint32_t status = 0;
802 mpd_qmul_uint(result, a, b, ctx, &status);
803 mpd_addstatus_raise(ctx, status);
804 }
805
806 void
mpd_mul_u32(mpd_t * result,const mpd_t * a,uint32_t b,mpd_context_t * ctx)807 mpd_mul_u32(mpd_t *result, const mpd_t *a, uint32_t b, mpd_context_t *ctx)
808 {
809 uint32_t status = 0;
810 mpd_qmul_u32(result, a, b, ctx, &status);
811 mpd_addstatus_raise(ctx, status);
812 }
813
814 #ifndef LEGACY_COMPILER
815 void
mpd_mul_u64(mpd_t * result,const mpd_t * a,uint64_t b,mpd_context_t * ctx)816 mpd_mul_u64(mpd_t *result, const mpd_t *a, uint64_t b, mpd_context_t *ctx)
817 {
818 uint32_t status = 0;
819 mpd_qmul_u64(result, a, b, ctx, &status);
820 mpd_addstatus_raise(ctx, status);
821 }
822 #endif
823
824 void
mpd_next_minus(mpd_t * result,const mpd_t * a,mpd_context_t * ctx)825 mpd_next_minus(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
826 {
827 uint32_t status = 0;
828 mpd_qnext_minus(result, a, ctx, &status);
829 mpd_addstatus_raise(ctx, status);
830 }
831
832 void
mpd_next_plus(mpd_t * result,const mpd_t * a,mpd_context_t * ctx)833 mpd_next_plus(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
834 {
835 uint32_t status = 0;
836 mpd_qnext_plus(result, a, ctx, &status);
837 mpd_addstatus_raise(ctx, status);
838 }
839
840 void
mpd_next_toward(mpd_t * result,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)841 mpd_next_toward(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
842 {
843 uint32_t status = 0;
844 mpd_qnext_toward(result, a, b, ctx, &status);
845 mpd_addstatus_raise(ctx, status);
846 }
847
848 void
mpd_plus(mpd_t * result,const mpd_t * a,mpd_context_t * ctx)849 mpd_plus(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
850 {
851 uint32_t status = 0;
852 mpd_qplus(result, a, ctx, &status);
853 mpd_addstatus_raise(ctx, status);
854 }
855
856 void
mpd_pow(mpd_t * result,const mpd_t * base,const mpd_t * exp,mpd_context_t * ctx)857 mpd_pow(mpd_t *result, const mpd_t *base, const mpd_t *exp, mpd_context_t *ctx)
858 {
859 uint32_t status = 0;
860 mpd_qpow(result, base, exp, ctx, &status);
861 mpd_addstatus_raise(ctx, status);
862 }
863
864 void
mpd_powmod(mpd_t * result,const mpd_t * base,const mpd_t * exp,const mpd_t * mod,mpd_context_t * ctx)865 mpd_powmod(mpd_t *result, const mpd_t *base, const mpd_t *exp, const mpd_t *mod,
866 mpd_context_t *ctx)
867 {
868 uint32_t status = 0;
869 mpd_qpowmod(result, base, exp, mod, ctx, &status);
870 mpd_addstatus_raise(ctx, status);
871 }
872
873 void
mpd_quantize(mpd_t * result,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)874 mpd_quantize(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
875 {
876 uint32_t status = 0;
877 mpd_qquantize(result, a, b, ctx, &status);
878 mpd_addstatus_raise(ctx, status);
879 }
880
881 void
mpd_rescale(mpd_t * result,const mpd_t * a,mpd_ssize_t exp,mpd_context_t * ctx)882 mpd_rescale(mpd_t *result, const mpd_t *a, mpd_ssize_t exp, mpd_context_t *ctx)
883 {
884 uint32_t status = 0;
885 mpd_qrescale(result, a, exp, ctx, &status);
886 mpd_addstatus_raise(ctx, status);
887 }
888
889 void
mpd_reduce(mpd_t * result,const mpd_t * a,mpd_context_t * ctx)890 mpd_reduce(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
891 {
892 uint32_t status = 0;
893 mpd_qreduce(result, a, ctx, &status);
894 mpd_addstatus_raise(ctx, status);
895 }
896
897 void
mpd_rem(mpd_t * r,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)898 mpd_rem(mpd_t *r, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
899 {
900 uint32_t status = 0;
901 mpd_qrem(r, a, b, ctx, &status);
902 mpd_addstatus_raise(ctx, status);
903 }
904
905 void
mpd_rem_near(mpd_t * r,const mpd_t * a,const mpd_t * b,mpd_context_t * ctx)906 mpd_rem_near(mpd_t *r, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx)
907 {
908 uint32_t status = 0;
909 mpd_qrem_near(r, a, b, ctx, &status);
910 mpd_addstatus_raise(ctx, status);
911 }
912
913 void
mpd_round_to_intx(mpd_t * result,const mpd_t * a,mpd_context_t * ctx)914 mpd_round_to_intx(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
915 {
916 uint32_t status = 0;
917 mpd_qround_to_intx(result, a, ctx, &status);
918 mpd_addstatus_raise(ctx, status);
919 }
920
921 void
mpd_round_to_int(mpd_t * result,const mpd_t * a,mpd_context_t * ctx)922 mpd_round_to_int(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
923 {
924 uint32_t status = 0;
925 mpd_qround_to_int(result, a, ctx, &status);
926 mpd_addstatus_raise(ctx, status);
927 }
928
929 void
mpd_trunc(mpd_t * result,const mpd_t * a,mpd_context_t * ctx)930 mpd_trunc(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
931 {
932 uint32_t status = 0;
933 mpd_qtrunc(result, a, ctx, &status);
934 mpd_addstatus_raise(ctx, status);
935 }
936
937 void
mpd_floor(mpd_t * result,const mpd_t * a,mpd_context_t * ctx)938 mpd_floor(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
939 {
940 uint32_t status = 0;
941 mpd_qfloor(result, a, ctx, &status);
942 mpd_addstatus_raise(ctx, status);
943 }
944
945 void
mpd_ceil(mpd_t * result,const mpd_t * a,mpd_context_t * ctx)946 mpd_ceil(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
947 {
948 uint32_t status = 0;
949 mpd_qceil(result, a, ctx, &status);
950 mpd_addstatus_raise(ctx, status);
951 }
952
953 void
mpd_sqrt(mpd_t * result,const mpd_t * a,mpd_context_t * ctx)954 mpd_sqrt(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
955 {
956 uint32_t status = 0;
957 mpd_qsqrt(result, a, ctx, &status);
958 mpd_addstatus_raise(ctx, status);
959 }
960
961 void
mpd_invroot(mpd_t * result,const mpd_t * a,mpd_context_t * ctx)962 mpd_invroot(mpd_t *result, const mpd_t *a, mpd_context_t *ctx)
963 {
964 uint32_t status = 0;
965 mpd_qinvroot(result, a, ctx, &status);
966 mpd_addstatus_raise(ctx, status);
967 }
968