1 /*
2 Copyright (C) 2014 Fredrik Johansson
3
4 This file is part of Arb.
5
6 Arb is free software: you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License (LGPL) as published
8 by the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version. See <http://www.gnu.org/licenses/>.
10 */
11
12 #include "mag.h"
13
14 void
mag_mul(mag_t z,const mag_t x,const mag_t y)15 mag_mul(mag_t z, const mag_t x, const mag_t y)
16 {
17 if (mag_is_special(x) || mag_is_special(y))
18 {
19 if (mag_is_inf(x) || mag_is_inf(y))
20 mag_inf(z);
21 else
22 mag_zero(z);
23 }
24 else
25 {
26 slong fix;
27
28 MAG_MAN(z) = MAG_FIXMUL(MAG_MAN(x), MAG_MAN(y)) + LIMB_ONE;
29 fix = !(MAG_MAN(z) >> (MAG_BITS - 1));
30 MAG_MAN(z) <<= fix;
31 _fmpz_add2_fast(MAG_EXPREF(z), MAG_EXPREF(x), MAG_EXPREF(y), -fix);
32 }
33 }
34
35 void
mag_mul_lower(mag_t z,const mag_t x,const mag_t y)36 mag_mul_lower(mag_t z, const mag_t x, const mag_t y)
37 {
38 if (mag_is_special(x) || mag_is_special(y))
39 {
40 if (mag_is_zero(x) || mag_is_zero(y))
41 mag_zero(z);
42 else
43 mag_inf(z);
44 }
45 else
46 {
47 slong fix;
48
49 MAG_MAN(z) = MAG_FIXMUL(MAG_MAN(x), MAG_MAN(y));
50 fix = !(MAG_MAN(z) >> (MAG_BITS - 1));
51 MAG_MAN(z) <<= fix;
52 _fmpz_add2_fast(MAG_EXPREF(z), MAG_EXPREF(x), MAG_EXPREF(y), -fix);
53 }
54 }
55
56