after multiple objections of libtom users [1], we decided to change licensing
[libtomfloat.git] / mpf_init_multi.c
blob71762c4ac3af0e5da705e7c4e83e49f915772d9b
1 /* LibTomFloat, multiple-precision floating-point library
3 * LibTomFloat is a library that provides multiple-precision
4 * floating-point artihmetic as well as trigonometric functionality.
6 * This library requires the public domain LibTomMath to be installed.
7 *
8 * This library is free for all purposes without any express
9 * gurantee it works
11 * Tom St Denis, tomstdenis@iahu.ca, http://float.libtomcrypt.org
13 #include <tomfloat.h>
14 #include <stdarg.h>
16 int mpf_init_multi(long radix, mp_float *a, ...)
18 mp_err res = MP_OKAY; /* Assume ok until proven otherwise */
19 int n = 0; /* Number of ok inits */
20 mp_float* cur_arg = a;
21 va_list args;
23 va_start(args, a); /* init args to next argument from caller */
24 while (cur_arg != NULL) {
25 if (mpf_init(cur_arg, radix) != MP_OKAY) {
26 /* Oops - error! Back-track and mp_clear what we already
27 succeeded in init-ing, then return error.
29 va_list clean_args;
31 /* end the current list */
32 va_end(args);
34 /* now start cleaning up */
35 cur_arg = a;
36 va_start(clean_args, a);
37 while (n--) {
38 mpf_clear(cur_arg);
39 cur_arg = va_arg(clean_args, mp_float*);
41 va_end(clean_args);
42 res = MP_MEM;
43 break;
45 n++;
46 cur_arg = va_arg(args, mp_float*);
48 va_end(args);
49 return res; /* Assumed ok, if error flagged above. */