summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzimmerma <zimmerma@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2009-08-26 11:48:19 +0000
committerzimmerma <zimmerma@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2009-08-26 11:48:19 +0000
commit2c4dee58cc90c46f48d6363ffb3f79ccf870f6bd (patch)
tree5dcae76bc09bb3a0b481ef4ff96d25143b2666d3
parentf91af7bc6941fddfdd8809aed61adfee3fbe87b7 (diff)
downloadmpc-2c4dee58cc90c46f48d6363ffb3f79ccf870f6bd.tar.gz
[swap.c] new function mpc_swap
git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@664 211d60ee-9f03-0410-a15a-8952a2c7a4e4
-rw-r--r--NEWS2
-rw-r--r--doc/mpc.texi7
-rw-r--r--src/Makefile.am5
-rw-r--r--src/mpc.h1
-rw-r--r--src/swap.c30
5 files changed, 42 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index abf3515..defc659 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,5 @@
Recent Changes:
- - New functions: mpc_pow, mpc_set_nan
+ - New functions: mpc_pow, mpc_set_nan, mpc_swap
- Bug fixes:
- log: along branch cut
- norm: infinite loop in case of overflow
diff --git a/doc/mpc.texi b/doc/mpc.texi
index 8adc56e..12650ea 100644
--- a/doc/mpc.texi
+++ b/doc/mpc.texi
@@ -626,6 +626,13 @@ For functions assigning complex variables from strings or input streams,
Set @var{rop} to Nan+i*NaN.
@end deftypefun
+@deftypefun void mpc_swap (mpc_t @var{op1}, mpc_t @var{op2})
+Swap the values of @var{op1} and @var{op2} efficiently. Warning: the
+precisions are exchanged too; in case the precisions are different,
+@code{mpc_swap} is thus not equivalent to three @code{mpc_set} calls using a
+third auxiliary variable.
+@end deftypefun
+
@node String and Stream Input and Output, Complex Comparison, Assigning Complex Numbers, Complex Functions
@comment node-name, next, previous, up
diff --git a/src/Makefile.am b/src/Makefile.am
index e36d26f..9979659 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,5 +9,6 @@ libmpc_la_SOURCES = mpc-impl.h abs.c add.c add_fr.c add_ui.c arg.c clear.c \
imag.c init2.c init3.c inp_str.c log.c mem.c mul_2exp.c mul.c mul_fr.c \
mul_i.c mul_si.c mul_ui.c neg.c norm.c out_str.c pow.c proj.c real.c \
urandom.c set.c set_prec.c set_str.c set_x.c set_x_x.c sin.c sinh.c sqr.c \
- sqrt.c strtoc.c sub.c sub_fr.c sub_ui.c tan.c tanh.c uceil_log2.c ui_div.c \
- ui_ui_sub.c
+ sqrt.c strtoc.c sub.c sub_fr.c sub_ui.c swap.c tan.c tanh.c uceil_log2.c \
+ ui_div.c ui_ui_sub.c
+
diff --git a/src/mpc.h b/src/mpc.h
index 48adcc5..1ab6a40 100644
--- a/src/mpc.h
+++ b/src/mpc.h
@@ -172,6 +172,7 @@ __MPC_DECLSPEC int mpc_set_ui __MPC_PROTO ((mpc_ptr, unsigned long int, mpc_
__MPC_DECLSPEC int mpc_set_ui_ui __MPC_PROTO ((mpc_ptr, unsigned long int, unsigned long int, mpc_rnd_t));
__MPC_DECLSPEC int mpc_set_z __MPC_PROTO ((mpc_ptr, mpz_srcptr, mpc_rnd_t));
__MPC_DECLSPEC int mpc_set_z_z __MPC_PROTO ((mpc_ptr, mpz_srcptr, mpz_srcptr, mpc_rnd_t));
+__MPC_DECLSPEC void mpc_swap __MPC_PROTO ((mpc_ptr, mpc_ptr));
#ifdef _MPC_H_HAVE_INTMAX_T
__MPC_DECLSPEC int mpc_set_sj __MPC_PROTO ((mpc_ptr, intmax_t, mpc_rnd_t));
diff --git a/src/swap.c b/src/swap.c
new file mode 100644
index 0000000..4a6f70e
--- /dev/null
+++ b/src/swap.c
@@ -0,0 +1,30 @@
+/* mpc_swap -- Swap two complex numbers.
+
+Copyright (C) 2009 Paul Zimmermann
+
+This file is part of the MPC Library.
+
+The MPC Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or (at your
+option) any later version.
+
+The MPC Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the MPC Library; see the file COPYING.LIB. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+#include "mpc-impl.h"
+
+void
+mpc_swap (mpc_ptr a, mpc_ptr b)
+{
+ /* assumes real and imaginary parts do not overlap */
+ mpfr_swap (MPC_RE(a), MPC_RE(b));
+ mpfr_swap (MPC_IM(a), MPC_IM(b));
+}