after multiple objections of libtom users [1], we decided to change licensing
[libtomfloat.git] / mpf_div.c
blobdecef8b3b7fa363421c6feb46f2d86a653f4f757
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>
15 int mpf_div(mp_float *a, mp_float *b, mp_float *c)
17 mp_float tmp;
18 int err;
20 /* ensure b is not zero */
21 if (mp_iszero(&(b->mantissa)) == MP_YES) {
22 return MP_VAL;
25 /* find 1/b */
26 if ((err = mpf_init(&tmp, c->radix)) != MP_OKAY) {
27 return err;
29 if ((err = mpf_inv(b, &tmp)) != MP_OKAY) { goto __ERR; }
31 /* now multiply */
32 err = mpf_mul(&tmp, a, c);
34 __ERR: mpf_clear(&tmp);
35 return err;