1 /* mpf_add_ui -- Add a float and an unsigned integer.
3 Copyright (C) 1993, 1994, 1996 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 Library General Public License as published by
9 the Free Software Foundation; either version 2 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 Library General Public
15 License for more details.
17 You should have received a copy of the GNU Library 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. */
27 mpf_add_ui (mpf_ptr sum, mpf_srcptr u, unsigned long int v)
29 mpf_add_ui (sum, u, v)
35 mp_srcptr up = u->_mp_d;
36 mp_ptr sump = sum->_mp_d;
37 mp_size_t usize, sumsize;
38 mp_size_t prec = sum->_mp_prec;
39 mp_exp_t uexp = u->_mp_exp;
51 __mpf_struct u_negated;
52 u_negated._mp_size = -usize;
53 u_negated._mp_exp = u->_mp_exp;
54 u_negated._mp_d = u->_mp_d;
55 mpf_sub_ui (sum, &u_negated, v);
56 sum->_mp_size = -(sum->_mp_size);
66 sumsize = MIN (usize, prec + 1);
67 MPN_COPY (sum->_mp_d, up + usize - sumsize, sumsize);
68 sum->_mp_size = sumsize;
69 sum->_mp_exp = u->_mp_exp;
79 /* U >> V, V is not part of final result. */
84 /* U's "limb point" is somewhere between the first limb
86 Both U and V are part of the final result. */
91 /* We begin with moving U to the top of SUM, to handle
93 MPN_COPY_DECR (sump + uexp - usize, up, usize);
95 MPN_ZERO (sump + 1, uexp - usize - 1);
96 #if 0 /* What is this??? */
98 MPN_COPY (sum->_mp_d, sump, uexp);
100 sum->_mp_size = uexp;
110 /* Ignore excess limbs in U. */
112 usize -= usize - prec; /* Eq. usize = prec */
115 MPN_COPY (sump, up, usize - uexp);
116 cy_limb = mpn_add_1 (sump + usize - uexp, up + usize - uexp,
117 uexp, (mp_limb_t) v);
118 sump[usize] = cy_limb;
119 sum->_mp_size = usize + cy_limb;
120 sum->_mp_exp = uexp + cy_limb;
126 /* U < 1, so V > U for sure. */
137 if (usize + (-uexp) + 1 > prec)
139 /* Ignore excess limbs in U. */
140 up += usize + (-uexp) + 1 - prec;
141 usize -= usize + (-uexp) + 1 - prec;
144 MPN_COPY (sump, up, usize);
145 MPN_ZERO (sump + usize, -uexp);
146 sump[usize + (-uexp)] = v;
147 sum->_mp_size = usize + (-uexp) + 1;