-
Notifications
You must be signed in to change notification settings - Fork 25
/
mpf_div.c
37 lines (31 loc) · 914 Bytes
/
mpf_div.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
/* 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>
int mpf_div(mp_float *a, mp_float *b, mp_float *c)
{
mp_float tmp;
int err;
/* ensure b is not zero */
if (mp_iszero(&(b->mantissa)) == MP_YES) {
return MP_VAL;
}
/* find 1/b */
if ((err = mpf_init(&tmp, c->radix)) != MP_OKAY) {
return err;
}
if ((err = mpf_inv(b, &tmp)) != MP_OKAY) { goto __ERR; }
/* now multiply */
err = mpf_mul(&tmp, a, c);
__ERR: mpf_clear(&tmp);
return err;
}