summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Zimmermann <Paul.Zimmermann@inria.fr>2018-04-19 20:45:59 +0200
committerPaul Zimmermann <Paul.Zimmermann@inria.fr>2018-04-19 20:45:59 +0200
commit0576b43a711fb65c0a5e447dcf96081670f85e1e (patch)
treee1328ace707318689b9f22e743d6dbcee32cd0ab
parent0641b55b6a5665b2449c70a6073db722ad15269e (diff)
downloadmpc-git-0576b43a711fb65c0a5e447dcf96081670f85e1e.tar.gz
check return value of malloc() is not NULL in mpc_sum
-rw-r--r--NEWS3
-rw-r--r--doc/mpc.texi4
-rw-r--r--src/Makefile.am4
-rw-r--r--src/mpc.h1
-rw-r--r--src/sum.c2
-rw-r--r--tests/Makefile.am2
6 files changed, 13 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index 2fa0ad9..c2025c7 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,6 @@
+Changes in version xxx:
+ - New functions: mpc_sum
+
Changes in version 1.1.0:
- Minimally required library versions: GMP 5.0.0 and MPFR 3.0.0
- Fixed issues with MPFR 4.0.0
diff --git a/doc/mpc.texi b/doc/mpc.texi
index f324b99..7cf43b2 100644
--- a/doc/mpc.texi
+++ b/doc/mpc.texi
@@ -939,6 +939,10 @@ of the real and imaginary parts by @var{op2}
when @var{rop} and @var{op1} are identical.
@end deftypefun
+@deftypefun int mpc_sum (mpc_t @var{rop}, mpc_ptr* @var{op}, unsigned long @var{n}, mpc_rnd_t @var{rnd})
+Set @var{rop} to the sum of the array @var{op} of length @var{n}
+rounded according to @var{rnd}.
+@end deftypefun
@node Power Functions and Logarithm
@section Power Functions and Logarithm
diff --git a/src/Makefile.am b/src/Makefile.am
index 97c7a06..c17c9da 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -30,7 +30,7 @@ libmpc_la_SOURCES = mpc-impl.h abs.c acos.c acosh.c add.c add_fr.c \
pow_ld.c pow_d.c pow_si.c pow_ui.c pow_z.c proj.c real.c rootofunity.c \
urandom.c set.c \
set_prec.c set_str.c set_x.c set_x_x.c sin.c sin_cos.c sinh.c sqr.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
+ sqrt.c strtoc.c sub.c sub_fr.c sub_ui.c sum.c swap.c tan.c tanh.c \
+ uceil_log2.c ui_div.c ui_ui_sub.c
libmpc_la_LIBADD = @LTLIBOBJS@
diff --git a/src/mpc.h b/src/mpc.h
index 07da900..5252d9d 100644
--- a/src/mpc.h
+++ b/src/mpc.h
@@ -201,6 +201,7 @@ __MPC_DECLSPEC int mpc_asinh (mpc_ptr, mpc_srcptr, mpc_rnd_t);
__MPC_DECLSPEC int mpc_acosh (mpc_ptr, mpc_srcptr, mpc_rnd_t);
__MPC_DECLSPEC int mpc_atanh (mpc_ptr, mpc_srcptr, mpc_rnd_t);
__MPC_DECLSPEC int mpc_rootofunity (mpc_ptr, unsigned long int, unsigned long int, mpc_rnd_t);
+__MPC_DECLSPEC int mpc_sum (mpc_ptr, const mpc_ptr *, unsigned long, mpc_rnd_t);
__MPC_DECLSPEC void mpc_clear (mpc_ptr);
__MPC_DECLSPEC int mpc_urandom (mpc_ptr, gmp_randstate_t);
__MPC_DECLSPEC void mpc_init2 (mpc_ptr, mpfr_prec_t);
diff --git a/src/sum.c b/src/sum.c
index 9cebe12..243286c 100644
--- a/src/sum.c
+++ b/src/sum.c
@@ -18,6 +18,7 @@ You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see http://www.gnu.org/licenses/ .
*/
+#include <stdio.h> /* for MPC_ASSERT */
#include "mpc-impl.h"
int
@@ -28,6 +29,7 @@ mpc_sum (mpc_ptr sum, const mpc_ptr *z, unsigned long n, mpc_rnd_t rnd)
unsigned long i;
t = (mpfr_ptr *) malloc (n * sizeof(mpfr_t));
+ MPC_ASSERT(t != NULL);
for (i = 0; i < n; i++)
t[i] = mpc_realref (z[i]);
inex_re = mpfr_sum (mpc_realref (sum), t, n, MPC_RND_RE (rnd));
diff --git a/tests/Makefile.am b/tests/Makefile.am
index baa3e63..c7e4616 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -37,7 +37,7 @@ check_PROGRAMS = tabs tacos tacosh tadd tadd_fr tadd_si tadd_ui targ \
tpow_d tpow_fr tpow_ld tpow_si tpow_ui tpow_z tprec tproj treal \
treimref trootofunity \
tset tsin tsin_cos tsinh tsqr tsqrt tstrtoc tsub tsub_fr \
- tsub_ui tswap ttan ttanh tui_div tui_ui_sub tget_version exceptions
+ tsub_ui tsum tswap ttan ttanh tui_div tui_ui_sub tget_version exceptions
check_LTLIBRARIES=libmpc-tests.la
libmpc_tests_la_SOURCES = mpc-tests.h check_data.c clear_parameters.c \