(root)/
mpfr-4.2.1/
src/
d_sub.c
       1  /* mpfr_d_sub -- subtract a multiple precision floating-point number
       2                   from a machine double precision float
       3  
       4  Copyright 2007-2023 Free Software Foundation, Inc.
       5  Contributed by the AriC and Caramba projects, INRIA.
       6  
       7  This file is part of the GNU MPFR Library.
       8  
       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.
      13  
      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.
      18  
      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  https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
      22  51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
      23  
      24  #include "mpfr-impl.h"
      25  
      26  int
      27  mpfr_d_sub (mpfr_ptr a, double b, mpfr_srcptr c, mpfr_rnd_t rnd_mode)
      28  {
      29    int inexact;
      30    mpfr_t d;
      31    mp_limb_t tmp_man[MPFR_LIMBS_PER_DOUBLE];
      32    MPFR_SAVE_EXPO_DECL (expo);
      33  
      34    MPFR_LOG_FUNC (
      35      ("b=%.20g c[%Pd]=%.*Rg rnd=%d", b, mpfr_get_prec (c), mpfr_log_prec, c, rnd_mode),
      36      ("a[%Pd]=%.*Rg", mpfr_get_prec (a), mpfr_log_prec, a));
      37  
      38    MPFR_SAVE_EXPO_MARK (expo);
      39  
      40    MPFR_TMP_INIT1(tmp_man, d, IEEE_DBL_MANT_DIG);
      41    inexact = mpfr_set_d (d, b, rnd_mode);
      42    MPFR_ASSERTD (inexact == 0);
      43  
      44    MPFR_CLEAR_FLAGS ();
      45    inexact = mpfr_sub (a, d, c, rnd_mode);
      46    MPFR_SAVE_EXPO_UPDATE_FLAGS (expo, __gmpfr_flags);
      47  
      48    MPFR_SAVE_EXPO_FREE (expo);
      49    return mpfr_check_range (a, inexact, rnd_mode);
      50  }