1 /* mpf_add_ui -- Add a float and an unsigned integer.
3 Copyright 1993, 1994, 1996, 2000, 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 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
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
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/. */
35 mpf_add_ui (mpf_ptr sum
, mpf_srcptr u
, unsigned long int v
)
37 mp_srcptr up
= u
->_mp_d
;
38 mp_ptr sump
= sum
->_mp_d
;
39 mp_size_t usize
, sumsize
;
40 mp_size_t prec
= sum
->_mp_prec
;
41 mp_exp_t uexp
= u
->_mp_exp
;
53 __mpf_struct u_negated
;
54 u_negated
._mp_size
= -usize
;
55 u_negated
._mp_exp
= u
->_mp_exp
;
56 u_negated
._mp_d
= u
->_mp_d
;
57 mpf_sub_ui (sum
, &u_negated
, v
);
58 sum
->_mp_size
= -(sum
->_mp_size
);
68 sumsize
= MIN (usize
, prec
+ 1);
69 MPN_COPY (sum
->_mp_d
, up
+ usize
- sumsize
, sumsize
);
70 sum
->_mp_size
= sumsize
;
71 sum
->_mp_exp
= u
->_mp_exp
;
81 /* U >> V, V is not part of final result. */
86 /* U's "limb point" is somewhere between the first limb
88 Both U and V are part of the final result. */
93 /* We begin with moving U to the top of SUM, to handle
95 MPN_COPY_DECR (sump
+ uexp
- usize
, up
, usize
);
97 MPN_ZERO (sump
+ 1, uexp
- usize
- 1);
98 #if 0 /* What is this??? */
100 MPN_COPY (sum
->_mp_d
, sump
, uexp
);
102 sum
->_mp_size
= uexp
;
112 /* Ignore excess limbs in U. */
114 usize
-= usize
- prec
; /* Eq. usize = prec */
117 MPN_COPY_INCR (sump
, up
, usize
- uexp
);
118 cy_limb
= mpn_add_1 (sump
+ usize
- uexp
, up
+ usize
- uexp
,
119 uexp
, (mp_limb_t
) v
);
120 sump
[usize
] = cy_limb
;
121 sum
->_mp_size
= usize
+ cy_limb
;
122 sum
->_mp_exp
= uexp
+ cy_limb
;
128 /* U < 1, so V > U for sure. */
139 if (usize
+ (-uexp
) + 1 > prec
)
141 /* Ignore excess limbs in U. */
142 up
+= usize
+ (-uexp
) + 1 - prec
;
143 usize
-= usize
+ (-uexp
) + 1 - prec
;
146 MPN_COPY_INCR (sump
, up
, usize
);
147 MPN_ZERO (sump
+ usize
, -uexp
);
148 sump
[usize
+ (-uexp
)] = v
;
149 sum
->_mp_size
= usize
+ (-uexp
) + 1;