191094Sdes/* mpfr_swap (U, V) -- Swap U and V.
291094Sdes
391094SdesCopyright 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
491094SdesContributed by the Arenaire and Cacao projects, INRIA.
591094Sdes
691094SdesThis file is part of the GNU MPFR Library.
7117610Sdes
8117610SdesThe GNU MPFR Library is free software; you can redistribute it and/or modify
991094Sdesit under the terms of the GNU Lesser General Public License as published by
10117610Sdesthe Free Software Foundation; either version 3 of the License, or (at your
11117610Sdesoption) any later version.
12117610Sdes
13117610SdesThe GNU MPFR Library is distributed in the hope that it will be useful, but
1491094SdesWITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1591094Sdesor FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16117610SdesLicense for more details.
17117610Sdes
1891094SdesYou should have received a copy of the GNU Lesser General Public License
19174832Sdesalong with the GNU MPFR Library; see the file COPYING.LESSER.  If not, see
20174832Sdeshttp://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
21174832Sdes51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
22117610Sdes
23117610Sdes#include "mpfr-impl.h"
24117610Sdes
25117610Sdes/* Using memcpy is a few slower than swapping by hand. */
26117610Sdes
27174832Sdesvoid
28174832Sdesmpfr_swap (mpfr_ptr u, mpfr_ptr v)
29117610Sdes{
30117610Sdes  mpfr_prec_t p1, p2;
31117610Sdes  mpfr_sign_t s1, s2;
32117610Sdes  mpfr_exp_t e1, e2;
33174832Sdes  mp_limb_t *m1, *m2;
34174832Sdes
35174832Sdes  p1 = MPFR_PREC(u);
36117610Sdes  p2 = MPFR_PREC(v);
37117610Sdes  MPFR_PREC(v) = p1;
38117610Sdes  MPFR_PREC(u) = p2;
39117610Sdes
40117610Sdes  s1 = MPFR_SIGN(u);
41174832Sdes  s2 = MPFR_SIGN(v);
42117610Sdes  MPFR_SIGN(v) = s1;
4391094Sdes  MPFR_SIGN(u) = s2;
4491094Sdes
45117610Sdes  e1 = MPFR_EXP(u);
46117610Sdes  e2 = MPFR_EXP(v);
4791094Sdes  MPFR_EXP(v) = e1;
48117610Sdes  MPFR_EXP(u) = e2;
49117610Sdes
5091094Sdes  m1 = MPFR_MANT(u);
5191094Sdes  m2 = MPFR_MANT(v);
52117610Sdes  MPFR_MANT(v) = m1;
53117610Sdes  MPFR_MANT(u) = m2;
54117610Sdes}
55117610Sdes