1
/* Reference floating point routines.
3
Copyright 1996, 2001 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 the GNU Lesser General Public License as published by
9
the Free Software Foundation; either version 2.1 of the License, or (at your
10
option) any later version.
12
The GNU MP Library is distributed in the hope that it will be useful, but
13
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15
License for more details.
17
You should have received a copy of the GNU Lesser General Public License
18
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
19
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20
MA 02111-1307, USA. */
28
refmpf_add (mpf_ptr w, mpf_srcptr u, mpf_srcptr v)
30
mp_size_t hi, lo, size;
42
wt = (mp_ptr) TMP_ALLOC ((size+1) * BYTES_PER_MP_LIMB);
43
MPN_COPY (wt, PTR (v), size);
51
wt = (mp_ptr) TMP_ALLOC ((size+1) * BYTES_PER_MP_LIMB);
52
MPN_COPY (wt, PTR (u), size);
57
if ((SIZ (u) ^ SIZ (v)) < 0)
63
refmpf_sub (w, u, tmp);
68
/* Compute the significance of the hi and lo end of the result. */
69
hi = MAX (EXP (u), EXP (v));
70
lo = MIN (EXP (u) - ABSIZ (u), EXP (v) - ABSIZ (v));
72
ut = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB);
73
vt = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB);
74
wt = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB);
78
off = size + (EXP (u) - hi) - ABSIZ (u);
79
MPN_COPY (ut + off, PTR (u), ABSIZ (u));
80
off = size + (EXP (v) - hi) - ABSIZ (v);
81
MPN_COPY (vt + off, PTR (v), ABSIZ (v));
84
cy = mpn_add_n (wt, ut, vt, size);
92
wt += size - PREC (w);
95
MPN_COPY (PTR (w), wt, size);
96
SIZ (w) = neg == 0 ? size : -size;
102
refmpf_sub (mpf_ptr w, mpf_srcptr u, mpf_srcptr v)
104
mp_size_t hi, lo, size;
115
wt = (mp_ptr) TMP_ALLOC ((size+1) * BYTES_PER_MP_LIMB);
116
MPN_COPY (wt, PTR (v), size);
124
wt = (mp_ptr) TMP_ALLOC ((size+1) * BYTES_PER_MP_LIMB);
125
MPN_COPY (wt, PTR (u), size);
130
if ((SIZ (u) ^ SIZ (v)) < 0)
133
SIZ (tmp) = -SIZ (v);
136
refmpf_add (w, u, tmp);
143
/* Compute the significance of the hi and lo end of the result. */
144
hi = MAX (EXP (u), EXP (v));
145
lo = MIN (EXP (u) - ABSIZ (u), EXP (v) - ABSIZ (v));
147
ut = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB);
148
vt = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB);
149
wt = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB);
153
off = size + (EXP (u) - hi) - ABSIZ (u);
154
MPN_COPY (ut + off, PTR (u), ABSIZ (u));
155
off = size + (EXP (v) - hi) - ABSIZ (v);
156
MPN_COPY (vt + off, PTR (v), ABSIZ (v));
159
if (mpn_cmp (ut, vt, size) >= 0)
160
mpn_sub_n (wt, ut, vt, size);
163
mpn_sub_n (wt, vt, ut, size);
167
while (size != 0 && wt[size - 1] == 0)
176
wt += size - PREC (w);
179
MPN_COPY (PTR (w), wt, size);
180
SIZ (w) = neg == 0 ? size : -size;