beta-0.89.2
[luatex.git] / source / libs / mpfr / mpfr-3.1.3 / src / add_d.c
blobee55aed2499c61d966c3936c27d30a426fa08677
1 /* mpfr_add_d -- add a multiple precision floating-point number
2 to a machine double precision float
4 Copyright 2007-2015 Free Software Foundation, Inc.
5 Contributed by the AriC and Caramel projects, INRIA.
7 This file is part of the GNU MPFR Library.
9 The GNU MPFR Library is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or (at your
12 option) any later version.
14 The GNU MPFR Library is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17 License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
21 http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
22 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
24 #include "mpfr-impl.h"
26 int
27 mpfr_add_d (mpfr_ptr a, mpfr_srcptr b, double c, mpfr_rnd_t rnd_mode)
29 int inexact;
30 mpfr_t d;
31 MPFR_SAVE_EXPO_DECL (expo);
33 MPFR_LOG_FUNC
34 (("b[%Pu]=%.*Rg c=%.20g rnd=%d",
35 mpfr_get_prec(b), mpfr_log_prec, b, c, rnd_mode),
36 ("a[%Pu]=%.*Rg inexact=%d",
37 mpfr_get_prec (a), mpfr_log_prec, a, inexact));
39 MPFR_SAVE_EXPO_MARK (expo);
41 mpfr_init2 (d, IEEE_DBL_MANT_DIG);
42 inexact = mpfr_set_d (d, c, rnd_mode);
43 MPFR_ASSERTN (inexact == 0);
45 mpfr_clear_flags ();
46 inexact = mpfr_add (a, b, d, rnd_mode);
47 MPFR_SAVE_EXPO_UPDATE_FLAGS (expo, __gmpfr_flags);
49 mpfr_clear (d);
50 MPFR_SAVE_EXPO_FREE (expo);
51 return mpfr_check_range (a, inexact, rnd_mode);