version 1.1.1.1, 2000/01/10 15:35:22 |
version 1.1.1.3, 2003/08/25 16:06:35 |
|
|
/* mpf_sub -- Subtract two floats. |
/* mpf_sub -- Subtract two floats. |
|
|
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc. |
Copyright 1993, 1994, 1995, 1996, 1999, 2000, 2001, 2002 Free Software |
|
Foundation, Inc. |
|
|
This file is part of the GNU MP Library. |
This file is part of the GNU MP Library. |
|
|
The GNU MP Library is free software; you can redistribute it and/or modify |
The GNU MP Library is free software; you can redistribute it and/or modify |
it under the terms of the GNU Library General Public License as published by |
it under the terms of the GNU Lesser General Public License as published by |
the Free Software Foundation; either version 2 of the License, or (at your |
the Free Software Foundation; either version 2.1 of the License, or (at your |
option) any later version. |
option) any later version. |
|
|
The GNU MP Library is distributed in the hope that it will be useful, but |
The GNU MP Library is distributed in the hope that it will be useful, but |
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
License for more details. |
License for more details. |
|
|
You should have received a copy of the GNU Library General Public License |
You should have received a copy of the GNU Lesser General Public License |
along with the GNU MP Library; see the file COPYING.LIB. If not, write to |
along with the GNU MP Library; see the file COPYING.LIB. If not, write to |
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
MA 02111-1307, USA. */ |
MA 02111-1307, USA. */ |
Line 23 MA 02111-1307, USA. */ |
|
Line 24 MA 02111-1307, USA. */ |
|
#include "gmp-impl.h" |
#include "gmp-impl.h" |
|
|
void |
void |
#if __STDC__ |
|
mpf_sub (mpf_ptr r, mpf_srcptr u, mpf_srcptr v) |
mpf_sub (mpf_ptr r, mpf_srcptr u, mpf_srcptr v) |
#else |
|
mpf_sub (r, u, v) |
|
mpf_ptr r; |
|
mpf_srcptr u; |
|
mpf_srcptr v; |
|
#endif |
|
{ |
{ |
mp_srcptr up, vp; |
mp_srcptr up, vp; |
mp_ptr rp, tp; |
mp_ptr rp, tp; |
Line 52 mpf_sub (r, u, v) |
|
Line 46 mpf_sub (r, u, v) |
|
} |
} |
if (vsize == 0) |
if (vsize == 0) |
{ |
{ |
mpf_set (r, u); |
if (r != u) |
|
mpf_set (r, u); |
return; |
return; |
} |
} |
|
|
Line 110 mpf_sub (r, u, v) |
|
Line 105 mpf_sub (r, u, v) |
|
|
|
if (usize == 0) |
if (usize == 0) |
{ |
{ |
|
if (vsize > prec) |
|
{ |
|
vp += vsize - prec; |
|
vsize = prec; |
|
} |
rsize = vsize; |
rsize = vsize; |
tp = (mp_ptr) vp; |
tp = (mp_ptr) vp; |
negate ^= 1; |
negate ^= 1; |
Line 117 mpf_sub (r, u, v) |
|
Line 117 mpf_sub (r, u, v) |
|
} |
} |
if (vsize == 0) |
if (vsize == 0) |
{ |
{ |
|
if (usize > prec) |
|
{ |
|
up += usize - prec; |
|
usize = prec; |
|
} |
rsize = usize; |
rsize = usize; |
tp = (mp_ptr) up; |
tp = (mp_ptr) up; |
goto normalize; |
goto normalize; |
Line 131 mpf_sub (r, u, v) |
|
Line 136 mpf_sub (r, u, v) |
|
wouldn't have exited unless up[usize - 1] and vp[vsize - 1] |
wouldn't have exited unless up[usize - 1] and vp[vsize - 1] |
were non-equal, this if-statement catches all cases where U |
were non-equal, this if-statement catches all cases where U |
is smaller than V. */ |
is smaller than V. */ |
{ mp_srcptr tp = up; up = vp; vp = tp; } |
MPN_SRCPTR_SWAP (up,usize, vp,vsize); |
{ mp_size_t tsize = usize; usize = vsize; vsize = tsize; } |
|
negate ^= 1; |
negate ^= 1; |
/* negating ediff not necessary since it is 0. */ |
/* negating ediff not necessary since it is 0. */ |
} |
} |
Line 152 mpf_sub (r, u, v) |
|
Line 156 mpf_sub (r, u, v) |
|
1 00000000 ... |
1 00000000 ... |
0 ffffffff ... */ |
0 ffffffff ... */ |
|
|
if (up[usize - 1] != 1 || vp[vsize - 1] != ~(mp_limb_t) 0 |
if (up[usize - 1] != 1 || vp[vsize - 1] != GMP_NUMB_MAX |
|| (usize >= 2 && up[usize - 2] != 0)) |
|| (usize >= 2 && up[usize - 2] != 0)) |
goto general_case; |
goto general_case; |
|
|
Line 162 mpf_sub (r, u, v) |
|
Line 166 mpf_sub (r, u, v) |
|
|
|
/* Skip sequences of 00000000/ffffffff */ |
/* Skip sequences of 00000000/ffffffff */ |
while (vsize != 0 && usize != 0 && up[usize - 1] == 0 |
while (vsize != 0 && usize != 0 && up[usize - 1] == 0 |
&& vp[vsize - 1] == ~(mp_limb_t) 0) |
&& vp[vsize - 1] == GMP_NUMB_MAX) |
{ |
{ |
usize--; |
usize--; |
vsize--; |
vsize--; |
Line 171 mpf_sub (r, u, v) |
|
Line 175 mpf_sub (r, u, v) |
|
|
|
if (usize == 0) |
if (usize == 0) |
{ |
{ |
while (vsize != 0 && vp[vsize - 1] == ~(mp_limb_t) 0) |
while (vsize != 0 && vp[vsize - 1] == GMP_NUMB_MAX) |
{ |
{ |
vsize--; |
vsize--; |
exp--; |
exp--; |
Line 208 mpf_sub (r, u, v) |
|
Line 212 mpf_sub (r, u, v) |
|
mp_size_t size, i; |
mp_size_t size, i; |
size = vsize; |
size = vsize; |
for (i = 0; i < size; i++) |
for (i = 0; i < size; i++) |
tp[i] = ~vp[i]; |
tp[i] = ~vp[i] & GMP_NUMB_MASK; |
cy_limb = 1 - mpn_add_1 (tp, tp, vsize, (mp_limb_t) 1); |
cy_limb = 1 - mpn_add_1 (tp, tp, vsize, (mp_limb_t) 1); |
rsize = vsize; |
rsize = vsize; |
if (cy_limb == 0) |
if (cy_limb == 0) |
Line 236 mpf_sub (r, u, v) |
|
Line 240 mpf_sub (r, u, v) |
|
mp_size_t size, i; |
mp_size_t size, i; |
size = vsize - usize; |
size = vsize - usize; |
for (i = 0; i < size; i++) |
for (i = 0; i < size; i++) |
tp[i] = ~vp[i]; |
tp[i] = ~vp[i] & GMP_NUMB_MASK; |
cy_limb = mpn_sub_n (tp + size, up, vp + size, usize); |
cy_limb = mpn_sub_n (tp + size, up, vp + size, usize); |
cy_limb+= mpn_sub_1 (tp + size, tp + size, usize, (mp_limb_t) 1); |
cy_limb+= mpn_sub_1 (tp + size, tp + size, usize, (mp_limb_t) 1); |
cy_limb-= mpn_add_1 (tp, tp, vsize, (mp_limb_t) 1); |
cy_limb-= mpn_add_1 (tp, tp, vsize, (mp_limb_t) 1); |
|
|
/* vvvvvvv */ |
/* vvvvvvv */ |
mp_size_t size, i; |
mp_size_t size, i; |
size = vsize - usize; |
size = vsize - usize; |
tp[0] = -vp[0]; |
tp[0] = -vp[0] & GMP_NUMB_MASK; |
for (i = 1; i < size; i++) |
for (i = 1; i < size; i++) |
tp[i] = ~vp[i]; |
tp[i] = ~vp[i] & GMP_NUMB_MASK; |
mpn_sub_n (tp + size, up, vp + size, usize); |
mpn_sub_n (tp + size, up, vp + size, usize); |
mpn_sub_1 (tp + size, tp + size, usize, (mp_limb_t) 1); |
mpn_sub_1 (tp + size, tp + size, usize, (mp_limb_t) 1); |
rsize = vsize; |
rsize = vsize; |
|
|
/* vvvvv */ |
/* vvvvv */ |
mp_size_t size, i; |
mp_size_t size, i; |
size = vsize + ediff - usize; |
size = vsize + ediff - usize; |
tp[0] = -vp[0]; |
tp[0] = -vp[0] & GMP_NUMB_MASK; |
for (i = 1; i < size; i++) |
for (i = 1; i < size; i++) |
tp[i] = ~vp[i]; |
tp[i] = ~vp[i] & GMP_NUMB_MASK; |
mpn_sub (tp + size, up, usize, vp + size, usize - ediff); |
mpn_sub (tp + size, up, usize, vp + size, usize - ediff); |
mpn_sub_1 (tp + size, tp + size, usize, (mp_limb_t) 1); |
mpn_sub_1 (tp + size, tp + size, usize, (mp_limb_t) 1); |
rsize = vsize + ediff; |
rsize = vsize + ediff; |
|
|
/* vv */ |
/* vv */ |
mp_size_t size, i; |
mp_size_t size, i; |
size = vsize + ediff - usize; |
size = vsize + ediff - usize; |
tp[0] = -vp[0]; |
tp[0] = -vp[0] & GMP_NUMB_MASK; |
for (i = 1; i < vsize; i++) |
for (i = 1; i < vsize; i++) |
tp[i] = ~vp[i]; |
tp[i] = ~vp[i] & GMP_NUMB_MASK; |
for (i = vsize; i < size; i++) |
for (i = vsize; i < size; i++) |
tp[i] = ~(mp_limb_t) 0; |
tp[i] = GMP_NUMB_MAX; |
mpn_sub_1 (tp + size, up, usize, (mp_limb_t) 1); |
mpn_sub_1 (tp + size, up, usize, (mp_limb_t) 1); |
rsize = size + usize; |
rsize = size + usize; |
} |
} |