Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(121832)

Side by Side Diff: Modules/_decimal/libmpdec/mpdecimal.h

Issue 7652: Merge C version of decimal into py3k.
Patch Set: Created 7 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Modules/_decimal/libmpdec/mpdecimal.c ('k') | Modules/_decimal/libmpdec/numbertheory.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2008-2010 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 #ifndef MPDECIMAL_H
30 #define MPDECIMAL_H
31
32
33 #ifdef __cplusplus
34 extern "C" {
35 #define __STDC_LIMIT_MACROS
36 #endif
37
38
39 #ifndef _MSC_VER
40 #include "pyconfig.h"
41 #endif
42
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <string.h>
46 #include <limits.h>
47 #include <assert.h>
48
49 #ifdef _MSC_VER
50 #include "vccompat.h"
51 #ifndef UNUSED
52 #define UNUSED
53 #endif
54 #define EXTINLINE extern inline
55 #else
56 #ifdef HAVE_STDINT_H
57 #include <stdint.h>
58 #endif
59 #ifdef HAVE_INTTYPES_H
60 #include <inttypes.h>
61 #endif
62 #ifndef __GNUC_STDC_INLINE__
63 #define __GNUC_STDC_INLINE__
64 #endif
65 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
66 #define UNUSED __attribute__((unused))
67 #else
68 #define UNUSED
69 #endif
70 #define EXTINLINE
71 #endif
72
73
74 #if !defined(LEGACY_COMPILER)
75 #if !defined(UINT64_MAX)
76 /* The following #error is just a warning. If the compiler indeed does
77 * not have uint64_t, it is perfectly safe to comment out the #error. */
78 #error "Warning: Compiler without uint64_t. Comment out this line."
79 #define LEGACY_COMPILER
80 #endif
81 #endif
82
83
84 /******************************************************************************/
85 /* Configuration */
86 /******************************************************************************/
87
88 #if defined(UNIVERSAL)
89 #if defined(CONFIG_64) || defined(CONFIG_32)
90 #error "cannot use CONFIG_64 or CONFIG_32 with UNIVERSAL."
91 #endif
92 #if defined(__ppc__)
93 #define CONFIG_32
94 #define ANSI
95 #elif defined(__ppc64__)
96 #define CONFIG_64
97 #define ANSI
98 #elif defined(__i386__)
99 #define CONFIG_32
100 #define ANSI
101 #elif defined(__x86_64__)
102 #define CONFIG_64
103 #define ASM
104 #else
105 #error "unknown architecture for universal build."
106 #endif
107 #endif
108
109
110 /* BEGIN CONFIG_64 */
111 #if defined(CONFIG_64)
112 /* types for modular and base arithmetic */
113 #define MPD_UINT_MAX UINT64_MAX
114 #define MPD_BITS_PER_UINT 64
115 typedef uint64_t mpd_uint_t; /* unsigned mod type */
116
117 #define MPD_SIZE_MAX SIZE_MAX
118 typedef size_t mpd_size_t; /* unsigned size type */
119
120 /* type for exp, digits, len, prec */
121 #define MPD_SSIZE_MAX INT64_MAX
122 #define MPD_SSIZE_MIN INT64_MIN
123 typedef int64_t mpd_ssize_t;
124 #define _mpd_strtossize strtoll
125
126 /* decimal arithmetic */
127 #define MPD_RADIX 10000000000000000000ULL /* 10**19 */
128 #define MPD_RDIGITS 19
129 #define MPD_MAX_POW10 19
130 #define MPD_EXPDIGITS 19 /* MPD_EXPDIGITS <= MPD_RDIGITS+1 */
131
132 #define MPD_MAXTRANSFORM_2N 4294967296ULL /* 2**32 */
133 #define MPD_MAX_PREC 999999999999999999LL
134 #define MPD_MAX_PREC_LOG2 64
135 #define MPD_ELIMIT 1000000000000000000LL
136 #define MPD_MAX_EMAX 999999999999999999LL /* ELIMIT-1 */
137 #define MPD_MIN_EMIN (-999999999999999999LL) /* -EMAX */
138 #define MPD_MIN_ETINY (MPD_MIN_EMIN-(MPD_MAX_PREC-1))
139 #define MPD_EXP_INF 2000000000000000001LL
140 #define MPD_EXP_CLAMP (-4000000000000000001LL)
141 #define MPD_MAXIMPORT 105263157894736842L /* ceil((2*MPD_MAX_PREC)/MPD_RDIGITS) */
142
143 /* conversion specifiers */
144 #define PRI_mpd_uint_t PRIu64
145 #define PRI_mpd_ssize_t PRIi64
146 /* END CONFIG_64 */
147
148
149 /* BEGIN CONFIG_32 */
150 #elif defined(CONFIG_32)
151 /* types for modular and base arithmetic */
152 #define MPD_UINT_MAX UINT32_MAX
153 #define MPD_BITS_PER_UINT 32
154 typedef uint32_t mpd_uint_t; /* unsigned mod type */
155
156 #ifndef LEGACY_COMPILER
157 #define MPD_UUINT_MAX UINT64_MAX
158 typedef uint64_t mpd_uuint_t; /* double width unsigned mod type */
159 #endif
160
161 #define MPD_SIZE_MAX SIZE_MAX
162 typedef size_t mpd_size_t; /* unsigned size type */
163
164 /* type for dec->len, dec->exp, ctx->prec */
165 #define MPD_SSIZE_MAX INT32_MAX
166 #define MPD_SSIZE_MIN INT32_MIN
167 typedef int32_t mpd_ssize_t;
168 #define _mpd_strtossize strtol
169
170 /* decimal arithmetic */
171 #define MPD_RADIX 1000000000UL /* 10**9 */
172 #define MPD_RDIGITS 9
173 #define MPD_MAX_POW10 9
174 #define MPD_EXPDIGITS 10 /* MPD_EXPDIGITS <= MPD_RDIGITS+1 */
175
176 #define MPD_MAXTRANSFORM_2N 33554432UL /* 2**25 */
177 #define MPD_MAX_PREC 425000000L
178 #define MPD_MAX_PREC_LOG2 32
179 #define MPD_ELIMIT 425000001L
180 #define MPD_MAX_EMAX 425000000L /* ELIMIT-1 */
181 #define MPD_MIN_EMIN (-425000000L) /* -EMAX */
182 #define MPD_MIN_ETINY (MPD_MIN_EMIN-(MPD_MAX_PREC-1))
183 #define MPD_EXP_INF 1000000001L /* allows for emax=999999999 in the tests * /
184 #define MPD_EXP_CLAMP (-2000000001L) /* allows for emin=-999999999 in the tests */
185 #define MPD_MAXIMPORT 94444445L /* ceil((2*MPD_MAX_PREC)/MPD_RDIGITS) */
186
187 /* conversion specifiers */
188 #define PRI_mpd_uint_t PRIu32
189 #define PRI_mpd_ssize_t PRIi32
190 /* END CONFIG_32 */
191
192 #else
193 #error "define CONFIG_64 or CONFIG_32"
194 #endif
195 /* END CONFIG */
196
197
198 #if MPD_SIZE_MAX != MPD_UINT_MAX
199 #error "unsupported platform: need mpd_size_t == mpd_uint_t"
200 #endif
201
202
203 /******************************************************************************/
204 /* Context */
205 /******************************************************************************/
206
207 enum {
208 MPD_ROUND_UP, /* round away from 0 */
209 MPD_ROUND_DOWN, /* round toward 0 (truncate) */
210 MPD_ROUND_CEILING, /* round toward +infinity */
211 MPD_ROUND_FLOOR, /* round toward -infinity */
212 MPD_ROUND_HALF_UP, /* 0.5 is rounded up */
213 MPD_ROUND_HALF_DOWN, /* 0.5 is rounded down */
214 MPD_ROUND_HALF_EVEN, /* 0.5 is rounded to even */
215 MPD_ROUND_05UP, /* round zero or five away from 0 */
216 MPD_ROUND_TRUNC, /* truncate, but set infinity */
217 MPD_ROUND_GUARD
218 };
219
220 enum { MPD_CLAMP_DEFAULT, MPD_CLAMP_IEEE_754, MPD_CLAMP_GUARD };
221
222 extern const char *mpd_round_string[MPD_ROUND_GUARD];
223 extern const char *mpd_clamp_string[MPD_CLAMP_GUARD];
224
225
226 typedef struct {
227 mpd_ssize_t prec; /* precision */
228 mpd_ssize_t emax; /* max positive exp */
229 mpd_ssize_t emin; /* min negative exp */
230 uint32_t traps; /* status events that should be trapped */
231 uint32_t status; /* status flags */
232 uint32_t newtrap; /* set by mpd_addstatus_raise() */
233 int round; /* rounding mode */
234 int clamp; /* clamp mode */
235 int allcr; /* all functions correctly rounded */
236 } mpd_context_t;
237
238
239 /* Status flags */
240 #define MPD_Clamped 0x00000001U
241 #define MPD_Conversion_syntax 0x00000002U
242 #define MPD_Division_by_zero 0x00000004U
243 #define MPD_Division_impossible 0x00000008U
244 #define MPD_Division_undefined 0x00000010U
245 #define MPD_Fpu_error 0x00000020U
246 #define MPD_Inexact 0x00000040U
247 #define MPD_Invalid_context 0x00000080U
248 #define MPD_Invalid_operation 0x00000100U
249 #define MPD_Malloc_error 0x00000200U
250 #define MPD_Not_implemented 0x00000400U
251 #define MPD_Overflow 0x00000800U
252 #define MPD_Rounded 0x00001000U
253 #define MPD_Subnormal 0x00002000U
254 #define MPD_Underflow 0x00004000U
255 #define MPD_Max_status (0x00008000U-1U)
256
257 /* Conditions that result in an IEEE 754 exception */
258 #define MPD_IEEE_Invalid_operation (MPD_Conversion_syntax | \
259 MPD_Division_impossible | \
260 MPD_Division_undefined | \
261 MPD_Fpu_error | \
262 MPD_Invalid_context | \
263 MPD_Invalid_operation | \
264 MPD_Malloc_error) \
265
266 /* Errors that require the result of an operation to be set to NaN */
267 #define MPD_Errors (MPD_IEEE_Invalid_operation | \
268 MPD_Division_by_zero)
269
270 /* Default traps */
271 #define MPD_Traps (MPD_IEEE_Invalid_operation | \
272 MPD_Division_by_zero | \
273 MPD_Overflow | \
274 MPD_Underflow)
275
276 /* Official name */
277 #define MPD_Insufficient_storage MPD_Malloc_error
278
279 /* IEEE 754 interchange format contexts */
280 #define MPD_IEEE_CONTEXT_MAX_BITS 512 /* 16*(log2(MPD_MAX_EMAX / 3)-3) */
281 #define MPD_DECIMAL32 32
282 #define MPD_DECIMAL64 64
283 #define MPD_DECIMAL128 128
284
285
286 #define MPD_MINALLOC_MIN 2
287 #define MPD_MINALLOC_MAX 64
288 extern mpd_ssize_t MPD_MINALLOC;
289 extern void (* mpd_traphandler)(mpd_context_t *);
290 void mpd_dflt_traphandler(mpd_context_t *);
291
292 void mpd_setminalloc(mpd_ssize_t n);
293 void mpd_init(mpd_context_t *ctx, mpd_ssize_t prec);
294
295 void mpd_maxcontext(mpd_context_t *ctx);
296 void mpd_maxcontext_plus(mpd_context_t *workctx, const mpd_context_t *ctx);
297 void mpd_defaultcontext(mpd_context_t *ctx);
298 void mpd_basiccontext(mpd_context_t *ctx);
299 int mpd_ieee_context(mpd_context_t *ctx, int bits);
300
301 mpd_ssize_t mpd_getprec(const mpd_context_t *ctx);
302 mpd_ssize_t mpd_getemax(const mpd_context_t *ctx);
303 mpd_ssize_t mpd_getemin(const mpd_context_t *ctx);
304 int mpd_getround(const mpd_context_t *ctx);
305 uint32_t mpd_gettraps(const mpd_context_t *ctx);
306 uint32_t mpd_getstatus(const mpd_context_t *ctx);
307 int mpd_getclamp(const mpd_context_t *ctx);
308 int mpd_getcr(const mpd_context_t *ctx);
309
310 int mpd_qsetprec(mpd_context_t *ctx, mpd_ssize_t prec);
311 int mpd_qsetemax(mpd_context_t *ctx, mpd_ssize_t emax);
312 int mpd_qsetemin(mpd_context_t *ctx, mpd_ssize_t emin);
313 int mpd_qsetround(mpd_context_t *ctx, int newround);
314 int mpd_qsettraps(mpd_context_t *ctx, uint32_t flags);
315 int mpd_qsetstatus(mpd_context_t *ctx, uint32_t flags);
316 int mpd_qsetclamp(mpd_context_t *ctx, int c);
317 int mpd_qsetcr(mpd_context_t *ctx, int c);
318 void mpd_addstatus_raise(mpd_context_t *ctx, uint32_t flags);
319
320
321 /******************************************************************************/
322 /* Decimal Arithmetic */
323 /******************************************************************************/
324
325 /* mpd_t flags */
326 #define MPD_POS ((uint8_t)0)
327 #define MPD_NEG ((uint8_t)1)
328 #define MPD_INF ((uint8_t)2)
329 #define MPD_NAN ((uint8_t)4)
330 #define MPD_SNAN ((uint8_t)8)
331 #define MPD_SPECIAL (MPD_INF|MPD_NAN|MPD_SNAN)
332 #define MPD_STATIC ((uint8_t)16)
333 #define MPD_STATIC_DATA ((uint8_t)32)
334 #define MPD_SHARED_DATA ((uint8_t)64)
335 #define MPD_CONST_DATA ((uint8_t)128)
336 #define MPD_DATAFLAGS (MPD_STATIC_DATA|MPD_SHARED_DATA|MPD_CONST_DATA)
337
338 /* mpd_t */
339 typedef struct {
340 uint8_t flags;
341 mpd_ssize_t exp;
342 mpd_ssize_t digits;
343 mpd_ssize_t len;
344 mpd_ssize_t alloc;
345 mpd_uint_t *data;
346 } mpd_t;
347
348
349 typedef unsigned char uchar;
350 extern mpd_t mpd_ln10;
351
352
353 /******************************************************************************/
354 /* Quiet, thread-safe functions */
355 /******************************************************************************/
356
357 /* format specification */
358 typedef struct {
359 mpd_ssize_t min_width; /* minimum field width */
360 mpd_ssize_t prec; /* fraction digits or significant digits */
361 char type; /* conversion specifier */
362 char align; /* alignment */
363 char sign; /* sign printing/alignment */
364 char fill[5]; /* fill character */
365 const char *dot; /* decimal point */
366 const char *sep; /* thousands separator */
367 const char *grouping; /* grouping of digits */
368 } mpd_spec_t;
369
370 /* output to a string */
371 char *mpd_to_sci(const mpd_t *dec, int fmt);
372 char *mpd_to_eng(const mpd_t *dec, int fmt);
373 mpd_ssize_t mpd_to_sci_size(char **res, const mpd_t *dec, int fmt);
374 mpd_ssize_t mpd_to_eng_size(char **res, const mpd_t *dec, int fmt);
375 int mpd_validate_lconv(mpd_spec_t *spec);
376 int mpd_parse_fmt_str(mpd_spec_t *spec, const char *fmt, int caps);
377 char * mpd_qformat_spec(const mpd_t *dec, const mpd_spec_t *spec, const mpd_cont ext_t *ctx, uint32_t *status);
378 char *mpd_qformat(const mpd_t *dec, const char *fmt, const mpd_context_t *ctx, u int32_t *status);
379
380 #define MPD_NUM_FLAGS 15
381 #define MPD_MAX_FLAG_STRING 208
382 #define MPD_MAX_FLAG_LIST (MPD_MAX_FLAG_STRING+18)
383 #define MPD_MAX_SIGNAL_LIST 121
384 int mpd_snprint_flags(char *dest, int nmemb, uint32_t flags);
385 int mpd_lsnprint_flags(char *dest, int nmemb, uint32_t flags, const char *flag_s tring[]);
386 int mpd_lsnprint_signals(char *dest, int nmemb, uint32_t flags, const char *sign al_string[]);
387
388 /* output to a file */
389 void mpd_fprint(FILE *file, const mpd_t *dec);
390 void mpd_print(const mpd_t *dec);
391
392 /* assignment from a string */
393 void mpd_qset_string(mpd_t *dec, const char *s, const mpd_context_t *ctx, uint32 _t *status);
394
395 /* set to NaN with error flags */
396 void mpd_seterror(mpd_t *result, uint32_t flags, uint32_t *status);
397 /* set a special with sign and type */
398 void mpd_setspecial(mpd_t *dec, uint8_t sign, uint8_t type);
399 /* set coefficient to zero or all nines */
400 void mpd_zerocoeff(mpd_t *result);
401 void mpd_qmaxcoeff(mpd_t *result, const mpd_context_t *ctx, uint32_t *status);
402
403 /* quietly assign a C integer type to an mpd_t */
404 void mpd_qset_ssize(mpd_t *result, mpd_ssize_t a, const mpd_context_t *ctx, uint 32_t *status);
405 void mpd_qset_i32(mpd_t *result, int32_t a, const mpd_context_t *ctx, uint32_t * status);
406 void mpd_qset_uint(mpd_t *result, mpd_uint_t a, const mpd_context_t *ctx, uint32 _t *status);
407 void mpd_qset_u32(mpd_t *result, uint32_t a, const mpd_context_t *ctx, uint32_t *status);
408 #ifndef LEGACY_COMPILER
409 void mpd_qset_i64(mpd_t *result, int64_t a, const mpd_context_t *ctx, uint32_t * status);
410 void mpd_qset_u64(mpd_t *result, uint64_t a, const mpd_context_t *ctx, uint32_t *status);
411 #endif
412
413 /* quietly assign a C integer type to an mpd_t with a static coefficient */
414 void mpd_qsset_ssize(mpd_t *result, mpd_ssize_t a, const mpd_context_t *ctx, uin t32_t *status);
415 void mpd_qsset_i32(mpd_t *result, int32_t a, const mpd_context_t *ctx, uint32_t *status);
416 void mpd_qsset_uint(mpd_t *result, mpd_uint_t a, const mpd_context_t *ctx, uint3 2_t *status);
417 void mpd_qsset_u32(mpd_t *result, uint32_t a, const mpd_context_t *ctx, uint32_t *status);
418
419 /* quietly get a C integer type from an mpd_t */
420 mpd_ssize_t mpd_qget_ssize(const mpd_t *dec, uint32_t *status);
421 mpd_uint_t mpd_qget_uint(const mpd_t *dec, uint32_t *status);
422 mpd_uint_t mpd_qabs_uint(const mpd_t *dec, uint32_t *status);
423
424
425 /* quiet functions */
426 int mpd_qcheck_nan(mpd_t *nanresult, const mpd_t *a, const mpd_context_t *ctx, u int32_t *status);
427 int mpd_qcheck_nans(mpd_t *nanresult, const mpd_t *a, const mpd_t *b, const mpd_ context_t *ctx, uint32_t *status);
428 void mpd_qfinalize(mpd_t *result, const mpd_context_t *ctx, uint32_t *status);
429
430 const char * mpd_class(const mpd_t *a, const mpd_context_t *ctx);
431
432 int mpd_qcopy(mpd_t *result, const mpd_t *a, uint32_t *status);
433 mpd_t *mpd_qncopy(const mpd_t *a);
434 int mpd_qcopy_abs(mpd_t *result, const mpd_t *a, uint32_t *status);
435 int mpd_qcopy_negate(mpd_t *result, const mpd_t *a, uint32_t *status);
436 int mpd_qcopy_sign(mpd_t *result, const mpd_t *a, const mpd_t *b, uint32_t *stat us);
437
438 void mpd_qand(mpd_t *result, const mpd_t *a, const mpd_t *b, const mpd_context_t *ctx, uint32_t *status);
439 void mpd_qinvert(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32 _t *status);
440 void mpd_qlogb(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_t *status);
441 void mpd_qor(mpd_t *result, const mpd_t *a, const mpd_t *b, const mpd_context_t *ctx, uint32_t *status);
442 void mpd_qscaleb(mpd_t *result, const mpd_t *a, const mpd_t *b, const mpd_contex t_t *ctx, uint32_t *status);
443 void mpd_qxor(mpd_t *result, const mpd_t *a, const mpd_t *b, const mpd_context_t *ctx, uint32_t *status);
444 int mpd_same_quantum(const mpd_t *a, const mpd_t *b);
445
446 void mpd_qrotate(mpd_t *result, const mpd_t *a, const mpd_t *b, const mpd_contex t_t *ctx, uint32_t *status);
447 int mpd_qshiftl(mpd_t *result, const mpd_t *a, mpd_ssize_t n, uint32_t *status);
448 mpd_uint_t mpd_qshiftr(mpd_t *result, const mpd_t *a, mpd_ssize_t n, uint32_t *s tatus);
449 mpd_uint_t mpd_qshiftr_inplace(mpd_t *result, mpd_ssize_t n);
450 void mpd_qshift(mpd_t *result, const mpd_t *a, const mpd_t *b, const mpd_context _t *ctx, uint32_t *status);
451 void mpd_qshiftn(mpd_t *result, const mpd_t *a, mpd_ssize_t n, const mpd_context _t *ctx, uint32_t *status);
452
453 int mpd_qcmp(const mpd_t *a, const mpd_t *b, uint32_t *status);
454 int mpd_qcompare(mpd_t *result, const mpd_t *a, const mpd_t *b, const mpd_contex t_t *ctx, uint32_t *status);
455 int mpd_qcompare_signal(mpd_t *result, const mpd_t *a, const mpd_t *b, const mpd _context_t *ctx, uint32_t *status);
456 int mpd_cmp_total(const mpd_t *a, const mpd_t *b);
457 int mpd_cmp_total_mag(const mpd_t *a, const mpd_t *b);
458 int mpd_compare_total(mpd_t *result, const mpd_t *a, const mpd_t *b);
459 int mpd_compare_total_mag(mpd_t *result, const mpd_t *a, const mpd_t *b);
460
461 void mpd_qround_to_intx(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_t *status);
462 void mpd_qround_to_int(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_t *status);
463 void mpd_qtrunc(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_ t *status);
464 void mpd_qfloor(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_ t *status);
465 void mpd_qceil(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_t *status);
466
467 void mpd_qabs(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_t *status);
468 void mpd_qmax(mpd_t *result, const mpd_t *a, const mpd_t *b, const mpd_context_t *ctx, uint32_t *status);
469 void mpd_qmax_mag(mpd_t *result, const mpd_t *a, const mpd_t *b, const mpd_conte xt_t *ctx, uint32_t *status);
470 void mpd_qmin(mpd_t *result, const mpd_t *a, const mpd_t *b, const mpd_context_t *ctx, uint32_t *status);
471 void mpd_qmin_mag(mpd_t *result, const mpd_t *a, const mpd_t *b, const mpd_conte xt_t *ctx, uint32_t *status);
472 void mpd_qminus(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_ t *status);
473 void mpd_qplus(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_t *status);
474 void mpd_qnext_minus(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, ui nt32_t *status);
475 void mpd_qnext_plus(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uin t32_t *status);
476 void mpd_qnext_toward(mpd_t *result, const mpd_t *a, const mpd_t *b, const mpd_c ontext_t *ctx, uint32_t *status);
477 void mpd_qquantize(mpd_t *result, const mpd_t *a, const mpd_t *b, const mpd_cont ext_t *ctx, uint32_t *status);
478 void mpd_qrescale(mpd_t *result, const mpd_t *a, mpd_ssize_t exp, const mpd_cont ext_t *ctx, uint32_t *status);
479 void mpd_qrescale_fmt(mpd_t *result, const mpd_t *a, mpd_ssize_t exp, const mpd_ context_t *ctx, uint32_t *status);
480 void mpd_qreduce(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32 _t *status);
481 void mpd_qadd(mpd_t *result, const mpd_t *a, const mpd_t *b, const mpd_context_t *ctx, uint32_t *status);
482 void mpd_qadd_ssize(mpd_t *result, const mpd_t *a, mpd_ssize_t b, const mpd_cont ext_t *ctx, uint32_t *status);
483 void mpd_qadd_i32(mpd_t *result, const mpd_t *a, int32_t b, const mpd_context_t *ctx, uint32_t *status);
484 void mpd_qadd_uint(mpd_t *result, const mpd_t *a, mpd_uint_t b, const mpd_contex t_t *ctx, uint32_t *status);
485 void mpd_qadd_u32(mpd_t *result, const mpd_t *a, uint32_t b, const mpd_context_t *ctx, uint32_t *status);
486 void mpd_qsub(mpd_t *result, const mpd_t *a, const mpd_t *b, const mpd_context_t *ctx, uint32_t *status);
487 void mpd_qsub_ssize(mpd_t *result, const mpd_t *a, mpd_ssize_t b, const mpd_cont ext_t *ctx, uint32_t *status);
488 void mpd_qsub_i32(mpd_t *result, const mpd_t *a, int32_t b, const mpd_context_t *ctx, uint32_t *status);
489 void mpd_qsub_uint(mpd_t *result, const mpd_t *a, mpd_uint_t b, const mpd_contex t_t *ctx, uint32_t *status);
490 void mpd_qsub_u32(mpd_t *result, const mpd_t *a, uint32_t b, const mpd_context_t *ctx, uint32_t *status);
491 void mpd_qmul(mpd_t *result, const mpd_t *a, const mpd_t *b, const mpd_context_t *ctx, uint32_t *status);
492 void mpd_qmul_ssize(mpd_t *result, const mpd_t *a, mpd_ssize_t b, const mpd_cont ext_t *ctx, uint32_t *status);
493 void mpd_qmul_i32(mpd_t *result, const mpd_t *a, int32_t b, const mpd_context_t *ctx, uint32_t *status);
494 void mpd_qmul_uint(mpd_t *result, const mpd_t *a, mpd_uint_t b, const mpd_contex t_t *ctx, uint32_t *status);
495 void mpd_qmul_u32(mpd_t *result, const mpd_t *a, uint32_t b, const mpd_context_t *ctx, uint32_t *status);
496 void mpd_qfma(mpd_t *result, const mpd_t *a, const mpd_t *b, const mpd_t *c, con st mpd_context_t *ctx, uint32_t *status);
497 void mpd_qdiv(mpd_t *q, const mpd_t *a, const mpd_t *b, const mpd_context_t *ctx , uint32_t *status);
498 void mpd_qdiv_ssize(mpd_t *result, const mpd_t *a, mpd_ssize_t b, const mpd_cont ext_t *ctx, uint32_t *status);
499 void mpd_qdiv_i32(mpd_t *result, const mpd_t *a, int32_t b, const mpd_context_t *ctx, uint32_t *status);
500 void mpd_qdiv_uint(mpd_t *result, const mpd_t *a, mpd_uint_t b, const mpd_contex t_t *ctx, uint32_t *status);
501 void mpd_qdiv_u32(mpd_t *result, const mpd_t *a, uint32_t b, const mpd_context_t *ctx, uint32_t *status);
502 void mpd_qdivint(mpd_t *q, const mpd_t *a, const mpd_t *b, const mpd_context_t * ctx, uint32_t *status);
503 void mpd_qrem(mpd_t *r, const mpd_t *a, const mpd_t *b, const mpd_context_t *ctx , uint32_t *status);
504 void mpd_qrem_near(mpd_t *r, const mpd_t *a, const mpd_t *b, const mpd_context_t *ctx, uint32_t *status);
505 void mpd_qdivmod(mpd_t *q, mpd_t *r, const mpd_t *a, const mpd_t *b, const mpd_c ontext_t *ctx, uint32_t *status);
506 void mpd_qpow(mpd_t *result, const mpd_t *base, const mpd_t *exp, const mpd_cont ext_t *ctx, uint32_t *status);
507 void mpd_qpowmod(mpd_t *result, const mpd_t *base, const mpd_t *exp, const mpd_t *mod, const mpd_context_t *ctx, uint32_t *status);
508 void mpd_qexp(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_t *status);
509 void mpd_update_ln10(mpd_ssize_t prec, uint32_t *status);
510 void mpd_qln(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_t * status);
511 void mpd_qlog10(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_ t *status);
512 void mpd_qsqrt(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_t *status);
513 void mpd_qinvroot(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint3 2_t *status);
514
515
516 size_t mpd_sizeinbase(mpd_t *a, uint32_t base);
517 void mpd_qimport_u16(mpd_t *result, const uint16_t *srcdata, size_t srclen,
518 uint8_t srcsign, uint32_t srcbase,
519 const mpd_context_t *ctx, uint32_t *status);
520 void mpd_qimport_u32(mpd_t *result, const uint32_t *srcdata, size_t srclen,
521 uint8_t srcsign, uint32_t srcbase,
522 const mpd_context_t *ctx, uint32_t *status);
523 size_t mpd_qexport_u16(uint16_t *rdata, size_t rlen, uint32_t base,
524 const mpd_t *src, uint32_t *status);
525 size_t mpd_qexport_u32(uint32_t *rdata, size_t rlen, uint32_t base,
526 const mpd_t *src, uint32_t *status);
527
528
529 /******************************************************************************/
530 /* Signalling functions */
531 /******************************************************************************/
532
533 char * mpd_format(const mpd_t *dec, const char *fmt, mpd_context_t *ctx);
534 void mpd_import_u16(mpd_t *result, const uint16_t *srcdata, size_t srclen, uint8 _t srcsign, uint32_t base, mpd_context_t *ctx);
535 void mpd_import_u32(mpd_t *result, const uint32_t *srcdata, size_t srclen, uint8 _t srcsign, uint32_t base, mpd_context_t *ctx);
536 size_t mpd_export_u16(uint16_t *rdata, size_t rlen, uint32_t base, const mpd_t * src, mpd_context_t *ctx);
537 size_t mpd_export_u32(uint32_t *rdata, size_t rlen, uint32_t base, const mpd_t * src, mpd_context_t *ctx);
538 void mpd_finalize(mpd_t *result, mpd_context_t *ctx);
539 int mpd_check_nan(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
540 int mpd_check_nans(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx);
541 void mpd_set_string(mpd_t *result, const char *s, mpd_context_t *ctx);
542 void mpd_maxcoeff(mpd_t *result, mpd_context_t *ctx);
543 void mpd_sset_ssize(mpd_t *result, mpd_ssize_t a, mpd_context_t *ctx);
544 void mpd_sset_i32(mpd_t *result, int32_t a, mpd_context_t *ctx);
545 void mpd_sset_uint(mpd_t *result, mpd_uint_t a, mpd_context_t *ctx);
546 void mpd_sset_u32(mpd_t *result, uint32_t a, mpd_context_t *ctx);
547 void mpd_set_ssize(mpd_t *result, mpd_ssize_t a, mpd_context_t *ctx);
548 void mpd_set_i32(mpd_t *result, int32_t a, mpd_context_t *ctx);
549 void mpd_set_uint(mpd_t *result, mpd_uint_t a, mpd_context_t *ctx);
550 void mpd_set_u32(mpd_t *result, uint32_t a, mpd_context_t *ctx);
551 #ifndef LEGACY_COMPILER
552 void mpd_set_i64(mpd_t *result, int64_t a, mpd_context_t *ctx);
553 void mpd_set_u64(mpd_t *result, uint64_t a, mpd_context_t *ctx);
554 #endif
555 mpd_ssize_t mpd_get_ssize(const mpd_t *a, mpd_context_t *ctx);
556 mpd_uint_t mpd_get_uint(const mpd_t *a, mpd_context_t *ctx);
557 mpd_uint_t mpd_abs_uint(const mpd_t *a, mpd_context_t *ctx);
558 void mpd_and(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx);
559 void mpd_copy(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
560 void mpd_canonical(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
561 void mpd_copy_abs(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
562 void mpd_copy_negate(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
563 void mpd_copy_sign(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx);
564 void mpd_invert(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
565 void mpd_logb(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
566 void mpd_or(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx);
567 void mpd_rotate(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ct x);
568 void mpd_scaleb(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ct x);
569 void mpd_shiftl(mpd_t *result, const mpd_t *a, mpd_ssize_t n, mpd_context_t *ctx );
570 mpd_uint_t mpd_shiftr(mpd_t *result, const mpd_t *a, mpd_ssize_t n, mpd_context_ t *ctx);
571 void mpd_shiftn(mpd_t *result, const mpd_t *a, mpd_ssize_t n, mpd_context_t *ctx );
572 void mpd_shift(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx );
573 void mpd_xor(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx);
574 void mpd_abs(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
575 int mpd_cmp(const mpd_t *a, const mpd_t *b, mpd_context_t *ctx);
576 int mpd_compare(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ct x);
577 int mpd_compare_signal(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_contex t_t *ctx);
578 void mpd_add(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx);
579 void mpd_add_ssize(mpd_t *result, const mpd_t *a, mpd_ssize_t b, mpd_context_t * ctx);
580 void mpd_add_i32(mpd_t *result, const mpd_t *a, int32_t b, mpd_context_t *ctx);
581 void mpd_add_uint(mpd_t *result, const mpd_t *a, mpd_uint_t b, mpd_context_t *ct x);
582 void mpd_add_u32(mpd_t *result, const mpd_t *a, uint32_t b, mpd_context_t *ctx);
583 void mpd_sub(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx);
584 void mpd_sub_ssize(mpd_t *result, const mpd_t *a, mpd_ssize_t b, mpd_context_t * ctx);
585 void mpd_sub_i32(mpd_t *result, const mpd_t *a, int32_t b, mpd_context_t *ctx);
586 void mpd_sub_uint(mpd_t *result, const mpd_t *a, mpd_uint_t b, mpd_context_t *ct x);
587 void mpd_sub_u32(mpd_t *result, const mpd_t *a, uint32_t b, mpd_context_t *ctx);
588 void mpd_div(mpd_t *q, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx);
589 void mpd_div_ssize(mpd_t *result, const mpd_t *a, mpd_ssize_t b, mpd_context_t * ctx);
590 void mpd_div_i32(mpd_t *result, const mpd_t *a, int32_t b, mpd_context_t *ctx);
591 void mpd_div_uint(mpd_t *result, const mpd_t *a, mpd_uint_t b, mpd_context_t *ct x);
592 void mpd_div_u32(mpd_t *result, const mpd_t *a, uint32_t b, mpd_context_t *ctx);
593 void mpd_divmod(mpd_t *q, mpd_t *r, const mpd_t *a, const mpd_t *b, mpd_context_ t *ctx);
594 void mpd_divint(mpd_t *q, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx);
595 void mpd_exp(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
596 void mpd_fma(mpd_t *result, const mpd_t *a, const mpd_t *b, const mpd_t *c, mpd_ context_t *ctx);
597 void mpd_ln(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
598 void mpd_log10(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
599 void mpd_max(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx);
600 void mpd_max_mag(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *c tx);
601 void mpd_min(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx);
602 void mpd_min_mag(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *c tx);
603 void mpd_minus(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
604 void mpd_mul(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx);
605 void mpd_mul_ssize(mpd_t *result, const mpd_t *a, mpd_ssize_t b, mpd_context_t * ctx);
606 void mpd_mul_i32(mpd_t *result, const mpd_t *a, int32_t b, mpd_context_t *ctx);
607 void mpd_mul_uint(mpd_t *result, const mpd_t *a, mpd_uint_t b, mpd_context_t *ct x);
608 void mpd_mul_u32(mpd_t *result, const mpd_t *a, uint32_t b, mpd_context_t *ctx);
609 void mpd_next_minus(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
610 void mpd_next_plus(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
611 void mpd_next_toward(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_ t *ctx);
612 void mpd_plus(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
613 void mpd_pow(mpd_t *result, const mpd_t *base, const mpd_t *exp, mpd_context_t * ctx);
614 void mpd_powmod(mpd_t *result, const mpd_t *base, const mpd_t *exp, const mpd_t *mod, mpd_context_t *ctx);
615 void mpd_quantize(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t * ctx);
616 void mpd_rescale(mpd_t *result, const mpd_t *a, mpd_ssize_t exp, mpd_context_t * ctx);
617 void mpd_reduce(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
618 void mpd_rem(mpd_t *r, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx);
619 void mpd_rem_near(mpd_t *r, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx);
620 void mpd_round_to_intx(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
621 void mpd_round_to_int(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
622 void mpd_trunc(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
623 void mpd_floor(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
624 void mpd_ceil(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
625 void mpd_sqrt(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
626 void mpd_invroot(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
627
628
629 /******************************************************************************/
630 /* Configuration specific */
631 /******************************************************************************/
632
633 #ifdef CONFIG_64
634 void mpd_qsset_i64(mpd_t *result, int64_t a, const mpd_context_t *ctx, uint32_t *status);
635 void mpd_qsset_u64(mpd_t *result, uint64_t a, const mpd_context_t *ctx, uint32_t *status);
636 int64_t mpd_qget_i64(const mpd_t *dec, uint32_t *status);
637 uint64_t mpd_qget_u64(const mpd_t *dec, uint32_t *status);
638
639 void mpd_qadd_i64(mpd_t *result, const mpd_t *a, int64_t b, const mpd_context_t *ctx, uint32_t *status);
640 void mpd_qadd_u64(mpd_t *result, const mpd_t *a, uint64_t b, const mpd_context_t *ctx, uint32_t *status);
641 void mpd_qsub_i64(mpd_t *result, const mpd_t *a, int64_t b, const mpd_context_t *ctx, uint32_t *status);
642 void mpd_qsub_u64(mpd_t *result, const mpd_t *a, uint64_t b, const mpd_context_t *ctx, uint32_t *status);
643 void mpd_qmul_i64(mpd_t *result, const mpd_t *a, int64_t b, const mpd_context_t *ctx, uint32_t *status);
644 void mpd_qmul_u64(mpd_t *result, const mpd_t *a, uint64_t b, const mpd_context_t *ctx, uint32_t *status);
645 void mpd_qdiv_i64(mpd_t *result, const mpd_t *a, int64_t b, const mpd_context_t *ctx, uint32_t *status);
646 void mpd_qdiv_u64(mpd_t *result, const mpd_t *a, uint64_t b, const mpd_context_t *ctx, uint32_t *status);
647
648 void mpd_sset_i64(mpd_t *result, int64_t a, mpd_context_t *ctx);
649 void mpd_sset_u64(mpd_t *result, uint64_t a, mpd_context_t *ctx);
650 int64_t mpd_get_i64(const mpd_t *a, mpd_context_t *ctx);
651 uint64_t mpd_get_u64(const mpd_t *a, mpd_context_t *ctx);
652
653 void mpd_add_i64(mpd_t *result, const mpd_t *a, int64_t b, mpd_context_t *ctx);
654 void mpd_add_u64(mpd_t *result, const mpd_t *a, uint64_t b, mpd_context_t *ctx);
655 void mpd_sub_i64(mpd_t *result, const mpd_t *a, int64_t b, mpd_context_t *ctx);
656 void mpd_sub_u64(mpd_t *result, const mpd_t *a, uint64_t b, mpd_context_t *ctx);
657 void mpd_div_i64(mpd_t *result, const mpd_t *a, int64_t b, mpd_context_t *ctx);
658 void mpd_div_u64(mpd_t *result, const mpd_t *a, uint64_t b, mpd_context_t *ctx);
659 void mpd_mul_i64(mpd_t *result, const mpd_t *a, int64_t b, mpd_context_t *ctx);
660 void mpd_mul_u64(mpd_t *result, const mpd_t *a, uint64_t b, mpd_context_t *ctx);
661 #else
662 int32_t mpd_qget_i32(const mpd_t *dec, uint32_t *status);
663 uint32_t mpd_qget_u32(const mpd_t *dec, uint32_t *status);
664 int32_t mpd_get_i32(const mpd_t *a, mpd_context_t *ctx);
665 uint32_t mpd_get_u32(const mpd_t *a, mpd_context_t *ctx);
666 #endif
667
668
669 /******************************************************************************/
670 /* Get attributes of a decimal */
671 /******************************************************************************/
672
673 EXTINLINE mpd_ssize_t mpd_adjexp(const mpd_t *dec);
674 EXTINLINE mpd_ssize_t mpd_etiny(const mpd_context_t *ctx);
675 EXTINLINE mpd_ssize_t mpd_etop(const mpd_context_t *ctx);
676 EXTINLINE mpd_uint_t mpd_msword(const mpd_t *dec);
677 EXTINLINE int mpd_word_digits(mpd_uint_t word);
678 /* most significant digit of a word */
679 EXTINLINE mpd_uint_t mpd_msd(mpd_uint_t word);
680 /* least significant digit of a word */
681 EXTINLINE mpd_uint_t mpd_lsd(mpd_uint_t word);
682 /* coefficient size needed to store 'digits' */
683 EXTINLINE mpd_ssize_t mpd_digits_to_size(mpd_ssize_t digits);
684 /* number of digits in the exponent, undefined for MPD_SSIZE_MIN */
685 EXTINLINE int mpd_exp_digits(mpd_ssize_t exp);
686 EXTINLINE int mpd_iscanonical(const mpd_t *dec UNUSED);
687 EXTINLINE int mpd_isfinite(const mpd_t *dec);
688 EXTINLINE int mpd_isinfinite(const mpd_t *dec);
689 EXTINLINE int mpd_isinteger(const mpd_t *dec);
690 EXTINLINE int mpd_isnan(const mpd_t *dec);
691 EXTINLINE int mpd_isnegative(const mpd_t *dec);
692 EXTINLINE int mpd_ispositive(const mpd_t *dec);
693 EXTINLINE int mpd_isqnan(const mpd_t *dec);
694 EXTINLINE int mpd_issigned(const mpd_t *dec);
695 EXTINLINE int mpd_issnan(const mpd_t *dec);
696 EXTINLINE int mpd_isspecial(const mpd_t *dec);
697 EXTINLINE int mpd_iszero(const mpd_t *dec);
698 /* undefined for special numbers */
699 EXTINLINE int mpd_iszerocoeff(const mpd_t *dec);
700 EXTINLINE int mpd_isnormal(const mpd_t *dec, const mpd_context_t *ctx);
701 EXTINLINE int mpd_issubnormal(const mpd_t *dec, const mpd_context_t *ctx);
702 /* odd word */
703 EXTINLINE int mpd_isoddword(mpd_uint_t word);
704 /* odd coefficient */
705 EXTINLINE int mpd_isoddcoeff(const mpd_t *dec);
706 /* odd decimal, only defined for integers */
707 int mpd_isodd(const mpd_t *dec);
708 /* even decimal, only defined for integers */
709 int mpd_iseven(const mpd_t *dec);
710 /* 0 if dec is positive, 1 if dec is negative */
711 EXTINLINE uint8_t mpd_sign(const mpd_t *dec);
712 /* 1 if dec is positive, -1 if dec is negative */
713 EXTINLINE int mpd_arith_sign(const mpd_t *dec);
714 EXTINLINE long mpd_radix(void);
715 EXTINLINE int mpd_isdynamic(mpd_t *dec);
716 EXTINLINE int mpd_isstatic(mpd_t *dec);
717 EXTINLINE int mpd_isdynamic_data(mpd_t *dec);
718 EXTINLINE int mpd_isstatic_data(mpd_t *dec);
719 EXTINLINE int mpd_isshared_data(mpd_t *dec);
720 EXTINLINE int mpd_isconst_data(mpd_t *dec);
721 EXTINLINE mpd_ssize_t mpd_trail_zeros(const mpd_t *dec);
722
723
724 /******************************************************************************/
725 /* Set attributes of a decimal */
726 /******************************************************************************/
727
728 /* set number of decimal digits in the coefficient */
729 EXTINLINE void mpd_setdigits(mpd_t *result);
730 EXTINLINE void mpd_set_sign(mpd_t *result, uint8_t sign);
731 /* copy sign from another decimal */
732 EXTINLINE void mpd_signcpy(mpd_t *result, mpd_t *a);
733 EXTINLINE void mpd_set_infinity(mpd_t *result);
734 EXTINLINE void mpd_set_qnan(mpd_t *result);
735 EXTINLINE void mpd_set_snan(mpd_t *result);
736 EXTINLINE void mpd_set_negative(mpd_t *result);
737 EXTINLINE void mpd_set_positive(mpd_t *result);
738 EXTINLINE void mpd_set_dynamic(mpd_t *result);
739 EXTINLINE void mpd_set_static(mpd_t *result);
740 EXTINLINE void mpd_set_dynamic_data(mpd_t *result);
741 EXTINLINE void mpd_set_static_data(mpd_t *result);
742 EXTINLINE void mpd_set_shared_data(mpd_t *result);
743 EXTINLINE void mpd_set_const_data(mpd_t *result);
744 EXTINLINE void mpd_clear_flags(mpd_t *result);
745 EXTINLINE void mpd_set_flags(mpd_t *result, uint8_t flags);
746 EXTINLINE void mpd_copy_flags(mpd_t *result, const mpd_t *a);
747
748
749 /******************************************************************************/
750 /* Error Macros */
751 /******************************************************************************/
752
753 #define mpd_err_fatal(...) \
754 do {fprintf(stderr, "%s:%d: error: ", __FILE__, __LINE__); \
755 fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); \
756 exit(1); \
757 } while (0)
758 #define mpd_err_warn(...) \
759 do {fprintf(stderr, "%s:%d: warning: ", __FILE__, __LINE__); \
760 fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); \
761 } while (0)
762
763
764 /******************************************************************************/
765 /* Memory handling */
766 /******************************************************************************/
767
768 extern void *(* mpd_mallocfunc)(size_t size);
769 extern void *(* mpd_callocfunc)(size_t nmemb, size_t size);
770 extern void *(* mpd_reallocfunc)(void *ptr, size_t size);
771 extern void (* mpd_free)(void *ptr);
772
773 void *mpd_callocfunc_em(size_t nmemb, size_t size);
774
775 void *mpd_alloc(mpd_size_t nmemb, mpd_size_t size);
776 void *mpd_calloc(mpd_size_t nmemb, mpd_size_t size);
777 void *mpd_realloc(void *ptr, mpd_size_t nmemb, mpd_size_t size, uint8_t *err);
778 void *mpd_sh_alloc(mpd_size_t struct_size, mpd_size_t nmemb, mpd_size_t size);
779
780 mpd_t *mpd_qnew(void);
781 mpd_t *mpd_new(mpd_context_t *ctx);
782 mpd_t *mpd_qnew_size(mpd_ssize_t size);
783 void mpd_del(mpd_t *dec);
784
785 void mpd_uint_zero(mpd_uint_t *dest, mpd_size_t len);
786 int mpd_qresize(mpd_t *result, mpd_ssize_t size, uint32_t *status);
787 int mpd_qresize_zero(mpd_t *result, mpd_ssize_t size, uint32_t *status);
788 void mpd_minalloc(mpd_t *result);
789
790 int mpd_resize(mpd_t *result, mpd_ssize_t size, mpd_context_t *ctx);
791 int mpd_resize_zero(mpd_t *result, mpd_ssize_t size, mpd_context_t *ctx);
792
793
794 #ifdef __cplusplus
795 } /* END extern "C" */
796 #endif
797
798
799 #endif /* MPDECIMAL_H */
800
801
802
OLDNEW
« no previous file with comments | « Modules/_decimal/libmpdec/mpdecimal.c ('k') | Modules/_decimal/libmpdec/numbertheory.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+