-
Notifications
You must be signed in to change notification settings - Fork 25
/
mpf_init_multi.c
50 lines (46 loc) · 1.56 KB
/
mpf_init_multi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* LibTomFloat, multiple-precision floating-point library
*
* LibTomFloat is a library that provides multiple-precision
* floating-point artihmetic as well as trigonometric functionality.
*
* This library requires the public domain LibTomMath to be installed.
*
* This library is free for all purposes without any express
* gurantee it works
*
* Tom St Denis, [email protected], http://float.libtomcrypt.org
*/
#include <tomfloat.h>
#include <stdarg.h>
int mpf_init_multi(long radix, mp_float *a, ...)
{
mp_err res = MP_OKAY; /* Assume ok until proven otherwise */
int n = 0; /* Number of ok inits */
mp_float* cur_arg = a;
va_list args;
va_start(args, a); /* init args to next argument from caller */
while (cur_arg != NULL) {
if (mpf_init(cur_arg, radix) != MP_OKAY) {
/* Oops - error! Back-track and mp_clear what we already
succeeded in init-ing, then return error.
*/
va_list clean_args;
/* end the current list */
va_end(args);
/* now start cleaning up */
cur_arg = a;
va_start(clean_args, a);
while (n--) {
mpf_clear(cur_arg);
cur_arg = va_arg(clean_args, mp_float*);
}
va_end(clean_args);
res = MP_MEM;
break;
}
n++;
cur_arg = va_arg(args, mp_float*);
}
va_end(args);
return res; /* Assumed ok, if error flagged above. */
}