1
/* mpfr_mul_2ui -- multiply a floating-point number by a power of two
3
Copyright 1999, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5
This file is part of the MPFR Library.
7
The MPFR Library is free software; you can redistribute it and/or modify
8
it under the terms of the GNU Lesser General Public License as published by
9
the Free Software Foundation; either version 2.1 of the License, or (at your
10
option) any later version.
12
The MPFR 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 Lesser General Public
15
License for more details.
17
You should have received a copy of the GNU Lesser General Public License
18
along with the MPFR Library; see the file COPYING.LIB. If not, write to
19
the Free Software Foundation, Inc., 51 Franklin Place, Fifth Floor, Boston,
20
MA 02110-1301, USA. */
22
#include "mpfr-impl.h"
25
mpfr_mul_2ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int n, mp_rnd_t rnd_mode)
29
inexact = MPFR_UNLIKELY(y != x) ? mpfr_set (y, x, rnd_mode) : 0;
31
if (MPFR_LIKELY( MPFR_IS_PURE_FP(y)) )
33
/* n will have to be casted to long to make sure that the addition
34
and subtraction below (for overflow detection) are signed */
35
while (MPFR_UNLIKELY(n > LONG_MAX))
40
inex2 = mpfr_mul_2ui(y, y, LONG_MAX, rnd_mode);
42
return inex2; /* overflow */
45
/* MPFR_EMIN_MIN + (long) n is signed and doesn't lead to an overflow;
46
the first test useful so that the real test can't lead to an
49
mp_exp_t exp = MPFR_GET_EXP (y);
50
if (MPFR_UNLIKELY( __gmpfr_emax < MPFR_EMIN_MIN + (long) n ||
51
exp > __gmpfr_emax - (long) n))
52
return mpfr_overflow (y, rnd_mode, MPFR_SIGN(y));
54
MPFR_SET_EXP (y, exp + (long) n);