beta-0.89.2
[luatex.git] / source / libs / gmp / gmp-src / mpf / mul.c
blob5bde28c4b2f6497a5c44a712905fa7e630894266
1 /* mpf_mul -- Multiply two floats.
3 Copyright 1993, 1994, 1996, 2001, 2005 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of either:
10 * the GNU Lesser General Public License as published by the Free
11 Software Foundation; either version 3 of the License, or (at your
12 option) any later version.
16 * the GNU General Public License as published by the Free Software
17 Foundation; either version 2 of the License, or (at your option) any
18 later version.
20 or both in parallel, as here.
22 The GNU MP Library is distributed in the hope that it will be useful, but
23 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 for more details.
27 You should have received copies of the GNU General Public License and the
28 GNU Lesser General Public License along with the GNU MP Library. If not,
29 see https://www.gnu.org/licenses/. */
31 #include "gmp.h"
32 #include "gmp-impl.h"
34 void
35 mpf_mul (mpf_ptr r, mpf_srcptr u, mpf_srcptr v)
37 mp_srcptr up, vp;
38 mp_size_t usize, vsize;
39 mp_size_t sign_product;
40 mp_size_t prec = r->_mp_prec;
42 usize = u->_mp_size;
43 vsize = v->_mp_size;
44 sign_product = usize ^ vsize;
46 usize = ABS (usize);
47 vsize = ABS (vsize);
49 up = u->_mp_d;
50 vp = v->_mp_d;
51 if (usize > prec)
53 up += usize - prec;
54 usize = prec;
56 if (vsize > prec)
58 vp += vsize - prec;
59 vsize = prec;
62 if (usize == 0 || vsize == 0)
64 r->_mp_size = 0;
65 r->_mp_exp = 0; /* ??? */
67 else
69 mp_size_t rsize;
70 mp_limb_t cy_limb;
71 mp_ptr rp, tp;
72 mp_size_t adj;
73 TMP_DECL;
75 TMP_MARK;
76 rsize = usize + vsize;
77 tp = TMP_ALLOC_LIMBS (rsize);
78 cy_limb = (usize >= vsize
79 ? mpn_mul (tp, up, usize, vp, vsize)
80 : mpn_mul (tp, vp, vsize, up, usize));
82 adj = cy_limb == 0;
83 rsize -= adj;
84 prec++;
85 if (rsize > prec)
87 tp += rsize - prec;
88 rsize = prec;
90 rp = r->_mp_d;
91 MPN_COPY (rp, tp, rsize);
92 r->_mp_exp = u->_mp_exp + v->_mp_exp - adj;
93 r->_mp_size = sign_product >= 0 ? rsize : -rsize;
95 TMP_FREE;