summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorenge <enge@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2012-09-19 11:17:49 +0000
committerenge <enge@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2012-09-19 11:17:49 +0000
commitf4f7fe967cee583595999be3267f3c253064fa3e (patch)
tree5d9efd557b23ca31a5921219c05f41b00f9c7932
parente544b22eb979c53b5bea256ab8ff0c29f5756ffe (diff)
downloadmpc-rootsunity.tar.gz
merge trunk into branch rootsunityrootsunity
git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/branches/rootsunity@1273 211d60ee-9f03-0410-a15a-8952a2c7a4e4
-rw-r--r--BUGS2
-rw-r--r--INSTALL8
-rw-r--r--Makefile.vc268
-rw-r--r--NEWS90
-rw-r--r--README.dev44
-rw-r--r--TODO30
-rw-r--r--configure.ac22
-rw-r--r--doc/algorithms.bib46
-rw-r--r--doc/algorithms.tex308
-rw-r--r--doc/mpc.texi14
-rw-r--r--doc/version.texi8
-rw-r--r--m4/mpc.m44
-rw-r--r--m4/valgrind-tests.m416
-rw-r--r--src/Makefile.am13
-rw-r--r--src/acos.c37
-rw-r--r--src/acosh.c6
-rw-r--r--src/asin.c32
-rw-r--r--src/asinh.c4
-rw-r--r--src/atan.c84
-rw-r--r--src/atanh.c4
-rw-r--r--src/div.c136
-rw-r--r--src/div_2si.c (renamed from src/div_2exp.c)10
-rw-r--r--src/div_2ui.c (renamed from src/mul_2exp.c)10
-rw-r--r--src/div_fr.c4
-rw-r--r--src/exp.c30
-rw-r--r--src/fma.c34
-rw-r--r--src/fr_div.c4
-rw-r--r--src/get_version.c25
-rw-r--r--src/log.c129
-rw-r--r--src/log10.c96
-rw-r--r--src/mpc-impl.h57
-rw-r--r--src/mpc.h49
-rw-r--r--src/mul.c60
-rw-r--r--src/mul_2si.c32
-rw-r--r--src/mul_2ui.c32
-rw-r--r--src/mul_fr.c4
-rw-r--r--src/mul_i.c6
-rw-r--r--src/norm.c30
-rw-r--r--src/pow.c37
-rw-r--r--src/pow_fr.c4
-rw-r--r--src/pow_ui.c8
-rw-r--r--src/sin_cos.c42
-rw-r--r--src/sinh.c4
-rw-r--r--src/sqr.c35
-rw-r--r--src/sqrt.c98
-rw-r--r--src/strtoc.c4
-rw-r--r--src/tan.c24
-rw-r--r--src/tanh.c4
-rw-r--r--tests/Makefile.am9
-rw-r--r--tests/atan.dat10
-rw-r--r--tests/div.dat8
-rw-r--r--tests/log.dat31
-rw-r--r--tests/mpc-tests.h9
-rwxr-xr-xtests/mul.dat5
-rw-r--r--tests/pow.dat13
-rw-r--r--tests/random.c10
-rw-r--r--tests/read_data.c64
-rw-r--r--tests/sqrt.dat1
-rw-r--r--tests/tadd.c4
-rw-r--r--tests/tadd_fr.c6
-rw-r--r--tests/tadd_si.c4
-rw-r--r--tests/tadd_ui.c4
-rw-r--r--tests/tan.dat1
-rw-r--r--tests/tatan.c8
-rw-r--r--tests/tcos.c10
-rw-r--r--tests/tcosh.c10
-rw-r--r--tests/tdiv_2si.c (renamed from tests/tdiv_2exp.c)6
-rw-r--r--tests/tdiv_2ui.c35
-rw-r--r--tests/tfma.c4
-rw-r--r--tests/tgeneric.c124
-rw-r--r--tests/tmul.c22
-rw-r--r--tests/tmul_2si.c (renamed from tests/tmul_2exp.c)6
-rw-r--r--tests/tmul_2ui.c35
-rw-r--r--tests/tmul_i.c10
-rw-r--r--tests/tnorm.c18
-rw-r--r--tests/tpow.c6
-rw-r--r--tests/tpow_fr.c8
-rw-r--r--tests/tpow_ui.c8
-rw-r--r--tests/treimref.c10
-rw-r--r--tests/tset.c28
-rw-r--r--tests/tsqr.c8
-rw-r--r--tests/ttan.c46
-rw-r--r--tests/tui_div.c6
-rwxr-xr-xtools/coverage105
84 files changed, 1706 insertions, 1034 deletions
diff --git a/BUGS b/BUGS
index 14ef613..80e2017 100644
--- a/BUGS
+++ b/BUGS
@@ -12,4 +12,4 @@
Currently, the following functions have been rewritten to solve these
problems:
-mul, norm
+mul, norm, sqr
diff --git a/INSTALL b/INSTALL
index aa82a48..f2cb235 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,4 +1,4 @@
-Copyright (C) INRIA 2003, 2005, 2007, 2008, 2009, 2010, 2011
+Copyright (C) INRIA 2003, 2005, 2007, 2008, 2009, 2010, 2011, 2012
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
@@ -15,12 +15,12 @@ This is for the impatient, for deeper explanations see the chapter
0. You first need to install GMP, the GNU Multiprecision Arithmetic Library,
see <http://gmplib.org/>, and GNU MPFR, see <http://www.mpfr.org>.
GNU MPC requires GMP version 4.3.2 or later
- and GNU MPFR version 2.4.2 or later.
+ and GNU MPFR version 3.0.0 or later.
1. In the directory of the GNU MPC archive, type
- tar xzf mpc-1.0.0.tar.gz
- cd mpc-1.0.0
+ tar xzf mpc-1.1.tar.gz
+ cd mpc-1.1
./configure
make
diff --git a/Makefile.vc b/Makefile.vc
index 3c127e4..8f5226f 100644
--- a/Makefile.vc
+++ b/Makefile.vc
@@ -1,6 +1,6 @@
# Makefile for the MPC library (Windows version).
#
-# Copyright (C) INRIA - CNRS, 2002, 2004, 2005, 2007, 2008, 2009, 2010, 2011
+# Copyright (C) INRIA - CNRS, 2002, 2004, 2005, 2007, 2008, 2009, 2010, 2011, 2012
#
# This file is part of the MPC Library.
#
@@ -50,7 +50,7 @@ CPP = cl.exe
CC = cl.exe
CDEFAULTFLAGS=/O2 /GR- /MD /nologo /EHs
-VERSION=1.0.0dev
+VERSION=1.1dev
######################## do not edit below this line ##########################
@@ -83,7 +83,7 @@ INCLUDES = /I$(DIRMPC) /I$(GMPDIR)\include /I$(MPFR)\include
CKERNELFLAGS = $(CDEFAULTFLAGS) $(GMPMUSTBEDLL) $(INCLUDES)
CFLAGS = $(CKERNELFLAGS) /D__MPC_WITHIN_MPC /D_GMP_IEEE_FLOATS /DHAVE_CONFIG_H
-TESTCOMPILE=$(CC) $(CKERNELFLAGS) $(DIRMPCTESTS)\tgeneric.c $(DIRMPCTESTS)\comparisons.c $(DIRMPCTESTS)\memory.c $(DIRMPCTESTS)\read_data.c $(DIRMPCTESTS)\random.c $(DIRMPCTESTS)
+TESTCOMPILE=$(CC) $(CKERNELFLAGS) $(DIRMPCTESTS)\tgeneric.c $(DIRMPCTESTS)\comparisons.c $(DIRMPCTESTS)\read_data.c $(DIRMPCTESTS)\random.c $(DIRMPCTESTS)
MIDTESTCOMPILE=/link /out:$(DIRMPCTESTS)
ENDTESTCOMPILE=/LIBPATH:"$(GMPDIR)\lib" libmpc.lib libmpfr.lib libgmp.lib $(LIBS_LOGGING)
@@ -97,7 +97,7 @@ ENDTESTCOMPILE=/LIBPATH:"$(GMPDIR)\lib" libmpc.lib libmpfr.lib libgmp.lib $(LIBS
LIBRARYLIB = libmpc.lib
-CPPOBJECTS = $(DIRMPC)\abs.obj \
+CPPOBJECTS =$(DIRMPC)\abs.obj \
$(DIRMPC)\acos.obj \
$(DIRMPC)\acosh.obj \
$(DIRMPC)\add.obj \
@@ -116,7 +116,7 @@ $(DIRMPC)\conj.obj \
$(DIRMPC)\cos.obj \
$(DIRMPC)\cosh.obj \
$(DIRMPC)\div.obj \
-$(DIRMPC)\div_2exp.obj \
+$(DIRMPC)\div_2ui.obj \
$(DIRMPC)\div_fr.obj \
$(DIRMPC)\div_ui.obj \
$(DIRMPC)\exp.obj \
@@ -132,9 +132,10 @@ $(DIRMPC)\init2.obj \
$(DIRMPC)\init3.obj \
$(DIRMPC)\inp_str.obj \
$(DIRMPC)\log.obj \
+$(DIRMPC)\log10.obj \
$(DIRMPC)\mem.obj \
$(DIRMPC)\mul.obj \
-$(DIRMPC)\mul_2exp.obj \
+$(DIRMPC)\mul_2ui.obj \
$(DIRMPC)\mul_fr.obj \
$(DIRMPC)\mul_i.obj \
$(DIRMPC)\mul_si.obj \
@@ -192,7 +193,7 @@ conj.obj \
cos.obj \
cosh.obj \
div.obj \
-div_2exp.obj \
+div_2ui.obj \
div_fr.obj \
div_ui.obj \
exp.obj \
@@ -208,9 +209,10 @@ init2.obj \
init3.obj \
inp_str.obj \
log.obj \
+log10.obj \
mem.obj \
mul.obj \
-mul_2exp.obj \
+mul_2ui.obj \
mul_fr.obj \
mul_i.obj \
mul_si.obj \
@@ -246,8 +248,8 @@ tan.obj \
tanh.obj \
uceil_log2.obj \
ui_div.obj \
-ui_ui_sub.obj $(CPPLINKOBJECTS_LOGGING) \
-urandom.obj
+ui_ui_sub.obj $(CPPLINKOBJECTS_LOGGING) \
+urandom.obj
#
# Link target: automatically builds its object dependencies before
@@ -295,128 +297,130 @@ test :
-copy $(GMPDIR)\lib\*gmp*.dll $(DIRMPCTESTS)
-copy $(MPFRDIR)\lib\*mpfr*.dll $(DIRMPCTESTS)
copy $(LIBRARY) $(DIRMPCTESTS)
- $(TESTCOMPILE)tabs.c $(MIDTESTCOMPILE)tabs.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tabs.exe && cd ..
- $(TESTCOMPILE)tacos.c $(MIDTESTCOMPILE)tacos.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tacos.exe && cd ..
- $(TESTCOMPILE)tacosh.c $(MIDTESTCOMPILE)tacosh.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tacosh.exe && cd ..
- $(TESTCOMPILE)tadd.c $(MIDTESTCOMPILE)tadd.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tadd.exe && cd ..
- $(TESTCOMPILE)tadd_fr.c $(MIDTESTCOMPILE)tadd_fr.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tadd_fr.exe && cd ..
- $(TESTCOMPILE)tadd_si.c $(MIDTESTCOMPILE)tadd_si.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tadd_si.exe && cd ..
- $(TESTCOMPILE)tadd_ui.c $(MIDTESTCOMPILE)tadd_ui.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tadd_ui.exe && cd ..
- $(TESTCOMPILE)targ.c $(MIDTESTCOMPILE)targ.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && targ.exe && cd ..
- $(TESTCOMPILE)tasin.c $(MIDTESTCOMPILE)tasin.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tasin.exe && cd ..
- $(TESTCOMPILE)tasinh.c $(MIDTESTCOMPILE)tasinh.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tasinh.exe && cd ..
- $(TESTCOMPILE)tatan.c $(MIDTESTCOMPILE)tatan.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tatan.exe && cd ..
- $(TESTCOMPILE)tatanh.c $(MIDTESTCOMPILE)tatanh.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tatanh.exe && cd ..
- $(TESTCOMPILE)tconj.c $(MIDTESTCOMPILE)tconj.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tconj.exe && cd ..
- $(TESTCOMPILE)tcos.c $(MIDTESTCOMPILE)tcos.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tcos.exe && cd ..
- $(TESTCOMPILE)tcosh.c $(MIDTESTCOMPILE)tcosh.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tcosh.exe && cd ..
- $(TESTCOMPILE)tdiv.c $(MIDTESTCOMPILE)tdiv.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tdiv.exe && cd ..
- $(TESTCOMPILE)tdiv_2exp.c $(MIDTESTCOMPILE)tdiv_2exp.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tdiv_2exp.exe && cd ..
- $(TESTCOMPILE)tdiv_fr.c $(MIDTESTCOMPILE)tdiv_fr.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tdiv_fr.exe && cd ..
- $(TESTCOMPILE)tdiv_ui.c $(MIDTESTCOMPILE)tdiv_ui.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tdiv_ui.exe && cd ..
- $(TESTCOMPILE)texp.c $(MIDTESTCOMPILE)texp.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && texp.exe && cd ..
- $(TESTCOMPILE)tfma.c $(MIDTESTCOMPILE)tfma.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tfma.exe && cd ..
- $(TESTCOMPILE)tfr_div.c $(MIDTESTCOMPILE)tfr_div.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tfr_div.exe && cd ..
- $(TESTCOMPILE)tfr_sub.c $(MIDTESTCOMPILE)tfr_sub.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tfr_sub.exe && cd ..
- $(TESTCOMPILE)tget_version.c $(MIDTESTCOMPILE)tget_version.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tget_version.exe && cd ..
- $(TESTCOMPILE)timag.c $(MIDTESTCOMPILE)timag.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && timag.exe && cd ..
- $(TESTCOMPILE)tio_str.c $(MIDTESTCOMPILE)tio_str.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tio_str.exe && cd ..
- $(TESTCOMPILE)tlog.c $(MIDTESTCOMPILE)tlog.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tlog.exe && cd ..
- $(TESTCOMPILE)tmul.c $(MIDTESTCOMPILE)tmul.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tmul.exe && cd ..
- $(TESTCOMPILE)tmul_2exp.c $(MIDTESTCOMPILE)tmul_2exp.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tmul_2exp.exe && cd ..
- $(TESTCOMPILE)tmul_fr.c $(MIDTESTCOMPILE)tmul_fr.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tmul_fr.exe && cd ..
- $(TESTCOMPILE)tmul_i.c $(MIDTESTCOMPILE)tmul_i.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tmul_i.exe && cd ..
- $(TESTCOMPILE)tmul_si.c $(MIDTESTCOMPILE)tmul_si.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tmul_si.exe && cd ..
- $(TESTCOMPILE)tmul_ui.c $(MIDTESTCOMPILE)tmul_ui.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tmul_ui.exe && cd ..
- $(TESTCOMPILE)tneg.c $(MIDTESTCOMPILE)tneg.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tneg.exe && cd ..
- $(TESTCOMPILE)tnorm.c $(MIDTESTCOMPILE)tnorm.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tnorm.exe && cd ..
- $(TESTCOMPILE)tpow.c $(MIDTESTCOMPILE)tpow.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tpow.exe && cd ..
- $(TESTCOMPILE)tpow_d.c $(MIDTESTCOMPILE)tpow_d.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tpow_d.exe && cd ..
- $(TESTCOMPILE)tpow_fr.c $(MIDTESTCOMPILE)tpow_fr.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tpow_fr.exe && cd ..
- $(TESTCOMPILE)tpow_ld.c $(MIDTESTCOMPILE)tpow_ld.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tpow_ld.exe && cd ..
- $(TESTCOMPILE)tpow_si.c $(MIDTESTCOMPILE)tpow_si.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tpow_si.exe && cd ..
- $(TESTCOMPILE)tpow_ui.c $(MIDTESTCOMPILE)tpow_ui.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tpow_ui.exe && cd ..
- $(TESTCOMPILE)tpow_z.c $(MIDTESTCOMPILE)tpow_z.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tpow_z.exe && cd ..
- $(TESTCOMPILE)tprec.c $(MIDTESTCOMPILE)tprec.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tprec.exe && cd ..
- $(TESTCOMPILE)tproj.c $(MIDTESTCOMPILE)tproj.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tproj.exe && cd ..
- $(TESTCOMPILE)treal.c $(MIDTESTCOMPILE)treal.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && treal.exe && cd ..
- $(TESTCOMPILE)treimref.c $(MIDTESTCOMPILE)treimref.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && treimref.exe && cd ..
- $(TESTCOMPILE)tset.c $(MIDTESTCOMPILE)tset.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tset.exe && cd ..
- $(TESTCOMPILE)tsin.c $(MIDTESTCOMPILE)tsin.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tsin.exe && cd ..
- $(TESTCOMPILE)tsin_cos.c $(MIDTESTCOMPILE)tsin_cos.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tsin_cos.exe && cd ..
- $(TESTCOMPILE)tsinh.c $(MIDTESTCOMPILE)tsinh.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tsinh.exe && cd ..
- $(TESTCOMPILE)tsqr.c $(MIDTESTCOMPILE)tsqr.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tsqr.exe && cd ..
- $(TESTCOMPILE)tsqrt.c $(MIDTESTCOMPILE)tsqrt.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tsqrt.exe && cd ..
- $(TESTCOMPILE)tstrtoc.c $(MIDTESTCOMPILE)tstrtoc.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tstrtoc.exe && cd ..
- $(TESTCOMPILE)tsub.c $(MIDTESTCOMPILE)tsub.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tsub.exe && cd ..
- $(TESTCOMPILE)tsub_fr.c $(MIDTESTCOMPILE)tsub_fr.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tsub_fr.exe && cd ..
- $(TESTCOMPILE)tsub_ui.c $(MIDTESTCOMPILE)tsub_ui.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tsub_ui.exe && cd ..
- $(TESTCOMPILE)tswap.c $(MIDTESTCOMPILE)tswap.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tswap.exe && cd ..
- $(TESTCOMPILE)ttan.c $(MIDTESTCOMPILE)ttan.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && ttan.exe && cd ..
- $(TESTCOMPILE)ttanh.c $(MIDTESTCOMPILE)ttanh.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && ttanh.exe && cd ..
- $(TESTCOMPILE)tui_div.c $(MIDTESTCOMPILE)tui_div.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tui_div.exe && cd ..
- $(TESTCOMPILE)tui_ui_sub.c $(MIDTESTCOMPILE)tui_ui_sub.exe $(ENDTESTCOMPILE)
- cd $(DIRMPCTESTS) && tui_ui_sub.exe && cd ..
+ $(TESTCOMPILE)tabs.c $(MIDTESTCOMPILE)tabs.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tabs.exe && cd ..
+ $(TESTCOMPILE)tacos.c $(MIDTESTCOMPILE)tacos.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tacos.exe && cd ..
+ $(TESTCOMPILE)tacosh.c $(MIDTESTCOMPILE)tacosh.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tacosh.exe && cd ..
+ $(TESTCOMPILE)tadd.c $(MIDTESTCOMPILE)tadd.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tadd.exe && cd ..
+ $(TESTCOMPILE)tadd_fr.c $(MIDTESTCOMPILE)tadd_fr.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tadd_fr.exe && cd ..
+ $(TESTCOMPILE)tadd_si.c $(MIDTESTCOMPILE)tadd_si.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tadd_si.exe && cd ..
+ $(TESTCOMPILE)tadd_ui.c $(MIDTESTCOMPILE)tadd_ui.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tadd_ui.exe && cd ..
+ $(TESTCOMPILE)targ.c $(MIDTESTCOMPILE)targ.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && targ.exe && cd ..
+ $(TESTCOMPILE)tasin.c $(MIDTESTCOMPILE)tasin.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tasin.exe && cd ..
+ $(TESTCOMPILE)tasinh.c $(MIDTESTCOMPILE)tasinh.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tasinh.exe && cd ..
+ $(TESTCOMPILE)tatan.c $(MIDTESTCOMPILE)tatan.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tatan.exe && cd ..
+ $(TESTCOMPILE)tatanh.c $(MIDTESTCOMPILE)tatanh.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tatanh.exe && cd ..
+ $(TESTCOMPILE)tconj.c $(MIDTESTCOMPILE)tconj.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tconj.exe && cd ..
+ $(TESTCOMPILE)tcos.c $(MIDTESTCOMPILE)tcos.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tcos.exe && cd ..
+ $(TESTCOMPILE)tcosh.c $(MIDTESTCOMPILE)tcosh.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tcosh.exe && cd ..
+ $(TESTCOMPILE)tdiv.c $(MIDTESTCOMPILE)tdiv.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tdiv.exe && cd ..
+ $(TESTCOMPILE)tdiv_2ui.c $(MIDTESTCOMPILE)tdiv_2ui.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tdiv_2ui.exe && cd ..
+ $(TESTCOMPILE)tdiv_fr.c $(MIDTESTCOMPILE)tdiv_fr.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tdiv_fr.exe && cd ..
+ $(TESTCOMPILE)tdiv_ui.c $(MIDTESTCOMPILE)tdiv_ui.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tdiv_ui.exe && cd ..
+ $(TESTCOMPILE)texp.c $(MIDTESTCOMPILE)texp.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && texp.exe && cd ..
+ $(TESTCOMPILE)tfma.c $(MIDTESTCOMPILE)tfma.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tfma.exe && cd ..
+ $(TESTCOMPILE)tfr_div.c $(MIDTESTCOMPILE)tfr_div.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tfr_div.exe && cd ..
+ $(TESTCOMPILE)tfr_sub.c $(MIDTESTCOMPILE)tfr_sub.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tfr_sub.exe && cd ..
+ $(TESTCOMPILE)tget_version.c $(MIDTESTCOMPILE)tget_version.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tget_version.exe && cd ..
+ $(TESTCOMPILE)timag.c $(MIDTESTCOMPILE)timag.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && timag.exe && cd ..
+ $(TESTCOMPILE)tio_str.c $(MIDTESTCOMPILE)tio_str.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tio_str.exe && cd ..
+ $(TESTCOMPILE)tlog.c $(MIDTESTCOMPILE)tlog.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tlog.exe && cd ..
+ $(TESTCOMPILE)tlog10.c $(MIDTESTCOMPILE)tlog10.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tlog10.exe && cd ..
+ $(TESTCOMPILE)tmul.c $(MIDTESTCOMPILE)tmul.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tmul.exe && cd ..
+ $(TESTCOMPILE)tmul_2ui.c $(MIDTESTCOMPILE)tmul_2ui.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tmul_2ui.exe && cd ..
+ $(TESTCOMPILE)tmul_fr.c $(MIDTESTCOMPILE)tmul_fr.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tmul_fr.exe && cd ..
+ $(TESTCOMPILE)tmul_i.c $(MIDTESTCOMPILE)tmul_i.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tmul_i.exe && cd ..
+ $(TESTCOMPILE)tmul_si.c $(MIDTESTCOMPILE)tmul_si.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tmul_si.exe && cd ..
+ $(TESTCOMPILE)tmul_ui.c $(MIDTESTCOMPILE)tmul_ui.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tmul_ui.exe && cd ..
+ $(TESTCOMPILE)tneg.c $(MIDTESTCOMPILE)tneg.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tneg.exe && cd ..
+ $(TESTCOMPILE)tnorm.c $(MIDTESTCOMPILE)tnorm.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tnorm.exe && cd ..
+ $(TESTCOMPILE)tpow.c $(MIDTESTCOMPILE)tpow.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tpow.exe && cd ..
+ $(TESTCOMPILE)tpow_d.c $(MIDTESTCOMPILE)tpow_d.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tpow_d.exe && cd ..
+ $(TESTCOMPILE)tpow_fr.c $(MIDTESTCOMPILE)tpow_fr.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tpow_fr.exe && cd ..
+ $(TESTCOMPILE)tpow_ld.c $(MIDTESTCOMPILE)tpow_ld.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tpow_ld.exe && cd ..
+ $(TESTCOMPILE)tpow_si.c $(MIDTESTCOMPILE)tpow_si.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tpow_si.exe && cd ..
+ $(TESTCOMPILE)tpow_ui.c $(MIDTESTCOMPILE)tpow_ui.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tpow_ui.exe && cd ..
+ $(TESTCOMPILE)tpow_z.c $(MIDTESTCOMPILE)tpow_z.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tpow_z.exe && cd ..
+ $(TESTCOMPILE)tprec.c $(MIDTESTCOMPILE)tprec.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tprec.exe && cd ..
+ $(TESTCOMPILE)tproj.c $(MIDTESTCOMPILE)tproj.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tproj.exe && cd ..
+ $(TESTCOMPILE)treal.c $(MIDTESTCOMPILE)treal.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && treal.exe && cd ..
+ $(TESTCOMPILE)treimref.c $(MIDTESTCOMPILE)treimref.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && treimref.exe && cd ..
+ $(TESTCOMPILE)tset.c $(MIDTESTCOMPILE)tset.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tset.exe && cd ..
+ $(TESTCOMPILE)tsin.c $(MIDTESTCOMPILE)tsin.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tsin.exe && cd ..
+ $(TESTCOMPILE)tsin_cos.c $(MIDTESTCOMPILE)tsin_cos.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tsin_cos.exe && cd ..
+ $(TESTCOMPILE)tsinh.c $(MIDTESTCOMPILE)tsinh.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tsinh.exe && cd ..
+ $(TESTCOMPILE)tsqr.c $(MIDTESTCOMPILE)tsqr.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tsqr.exe && cd ..
+ $(TESTCOMPILE)tsqrt.c $(MIDTESTCOMPILE)tsqrt.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tsqrt.exe && cd ..
+ $(TESTCOMPILE)tstrtoc.c $(MIDTESTCOMPILE)tstrtoc.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tstrtoc.exe && cd ..
+ $(TESTCOMPILE)tsub.c $(MIDTESTCOMPILE)tsub.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tsub.exe && cd ..
+ $(TESTCOMPILE)tsub_fr.c $(MIDTESTCOMPILE)tsub_fr.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tsub_fr.exe && cd ..
+ $(TESTCOMPILE)tsub_ui.c $(MIDTESTCOMPILE)tsub_ui.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tsub_ui.exe && cd ..
+ $(TESTCOMPILE)tswap.c $(MIDTESTCOMPILE)tswap.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tswap.exe && cd ..
+ $(TESTCOMPILE)ttan.c $(MIDTESTCOMPILE)ttan.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && ttan.exe && cd ..
+ $(TESTCOMPILE)ttanh.c $(MIDTESTCOMPILE)ttanh.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && ttanh.exe && cd ..
+ $(TESTCOMPILE)tui_div.c $(MIDTESTCOMPILE)tui_div.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tui_div.exe && cd ..
+ $(TESTCOMPILE)tui_ui_sub.c $(MIDTESTCOMPILE)tui_ui_sub.exe $(ENDTESTCOMPILE)
+ cd $(DIRMPCTESTS) && tui_ui_sub.exe && cd ..
@echo --------------------------------------------------
@echo All tests passed
@echo --------------------------------------------------
diff --git a/NEWS b/NEWS
index b42b190..641cd6d 100644
--- a/NEWS
+++ b/NEWS
@@ -1,20 +1,34 @@
+Recent changes in the trunk:
+ - Minimally required library version: mpfr 3.0.0
+
+Changes in version 1.0.1:
+ - Switched to automake 1.11.6, see
+ https://lists.gnu.org/archive/html/automake/2012-07/msg00023.html
+ - #14669: Fixed extraction of CC from gmp.h
+ - Fixed case of intermediate zero real or imaginary part in mpc_fma,
+ found by hydra with GMP_CHECK_RANDOMIZE=1346362345
+
Changes in version 1.0:
- First release as a GNU package
- - License change: LGPLv3+ for code, GFDLv1.3+ for documentation
- - 0^0, which returned (NaN,NaN) previously, now returns (1,+0).
- - removed compatibility with K&R compilers, untestable due to lack of
+ - License change: LGPLv3+ for code, GFDLv1.3+ (with no invariant sections)
+ for documentation
+ - 100% of all lines are covered by tests
+ - Functions renamed:
+ mpc_mul_2exp to mpc_mul_2ui, mpc_div_2exp to mpc_div_2ui
+ - 0^0, which returned (NaN,NaN) previously, now returns (1,+0)
+ - Removed compatibility with K&R compilers, untestable due to lack of
such compilers
- - New function mpc_log10.
- - Optimisation:
- - fma
+ - New functions: mpc_log10, mpc_mul_2si, mpc_div_2si
+ - Speed-ups:
+ - mpc_fma
- Bug fixes:
- - div and norm now return a value indicating the effective rounding
- direction, as the other functions.
- - mul, sqr and norm now return correct results even if there are over-
- or underflows during the computation
- - asin, proj, sqr: Wrong result when input variable has infinite part and
- equals output variable is corrected.
- - fr_sub: Wrong return value for imaginary part.
+ - mpc_div and mpc_norm now return a value indicating the effective
+ rounding direction, as the other functions
+ - mpc_mul, mpc_sqr and mpc_norm now return correct results even if there
+ are over- or underflows during the computation
+ - mpc_asin, mpc_proj, mpc_sqr: Wrong result when input variable has
+ infinite part and equals output variable is corrected
+ - mpc_fr_sub: Wrong return value for imaginary part is corrected
Changes in version 0.9:
- New functions:
@@ -27,11 +41,12 @@ Changes in version 0.9:
- mpc_pow_z when the exponent fits in a long
- mpc_tan through the use of mpc_sin_cos
- Bug fixes:
- - trigonometric functions: infinite loop due to overflow for large arguments
- - exp: close to infinite loop for argument close to 0
- - sqrt: close to infinite loop for argument close to 1
- - add_si: replaced macro by function, since the macro evaluated the same
- expression twice
+ - trigonometric functions: infinite loop due to overflow for large
+ arguments
+ - mpc_exp: close to infinite loop for argument close to 0
+ - mpc_sqrt: close to infinite loop for argument close to 1
+ - mpc_add_si: replaced macro by function, since the macro evaluated the
+ same expression twice
- Logging feature for debugging:
./configure --enable-logging
#include "mpc-log.h" instead of #include "mpc.h"
@@ -42,24 +57,25 @@ Changes in version 0.8.2:
Changes in version 0.8.1:
- Bug fixes:
- - acosh, asinh, atanh: swap of precisions between real and imaginary parts
- - atan: memory leak
- - log: wrong ternary value in data file; masked by bug in mpfr-2.4.1
+ - mpc_acosh, mpc_asinh, mpc_atanh: swap of precisions between real and
+ imaginary parts
+ - mpc_atan: memory leak
+ - mpc_log: wrong ternary value in data file; masked by bug in mpfr-2.4.1
Changes in version 0.8 ("Dianthus deltoides"):
- New functions:
- mpc_asin, mpc_acos, mpc_atan, mpc_asinh, mpc_acosh, mpc_atanh,
mpc_pow_d, mpc_pow_ld, mpc_pow_si, mpc_pow_ui, mpc_pow_z, mpc_pow_fr
- Bug fixes:
- - ui_div: real divisor
+ - mpc_ui_div: real divisor
Changes in version 0.7 ("Campanula uniflora"):
- New functions: mpc_pow, mpc_set_nan, mpc_swap
- Bug fixes:
- - log: along branch cut
- - norm: infinite loop in case of overflow
- - ui_div, div, fr_div: handling of division by 0 and infinities
- following the example code of the C99 standard
+ - mpc_log: along branch cut
+ - mpc_norm: infinite loop in case of overflow
+ - mpc_ui_div, mpc_div, mpc_fr_div: handling of division by 0 and
+ infinities following the example code of the C99 standard
- compilation with g++
- Makefile.vc updated (thanks to Mickael Gastineau)
- Minimal gmp version is 4.2
@@ -73,10 +89,10 @@ Changes in version 0.6 ("Bellis perennis"):
mpc_set_z_z and mpc_free_str
- New macro: MPC_SET_X_Y
- mpc_set_ui_fr removed
- - Default precision removed, as well as init and all init_set
- combinations; use init2 and init3, followed by set, instead
- - exp, log, cos, sin, tan, cosh, sinh, tanh and sqrt return
- inexact value
+ - Default precision removed, as well as mpc_init and all mpc_init_set*
+ combinations; use mpc_init2 or mpc_init3, followed by mpc_set, instead
+ - mpc_exp, mpc_log, mpc_cos, mpc_sin, mpc_tan, mpc_cosh, mpc_sinh,
+ mpc_tanh and mpc_sqrt return inexact value
- inp_str returns inexact value and the number of read characters
in an additional parameter
- Get default $CC and $CFLAGS from gmp.h (__GMP_CC / __GMP_CFLAGS,
@@ -109,20 +125,22 @@ Changes in version 0.5.1:
- Export declarations for MSWindows, makefile.vc updated (thanks to
Mickael Gastineau)
- Optimisations:
- - mul_fr, sin, cos
+ - cmp_mul_fr, cmp_sin, cmp_cos
- Bug fixes:
- configure looks for gmp first, then for mpfr
- - cos, div, div_fr, fr_sub, mul_fr, set_fr, sqr
- - fix handling of special values: exp, log, mul, norm, sqr, sqrt
+ - mpc_cos, mpc_div, mpc_div_fr, mpc_fr_sub, mpc_mul_fr, mpc_set_fr,
+ mpc_sqr
+ - fix handling of special values: mpc_exp, mpc_log, mpc_mul, mpc_norm,
+ mpc_sqr, mpc_sqrt
Changes in version 0.5 ("Aconitum neomontanum"):
- Support for autotools
- New functions:
- logarithm
- - trigonometric functions: cos, tan
- - hyperbolic functions: cosh, sinh, tanh
+ - trigonometric functions: mpc_cos, mpc_tan
+ - hyperbolic functions: mpc_cosh, mpc_sinh, mpc_tanh
- Bug fixes:
- - sqrt with directed rounding
+ - mpc_sqrt with directed rounding
Copyright (C) 2008, 2009, 2010, 2011, 2012 INRIA
diff --git a/README.dev b/README.dev
index a809e87..d1a4859 100644
--- a/README.dev
+++ b/README.dev
@@ -8,31 +8,29 @@ $ autoreconf -i
Required versions:
* autoconf >= 2.61
-* automake >= 1.10.1
+* automake >= 1.11.6
* libtool >= 2.2
Creating a new release
----------------------
- 1) Check compilation with latest gmp and mpfr, with gmp 4.3.2 and mpfr 2.4.2;
- with and without "--enable-valgrind-tests --disable-shared".
- 2) Check the version number in configure.ac ("AC_INIT (mpc, _version_...)"),
- INSTALL, src/get_version.c, src/mpc.h (remove suffix "dev" in
- MPC_VERSION_STRING) and Makefile.vc.
- 3) Verify that the API version in src/Makefile.am is correct.
- 4) Check that NEWS, BUGS and TODO are up to date, and that the minimal
- version numbers of gmp and mpfr in configure.ac, INSTALL and
- doc/mpc.texi are correct.
- 5) Execute "autoreconf; touch doc/mpc.texi; make distcheck".
- This updates the date and version number in doc/version.texi and
- creates the tarball for distribution.
- 6) Create an svn tag from inside the svn root:
- svn cp trunk tags/VERSION
- 7) Update the web page on the server.
- The html documentation is created with
- makeinfo --html --no-split mpc.texi
- and the resulting mpc.html is copied to content_html.php.
- 8) After the release, update the version number in configure.ac, INSTALL,
- src/get_version.c, src/mpc.h and Makefile.vc.
- 9) Potentially increase the API version in src/Makefile.am.
-10) Commit the changes to svn.
+1) Check the version number in configure.ac ("AC_INIT (mpc, _version_...)"),
+ INSTALL, src/get_version.c, src/mpc.h (remove suffix "dev" in
+ MPC_VERSION_STRING) and Makefile.vc.
+2) Verify that the ABI version in src/Makefile.am is correct.
+3) Check that NEWS, BUGS and TODO are up to date, and that the minimal
+ version numbers of gmp and mpfr in configure.ac, INSTALL and
+ doc/mpc.texi are correct.
+4) Execute "autoreconf; touch doc/mpc.texi; make distcheck".
+ This updates the date and version number in doc/version.texi and
+ creates the tarball for distribution.
+5) Upload to GNU ftp server.
+6) Update the web page on the server.
+ The html documentation is created with
+ makeinfo --html --no-split mpc.texi
+ and the resulting mpc.html is copied to content_html.php.
+7) Create an svn tag from inside the svn root:
+ svn cp trunk tags/VERSION
+8) After the release, update the version number in configure.ac, INSTALL,
+ src/get_version.c, src/mpc.h and Makefile.vc.
+9) Commit the changes to svn.
diff --git a/TODO b/TODO
index 900a728..1b10204 100644
--- a/TODO
+++ b/TODO
@@ -1,13 +1,23 @@
+From Andreas Enge 27 August 2012:
+Implement im(atan(x+i*y)) as
+1/4 * [log1p (4y / (x^2 +(1-y)^2))]
+(see http://lists.gforge.inria.fr/pipermail/mpc-discuss/2012-August/001196.html)
+
+From Andreas Enge 23 July 2012:
+go through tests and move them to the data files if possible
+(see, for instance, tcos.c)
+
From Andreas Enge 31 August 2011:
implement mul_karatsuba with three multiplications at precision around p,
instead of two at precision 2*p and one at precision p
requires analysis of error propagation
-From Andreas Enge 30 August 2011:
-As soon as dependent on mpfr>=3, remove auxiliary functions from
-get_version.c and update mpc.h.
-Use MPFR_RND? instead of GMP_RND?, and remove workarounds for MPFR_RNDA from
-mpc-impl.h.
+From Andreas Enge 05 July 2012:
+Add support for rounding mode MPFR_RNDA.
+
+From Andreas Enge and Paul Zimmermann 6 July 2012:
+Improve speed of Im (atan) for x+i*y with small y, for instance by using
+the Taylor series directly.
Bench:
- from Andreas Enge 9 June 2009:
@@ -19,13 +29,19 @@ New functions to implement:
mpc_erfc, mpc_exp2, mpc_expm1, mpc_log1p, mpc_log2, mpc_lgamma, mpc_tgamma
http://lists.gforge.inria.fr/pipermail/mpc-discuss/2012-March/001090.html
- from Andreas Enge and Philippe Théveny 17 July 2008
- agm (and complex logarithm with agm ?)
+ agm (and complex logarithm with agm ?). For the error analysis, one can
+ start from Theorem 1 of http://www.lix.polytechnique.fr/Labo/Regis.Dupont/preprints/Dupont_FastEvalMod.ps.gz, and probably the best is to compute AGM(a,b)
+ as a*AGM(1,b/a) with |b/a| <= 1. In such a way, after one step all values
+ are in the same quadrant, and no cancellation occurs any more.
- from Andreas Enge 25 June 2009:
correctly rounded roots of unity zeta_n^i
- implement a root-finding algorithm using the Durand-Kerner method
- (cf http://en.wikipedia.org/wiki/Durand%E2%80%93Kerner_method)
+ (cf http://en.wikipedia.org/wiki/Durand%E2%80%93Kerner_method).
See also the CEVAL algorithm from Yap and Sagraloff:
http://www.mpi-inf.mpg.de/~msagralo/ceval.pdf
+ A good starting point for the Durand-Kerner and Aberth methods is the
+ paper by Dario Bini "Numerical computation of polynomial zeros by means of
+ Aberth's method", Numerical Algorithms 13 (1996), 179-200.
New tests to add:
- from Andreas Enge and Philippe Théveny 9 April 2008
diff --git a/configure.ac b/configure.ac
index 907a168..39f8891 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,7 +20,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.61)
-AC_INIT(mpc, 1.0.0dev, mpc-discuss@lists.gforge.inria.fr)
+AC_INIT(mpc, 1.1dev, mpc-discuss@lists.gforge.inria.fr)
AC_CONFIG_SRCDIR([src/mpc-impl.h])
AC_CONFIG_HEADER([config.h])
@@ -30,9 +30,6 @@ AM_MAINTAINER_MODE
USER_CC=$CC
USER_CFLAGS=$CFLAGS
-# automake 1.12 seems to require this, but automake 1.11 doesn't recognize it
-m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
-
AC_CANONICAL_HOST
AC_CONFIG_MACRO_DIR([m4])
@@ -111,6 +108,9 @@ fi
AC_PROG_CC
AC_LANG(C)
+# automake 1.12 seems to require this, but automake 1.11 doesn't recognize it
+m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
+
# Set up LibTool
LT_INIT
@@ -123,11 +123,12 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
AC_MSG_ERROR([gmp.h cannot be found or is unusable.])
])
-# Check if compiler accepts warning flags and add them to CFLAGS
+# Check (only in development versions) if the compiler accepts warning
+# flags and add them to CFLAGS
# Note: don't do this if the user defined CFLAGS, since adding new flags
# might override the user's settings, see
# http://lists.gforge.inria.fr/pipermail/mpc-discuss/2012-May/001115.html
-if test -z "$CFLAGS"; then
+if test -z "$USER_CFLAGS"; then
MPC_C_CHECK_WARNINGCFLAGS
fi
@@ -186,23 +187,22 @@ error
AC_MSG_ERROR([GMP version >= 4.3.2 required])
])
-# Check for a recent MPFR: we require MPFR 2.4.2 so that the tests
-# in log.dat pass
+# Check for a recent MPFR: we require MPFR 3.0.0 for MPC_RNDA
# The same remark as above for GMP applies.
AC_MSG_CHECKING(for recent MPFR)
AC_COMPILE_IFELSE(
[AC_LANG_SOURCE(
[[
#include "mpfr.h"
-#if (MPFR_VERSION < MPFR_VERSION_NUM (2,4,2))
-# error "Minimal MPFR version is 2.4.2"
+#if (MPFR_VERSION < MPFR_VERSION_NUM (3,0,0))
+# error "Minimal MPFR version is 3.0.0"
error
#endif
]])],
[AC_MSG_RESULT(yes)],
[
AC_MSG_RESULT(no)
- AC_MSG_ERROR([MPFR version >= 2.4.2 required])
+ AC_MSG_ERROR([MPFR version >= 3.0.0 required])
])
# Check for logging feature
diff --git a/doc/algorithms.bib b/doc/algorithms.bib
index 50bcaeb..2232a0e 100644
--- a/doc/algorithms.bib
+++ b/doc/algorithms.bib
@@ -1,3 +1,13 @@
+@phdthesis {Dupont06,
+ author = {R\'egis Dupont},
+ title = {Moyenne arithm\'etico-g\'eom\'etrique, suites de
+ {B}orchardt et applications},
+ school = {\'Ecole polytechnique},
+ address = {Palaiseau},
+ type = {Th\`ese de doctorat},
+ year = {2006}
+}
+
@Article{Friedland67,
author = {Paul Friedland},
title = {Algorithm 312: {A}bsolute value and square root of a complex
@@ -10,6 +20,12 @@
annote = "\url{http://portal.acm.org/citation.cfm?id=363780}"
}
+@Unpublished{MPFRAlgorithms,
+ author = {{MPFR Team}},
+ title = {The {MPFR} {L}ibrary: {A}lgorithms {A}nd {P}roofs},
+ note = {\url{http://www.mpfr.org/algorithms.pdf}},
+}
+
@Article{Smith98,
author = {David M. Smith},
title = {Algorithm 786: {M}ultiple-Precision Complex Arithmetic and
@@ -20,33 +36,3 @@
number = 4,
pages = {359--367}
}
-
-@Book{BrDiJeLeMeMuReStTo09,
- author = {Nicolas Brisebarre and Florent de Dinechin and
- Claude-Pierre Jeannerod and Vincent Lef\`evre and
- Guillaume Melquiond and Jean-Michel Muller and Nathalie
- Revol and Damien Stehl\'e and Serge Torres},
- title = {Handbook of Floating-Point Arithmetic},
- publisher = {Birkh\"auser},
- year = 2009,
- note = {571 pages}
-}
-
-@Unpublished{MPFRAlgorithms,
- author = {{MPFR Team}},
- title = {The {MPFR} {L}ibrary: {A}lgorithms {A}nd {P}roofs},
- note = {\url{http://www.mpfr.org/algorithms.pdf}},
-}
-
-@Article{Percival03,
- author = "Colin Percival",
- title = "Rapid multiplication modulo the sum and difference of
- highly composite numbers",
- journal = MC,
- year = 2003,
- volume = 72,
- number = 241,
- pages = "387--395",
- comment = "Includes good error analysis for FFT but proof is
- incorrect (result is OK)"
-}
diff --git a/doc/algorithms.tex b/doc/algorithms.tex
index 790eca1..810d06d 100644
--- a/doc/algorithms.tex
+++ b/doc/algorithms.tex
@@ -3,6 +3,7 @@
\usepackage[a4paper]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
+\usepackage{ae}
\usepackage{amsmath,amssymb}
\usepackage{hyperref}
\usepackage{comment}
@@ -31,6 +32,7 @@
\renewcommand {\theta}{\vartheta}
\renewcommand {\leq}{\leqslant}
\renewcommand {\geq}{\geqslant}
+\newcommand {\AGM}{\operatorname{AGM}}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
@@ -46,7 +48,7 @@
\title {MPC: Algorithms and Error Analysis}
\author {Andreas Enge \and Philippe Th\'eveny \and Paul Zimmermann}
-\date {Draft; June 27, 2012}
+\date {Draft; September 18, 2012}
\begin {document}
\maketitle
@@ -338,6 +340,50 @@ For the converse direction, write
\]
\end {proof}
+As a corollary to Propositions~\ref {prop:relerror}
+and~\ref {prop:comrelerror}, we obtain the following result that shows how
+to transform absolute into complex relative errors.
+
+\begin {prop}
+\label {prop:comabstorelerror}
+Let $\appro z = \appro x + i \appro y$ be representable at precision~$p$.
+If
+$\error (\appro x) \leq k \, \Ulp (\appro x)$ and
+$\error (\appro y) \leq k \, \Ulp (\appro y)$, then
+\[
+\relerror (\appro z) \leq k \, 2^{1-p}.
+\]
+As in Proposition~\ref {prop:relerror}, there is an immediate generalisation
+if $\appro z$ is not representable at precision~$p$.
+\end {prop}
+
+This result can be used to analyse how rounding affects complex
+relative errors.
+
+\begin {prop}
+\label {prop:comrelround}
+Let $\relerror (\appro z) = \epsilon$.
+Then
+\[
+\relerror (\round (\appro z)) \leq
+\epsilon + c (1 + \epsilon) 2^{1-p},
+\]
+where $c = \frac {1}{2}$ if both the real and the imaginary part are
+rounded to nearest, and $c = 1$ otherwise.
+\end {prop}
+
+\begin {proof}
+Write $\corr z = (1 + \theta) \appro z$ with $|\theta| = \epsilon$.
+Applying Proposition~\ref {prop:comabstorelerror} with $\appro z$ in the
+place of $\corr z$, $\round (\appro z)$ in the place of $\appro z$
+and $c$ in the place of~$k$,
+there is a $\theta'$ with $\appro z = (1 + \theta') \round (\appro z)$
+and $|\theta'| \leq c \, 2^{1-p}$.
+So $\corr z = (1 + \theta'') \round (\appro z)$ with
+$\theta'' = (1 + \theta)(1 + \theta') - 1
+= \theta + \theta' (1 + \theta)$.
+\end {proof}
+
\subsection {Real functions}
@@ -454,6 +500,37 @@ For the sine function, a completely analogous argument shows that
\eqref {eq:proprealcos} also holds.
+\subsubsection {Logarithm}
+\label {sssec:propreallog}
+
+Let
+\[
+\appro x = \log (1 + \appro {x_1})
+\]
+for $\appro {x_1} > -1$.
+By the mean value theorem, there is a $\xi$ between $x_1$ and $\appro {x_1}$
+such that
+\[
+\error (\appro x) = \frac {1}{1 + \xi} \error (\appro {x_1})
+\leq \frac {1}{1 + \min (x_1, \appro {x_1})} \error (\appro {x_1}).
+\]
+For $x_1 > 0$, this implies
+\begin {eqnarray*}
+\error (\appro x)
+& \leq & \error (\appro {x_1})
+\leq
+k \, 2^{\Exp (\appro {x_1}) - \Exp (\appro x)}
+\, 2^{\Exp (\appro x) - p} \\
+& \leq & 2 \, k \, \frac {\appro {x_1}}{\appro x} \, 2^{\Exp (\appro x) - p} \\
+& \leq & 2 \, k \, \frac {\appro {x_1}}{\appro {x_1} - \appro {x_1}^2/2}
+\, 2^{\Exp (\appro x) - p}
+\end {eqnarray*}
+using $\log (1 + z) \geq z - z^2/2$ for $z > 0$.
+For $0 < x_1 \leq 1$, we have $\appro {x_1}^2/2 \leq \appro {x_1}/2$ and
+\[
+\error (\appro x)
+\leq 4 \, k \, 2^{\Exp (\appro x) - p}.
+\]
\subsection {Complex functions}
@@ -485,7 +562,7 @@ exponent than the operands, that is, if cancellation occurs.
If $\appro {x_1}$ and $\appro {x_2}$, have the same sign, then there
is no cancellation, $d_{R, n} \leq 0$ and
\[
-\error (\appro x) \leq (k_{R,1} + k_{R,2} + c_R) 2^{\Exp (\appro x) - p}.
+\error (\appro x) \leq (k_{R,1} + k_{R,2}) 2^{\Exp (\appro x) - p}.
\]
An analogous error bound holds for the imaginary part.
@@ -494,6 +571,51 @@ For subtraction, the same bounds are obtained, except that the simpler bound
now holds whenever $\appro {x_1}$ and $\appro {x_2}$ resp.
$\appro {y_1}$ and $\appro {y_2}$ have different signs.
+We obtain a useful result for complex relative errors when $z_1$ and $z_2$
+lie in the same quadrant, so that cancellation occurs neither for the real
+nor for the imaginary part.
+
+\begin {lemma}
+\label {lm:arithgeom}
+Let $c_1 = a_1 + i b_1$ and $c_2 = a_2 + i b_2$ lie in the same quadrant,
+that is, $a_1 a_2$, $b_1 b_2 \geq 0$. Then
+\[
+|c_1| + |c_2| \leq \sqrt 2 \cdot |c_1 + c_2|.
+\]
+\end {lemma}
+
+\begin {proof}
+One readily verifies that
+\[
+2 |c_1 + c_2|^2 - (|c_1| + |c_2|)^2
+= (|c_1| - |c_2|)^2 + 4 (a_1 a_2 + b_1 b_2)
+\geq 0
+\]
+\end {proof}
+
+Assume now that $\corr {z_n} = (1 + \theta_n) \appro {z_n}$
+with $\epsilon_n = |\theta_n|$ lie in the same quadrant.
+Then
+$\corr z = (1 + \theta) \appro z$
+with
+\[
+\theta = \frac {\theta_1 \appro {z_1} + \theta_2 \appro {z_2}}
+ {\appro {z_1} + \appro {z_2}}.
+\]
+and
+\begin {equation}
+\label {eq:propaddrel}
+\relerror (\appro z)
+\leq
+\max (\epsilon_1, \epsilon_2)
+ \frac {|\appro {z_1}| + |\appro {z_2}|}{|\appro {z_1} + \appro {z_2}|}
+\leq
+\sqrt 2 \, \max (\epsilon_1, \epsilon_2)
+\end {equation}
+by Lemma~\ref {lm:arithgeom}.
+
+
+
\subsubsection {Multiplication}
\label {sssec:propmul}
@@ -636,7 +758,11 @@ A coarser bound may be obtained more easily by considering complex
relative errors. Write $\corr {z_n} = (1 + \theta_n) \appro {z_n}$
with $\epsilon_n = | \theta_n |$. Then $\corr z = (1 + \theta) \appro z$
with $\theta = \theta_1 + \theta_2 + \theta_1 \theta_2$ and
-$\epsilon = |\theta| \leq \epsilon_1 + \epsilon_2 + \epsilon_1 \epsilon_2$.
+\begin {equation}
+\label {eq:propmulrel}
+\epsilon = \relerror (\appro z)
+\leq \epsilon_1 + \epsilon_2 + \epsilon_1 \epsilon_2.
+\end {equation}
By Proposition~\ref {prop:relerror},
we have $\epsilon_{X, n} \leq k_{X, n} 2^{1-p}$ for $X \in \{ R, I \}$,
and by Proposition~\ref {prop:comrelerror},
@@ -875,6 +1001,39 @@ we find the exact same error estimate \eqref {eq:propmulcomrel}
also for the case of division.
+\subsubsection {Square root}
+Let
+\[
+\appro z = \sqrt {\appro {z_1}}.
+\]
+Write $\corr {z_1} = (1 + \theta_1) \appro {z_1}$ with
+$\epsilon_1 = |\theta_1|$, and assume $\epsilon_1 < 1$.
+Then $\corr z = (1 + \theta) \appro z$ with
+\[
+\theta = \sqrt {1 + \theta_1} - 1
+= \frac {1}{2} \theta_1
++ \sum_{n=2}^\infty \frac {(-1)^{n+1} 1 \cdot 3 \cdots (2 n - 3)}{2^n \, n!}
+ \theta_1^n
+\]
+as a Taylor series, and
+\[
+\epsilon = |\theta|
+\leq
+\frac {1}{2} \epsilon_1
++ \sum_{n=2}^\infty \frac {1 \cdot 3 \cdots (2 n - 3)}{2^n \, n!}
+\epsilon_1^n
+= 1 - \sqrt {1 - \epsilon_1}.
+\]
+By the mean value theorem, applied to the function $f (x) = \sqrt {1 - x}$,
+there is $0 < \xi < \epsilon_1$ with
+\begin {equation}
+\label {eq:propsqrt}
+\epsilon = \frac {1}{2 \sqrt {1 - \xi}} \, \epsilon_1
+\leq \frac {1}{2 \sqrt {1 - \epsilon_1}} \, \epsilon_1.
+\end {equation}
+For instance $\epsilon \leq \epsilon_1$ for $\epsilon_1 \leq \frac {3}{4}$.
+
+
\subsubsection {Logarithm}
@@ -1730,6 +1889,149 @@ Thus, assuming that $n 2^{-p} \leq 1$, the error estimates
\eqref {eq:powui_re} and \eqref {eq:powui_im} are valid with $n$
in the place of $n - 1$.
+\subsection{\texttt {mpc\_agm1}}
+
+Let
+\[
+z = \AGM (1, z_1);
+\]
+for the time being, we assume $\Re (z_1) \geq 0$ and $\Im (z_1) > 0$.
+
+Let $\corr {a_0} = \appro {a_0} = 1$,
+$\corr {b_0} = \appro {b_0} = z_1$, and let
+$\corr {a_n} = \frac {\corr {a_{n-1}} + \corr {b_{n-1}}}{2}$ and
+$\corr {b_n} = \sqrt {\corr {a_{n-1}} \corr {b_{n-1}}}$
+be the values of the AGM iteration performed with infinite precision and
+$\appro {a_n}, \appro {b_n}$ those performed with $p$-bit precision
+and some fixed rounding mode; let $c = \frac {1}{2}$ if this rounding mode
+is to nearest, $c = 1$ otherwise.
+Let $\eta_n = \relerror (\appro {a_n})$ and
+$\epsilon_n = \relerror (\appro {b_n})$.
+
+Let $c_n = \frac {\appro {a_{n-1}} + \appro {b_{n-1}}}{2}$, so that
+$\appro {a_n} = \round(c_n)$. By \eqref {eq:propaddrel}, the error of
+$c_n$ (relative to the correct value $a_n$) is bounded above by
+$\sqrt 2 \, \max (\epsilon_{n-1}, \eta_{n-1})$, division by~$2$ being exact.
+After rounding, we obtain
+\begin {equation}
+\label {eq:agmeta}
+\eta_n \leq
+\sqrt 2 \, \max (\eta_{n-1}, \epsilon_{n-1})
++ c \left( 1 + \sqrt 2 \, \max (\eta_{n-1}, \epsilon_{n-1}) \right) 2^{1-p}
+\end {equation}
+by Proposition~\ref {prop:comrelround}.
+
+Let $d_n = \round \left( \appro {a_{n-1}} \appro {b_{n-1}} \right)$.
+Then by \eqref {eq:propmulrel} and Proposition~\ref {prop:comrelround},
+the error of $d_n$ (relative to $a_{n-1} b_{n-1}$) is bounded above by
+\begin {equation}
+\label {eq:agmzeta}
+\zeta_n =
+\eta_{n-1} + \epsilon_{n-1} + \eta_{n-1} \epsilon_{n-1}
++ c (1 + \eta_{n-1} + \epsilon_{n-1} + \eta_{n-1} \epsilon_{n-1}) 2^{1-p}.
+\end {equation}
+Now $\appro {b_n} = \round (\sqrt {d_n})$, and by \eqref {eq:propsqrt}
+and Proposition~\ref {prop:comrelround},
+assuming $\zeta_n \leq \frac {3}{4}$,
+we obtain
+\begin {equation}
+\label {eq:agmepsilon}
+\epsilon_n \leq
+\zeta_n + c (1 + \zeta_n) 2^{1-p}.
+\end {equation}
+
+Let $r_n = (2^n - 1) d$ for some $d > 2 c$. Then for a sufficiently high
+precision~$p$ and not too many steps~$n$ compared to~$p$, we have
+$\eta_n, \epsilon_n \leq r_n 2^{1-p}$.
+For instance, $c=1$ and $d=4$ is compatible with any rounding mode, and
+we show
+$\eta_n, \epsilon_n \leq r_n 2^{1-p} \leq 2^{n + 3 -p}$
+by induction over \eqref {eq:agmeta}, \eqref {eq:agmzeta}
+and~\eqref {eq:agmepsilon}. For $n = 0$, we have $\eta_0 = \epsilon_0 = 0$.
+Inductively, by \eqref {eq:agmzeta} we obtain
+\[
+\frac {\zeta_n}{2^{1-p}} \leq
+2 r_{n-1} + 1 +
+\left( r_{n-1}^2 + 2 r_{n-1} + r_{n-1}^2 2^{1-p} \right) 2^{1-p}
+\leq
+r_n - 3 + 2^{2n+4-p}
+\leq
+r_n - 2
+\]
+as long as $2n+4 \leq p$. Then by \eqref {eq:agmepsilon},
+\[
+\frac {\epsilon_n}{2^{1-p}} \leq
+r_n - 1 + r_n 2^{1-p}
+\leq
+r_n - 1 + 2^{n+3-p}
+\leq r_n
+\]
+under a milder than the previous condition. Finally by \eqref {eq:agmeta},
+\[
+\frac {\eta_n}{2^{1-p}} \leq
+\sqrt 2 \, r_{n-1} + 1 + \sqrt {2} \, r_{n-1} 2^{1-p}
+\leq r_n
+\]
+under an even less restrictive condition.
+
+To summarise, we have
+\begin {equation}
+\label {eq:propagm}
+\corr {a_n} = (1 + \theta_1) \appro {a_n}
+\text { with }
+|\theta_1| \leq 2^{n + 3 - p}
+\text { for }
+2n+4 \leq p.
+\end {equation}
+
+We now use \cite[Prop.~3.3]{Dupont06}, which states that for
+$z_1 \neq 0, 1$,
+\[
+n \geq B (N, z_1)
+ = \max \left( 1, \left\lceil \log_2 |\log_2 |z_1|| \right\rceil \right)
+ + \lceil \log_2 (N+4) \rceil + 2
+\]
+(where $\log_2 0$ is to be understood as $- \infty$),
+we have
+\[
+a_n = (1 + \theta_2) z
+\text { with }
+|\theta_2| \leq 2^{-(N+2)}.
+\]
+So taking $\appro z = \appro {a_n}$ as an approximation for $z$, we obtain
+$z = \frac {1 + \theta_1}{1 + \theta_2} \appro z
+= (1 + \theta) \appro z$ with
+\[
+|\theta| \leq \frac {|\theta_1| + |\theta_2|}{|1 - |\theta_2||}
+\leq 2 \left( 2^{n+3-p} + 2^{-(N+2)} \right)
+\]
+(see the computation at the end of \S\ref {sssec:propdiv}).
+
+So after $n = B (N, z_1)$ steps of the AGM iteration at a working precision
+of $p = N + n + 5$, we obtain $\appro z = \appro {a_n}$ with a relative error
+bounded by $2^{-N}$.
+
+Using Propositions~\ref {prop:comrelerror} and~\ref {prop:relerror}, this
+complex relative error may be translated into an error expressed in $\Ulp$.
+With $\appro {z} = \appro x + i \appro y$, let
+$k_R = \max (\Exp (\appro y) - \Exp (\appro x) + 1, 0) + 1$,
+$k_I = \max (\Exp (\appro x) - \Exp (\appro y) + 1, 0) + 1$ and
+$k = \max (k_R, k_I)$.
+Then we have
+$\error (\appro x) \leq 2^{k_R - N + p} \Ulp (\appro x)$ and
+$\error (\appro y) \leq 2^{k_I - N + p} \Ulp (\appro y)$.
+
+In practice, one should take this additional loss into account: In a first
+loop, one may use an arbitrary guess for~$k$; if rounding fails after the
+first computation, one has nevertheless obtained the correct value of~$k$.
+Then after $n = B (N + k, z_1)$ steps of the AGM iteration at a working
+precision of $p = N + k + n + 5$, one has
+$\error (\appro x)
+\leq 2^{p - N - (k - k_R)} \Ulp (\appro x) \leq 2^{p - N} \Ulp (\appro x)$
+and
+$\error (\appro y)
+\leq 2^{p - N - (k - k_I)} \Ulp (\appro y) \leq 2^{p - N} \Ulp (\appro y)$.
+
\bibliographystyle{acm}
diff --git a/doc/mpc.texi b/doc/mpc.texi
index e38fedf..33f1b03 100644
--- a/doc/mpc.texi
+++ b/doc/mpc.texi
@@ -5,7 +5,7 @@
@synindex tp fn
@set MINGMP 4.3.2
-@set MINMPFR 2.4.2
+@set MINMPFR 3.0.0
@set AUTHORS Andreas Enge, Philippe Th@'eveny, Paul Zimmermann
@@ -13,7 +13,7 @@
This manual is for GNU MPC, a library for multiple precision complex arithmetic,
version @value{VERSION} of @value{UPDATED-MONTH}.
-Copyright @copyright{} 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 INRIA
+Copyright @copyright{} 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 INRIA
@quotation
Permission is granted to copy, distribute and/or modify this document
@@ -912,16 +912,18 @@ Set the floating-point number @var{rop} to the norm of @var{op}
rounded in the direction @var{rnd}.
@end deftypefun
-@deftypefun int mpc_mul_2exp (mpc_t @var{rop}, mpc_t @var{op1}, unsigned long int @var{op2}, mpc_rnd_t @var{rnd})
+@deftypefun int mpc_mul_2ui (mpc_t @var{rop}, mpc_t @var{op1}, unsigned long int @var{op2}, mpc_rnd_t @var{rnd})
+@deftypefunx int mpc_mul_2si (mpc_t @var{rop}, mpc_t @var{op1}, long int @var{op2}, mpc_rnd_t @var{rnd})
Set @var{rop} to @var{op1} times 2 raised to @var{op2}
-rounded according to @var{rnd}. Just increases the exponents
+rounded according to @var{rnd}. Just modifies the exponents
of the real and imaginary parts by @var{op2}
when @var{rop} and @var{op1} are identical.
@end deftypefun
-@deftypefun int mpc_div_2exp (mpc_t @var{rop}, mpc_t @var{op1}, unsigned long int @var{op2}, mpc_rnd_t @var{rnd})
+@deftypefun int mpc_div_2ui (mpc_t @var{rop}, mpc_t @var{op1}, unsigned long int @var{op2}, mpc_rnd_t @var{rnd})
+@deftypefunx int mpc_div_2si (mpc_t @var{rop}, mpc_t @var{op1}, long int @var{op2}, mpc_rnd_t @var{rnd})
Set @var{rop} to @var{op1} divided by 2 raised to @var{op2}
-rounded according to @var{rnd}. Just decreases the exponents
+rounded according to @var{rnd}. Just modifies the exponents
of the real and imaginary parts by @var{op2}
when @var{rop} and @var{op1} are identical.
@end deftypefun
diff --git a/doc/version.texi b/doc/version.texi
index 087e805..7184426 100644
--- a/doc/version.texi
+++ b/doc/version.texi
@@ -1,4 +1,4 @@
-@set UPDATED 10 January 2012
-@set UPDATED-MONTH January 2012
-@set EDITION 1.0.0dev
-@set VERSION 1.0.0dev
+@set UPDATED 19 July 2012
+@set UPDATED-MONTH July 2012
+@set EDITION 1.0
+@set VERSION 1.0
diff --git a/m4/mpc.m4 b/m4/mpc.m4
index 861bef9..414229b 100644
--- a/m4/mpc.m4
+++ b/m4/mpc.m4
@@ -91,6 +91,10 @@ AC_DEFUN([MPC_C_CHECK_WARNINGCFLAGS], [
AC_REQUIRE([AC_PROG_GREP])
if echo $VERSION | grep -c dev >/dev/null 2>&1 ; then
if test "x$GCC" = "xyes" -a "x$compiler" != "xicc" -a "x$compiler" != "xg++"; then
+ # enable -Werror for myself (Andreas Enge)
+ if test "x$USER" = "xenge"; then
+ MPC_C_CHECK_FLAG(-Werror)
+ fi
MPC_C_CHECK_FLAG(-g)
MPC_C_CHECK_FLAG(-std=c99)
MPC_C_CHECK_FLAG(-pedantic)
diff --git a/m4/valgrind-tests.m4 b/m4/valgrind-tests.m4
index 926d75c..e38236e 100644
--- a/m4/valgrind-tests.m4
+++ b/m4/valgrind-tests.m4
@@ -5,25 +5,29 @@ dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl From Simon Josefsson
+dnl with adaptations to MPC
# gl_VALGRIND_TESTS()
# -------------------
# Check if valgrind is available, and set VALGRIND to it if available.
AC_DEFUN([gl_VALGRIND_TESTS],
[
- AC_ARG_ENABLE(valgrind-tests,
- AS_HELP_STRING([--enable-valgrind-tests],
- [run self tests under valgrind]),
- [opt_valgrind_tests=$enableval], [opt_valgrind_tests=yes])
-
# Run self-tests under valgrind?
- if test "$opt_valgrind_tests" = "yes" && test "$cross_compiling" = no; then
+ if test "$cross_compiling" = no; then
AC_CHECK_PROGS(VALGRIND, valgrind)
fi
if test -n "$VALGRIND" && $VALGRIND -q true > /dev/null 2>&1; then
opt_valgrind_tests=yes
VALGRIND="$VALGRIND -q --error-exitcode=1 --leak-check=full"
+# Addition AE: enable suppression file through a shell variable
+ AC_MSG_CHECKING([for valgrind suppression file])
+ if test -n "$VALGRIND_SUPPRESSION"; then
+ AC_MSG_RESULT($VALGRIND_SUPPRESSION)
+ VALGRIND="$VALGRIND --suppressions=$VALGRIND_SUPPRESSION"
+ else
+ AC_MSG_RESULT([no])
+ fi
AC_DEFINE([MPC_USE_VALGRIND], 1, [Use valgrind for make check])
else
opt_valgrind_tests=no
diff --git a/src/Makefile.am b/src/Makefile.am
index a9bfa9c..c52adcc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,6 +1,6 @@
## src/Makefile.am -- Process this file with automake to produce Makefile.in
##
-## Copyright (C) 2008, 2009, 2010, 2011 INRIA
+## Copyright (C) 2008, 2009, 2010, 2011, 2012 INRIA
##
## This file is part of GNU MPC.
##
@@ -18,13 +18,14 @@
## along with this program. If not, see http://www.gnu.org/licenses/ .
lib_LTLIBRARIES = libmpc.la
-libmpc_la_LDFLAGS = $(MPC_LDFLAGS) -version-info 2:0:0
+libmpc_la_LDFLAGS = $(MPC_LDFLAGS) -version-info 3:0:0
libmpc_la_SOURCES = mpc-impl.h abs.c acos.c acosh.c add.c add_fr.c \
add_si.c add_ui.c arg.c asin.c asinh.c atan.c atanh.c clear.c cmp.c \
- cmp_si_si.c conj.c cos.c cosh.c div_2exp.c div.c div_fr.c div_ui.c exp.c \
- fma.c fr_div.c fr_sub.c get_prec2.c get_prec.c get_version.c get_x.c \
- imag.c init2.c init3.c inp_str.c log.c log10.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 pow_fr.c \
+ cmp_si_si.c conj.c cos.c cosh.c div_2si.c div_2ui.c div.c div_fr.c \
+ div_ui.c exp.c fma.c fr_div.c fr_sub.c get_prec2.c get_prec.c \
+ get_version.c get_x.c imag.c init2.c init3.c inp_str.c log.c log10.c \
+ mem.c mul_2si.c mul_2ui.c mul.c mul_fr.c mul_i.c mul_si.c mul_ui.c \
+ neg.c norm.c out_str.c pow.c pow_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 \
diff --git a/src/acos.c b/src/acos.c
index 2832125..6117786 100644
--- a/src/acos.c
+++ b/src/acos.c
@@ -1,6 +1,6 @@
/* mpc_acos -- arccosine of a complex number.
-Copyright (C) 2009, 2010, 2011 INRIA
+Copyright (C) 2009, 2010, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -67,7 +67,7 @@ mpc_acos (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
{
inex_re =
set_pi_over_2 (mpc_realref (rop), +1, MPC_RND_RE (rnd));
- mpfr_div_2ui (mpc_realref (rop), mpc_realref (rop), 1, GMP_RNDN);
+ mpfr_div_2ui (mpc_realref (rop), mpc_realref (rop), 1, MPFR_RNDN);
}
else
{
@@ -88,11 +88,11 @@ mpc_acos (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
{
p += mpc_ceil_log2 (p);
mpfr_set_prec (x, p);
- mpfr_const_pi (x, GMP_RNDD);
- mpfr_mul_ui (x, x, 3, GMP_RNDD);
+ mpfr_const_pi (x, MPFR_RNDD);
+ mpfr_mul_ui (x, x, 3, MPFR_RNDD);
ok =
- mpfr_can_round (x, p - 1, GMP_RNDD, MPC_RND_RE (rnd),
- prec+(MPC_RND_RE (rnd) == GMP_RNDN));
+ mpfr_can_round (x, p - 1, MPFR_RNDD, MPC_RND_RE (rnd),
+ prec+(MPC_RND_RE (rnd) == MPFR_RNDN));
} while (ok == 0);
inex_re =
@@ -103,7 +103,7 @@ mpc_acos (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
else
{
if (mpfr_sgn (mpc_realref (op)) > 0)
- mpfr_set_ui (mpc_realref (rop), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (rop), 0, MPFR_RNDN);
else
inex_re = mpfr_const_pi (mpc_realref (rop), MPC_RND_RE (rnd));
}
@@ -131,7 +131,7 @@ mpc_acos (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
inex_im = -mpfr_acosh (mpc_imagref (rop), mpc_realref (op),
INV_RND (MPC_RND_IM (rnd)));
- mpfr_set_ui (mpc_realref (rop), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (rop), 0, MPFR_RNDN);
}
else if (mpfr_cmp_si (mpc_realref (op), -1) < 0)
{
@@ -180,13 +180,13 @@ mpc_acos (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
/* the imaginary part of asin(z) has the same sign as Im(z), thus if
Im(z) > 0 and rnd_im = RNDZ, we want to round the Im(asin(z)) to -Inf
so that -Im(asin(z)) is rounded to zero */
- if (rnd_im == GMP_RNDZ)
- rnd_im = mpfr_sgn (mpc_imagref(op)) > 0 ? GMP_RNDD : GMP_RNDU;
+ if (rnd_im == MPFR_RNDZ)
+ rnd_im = mpfr_sgn (mpc_imagref(op)) > 0 ? MPFR_RNDD : MPFR_RNDU;
else
- rnd_im = rnd_im == GMP_RNDU ? GMP_RNDD
- : rnd_im == GMP_RNDD ? GMP_RNDU
+ rnd_im = rnd_im == MPFR_RNDU ? MPFR_RNDD
+ : rnd_im == MPFR_RNDD ? MPFR_RNDU
: rnd_im; /* both RNDZ and RNDA map to themselves for -asin(z) */
- rnd1 = RNDC(GMP_RNDN, rnd_im);
+ rnd1 = MPC_RND (MPFR_RNDN, rnd_im);
mpfr_init2 (pi_over_2, p);
for (;;)
{
@@ -195,14 +195,13 @@ mpc_acos (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
mpfr_set_prec (mpc_realref(z1), p);
mpfr_set_prec (pi_over_2, p);
- mpfr_const_pi (pi_over_2, GMP_RNDN);
- mpfr_div_2exp (pi_over_2, pi_over_2, 1, GMP_RNDN); /* Pi/2 */
+ set_pi_over_2 (pi_over_2, +1, MPFR_RNDN);
e1 = 1; /* Exp(pi_over_2) */
inex = mpc_asin (z1, op, rnd1); /* asin(z) */
MPC_ASSERT (mpfr_sgn (mpc_imagref(z1)) * mpfr_sgn (mpc_imagref(op)) > 0);
inex_im = MPC_INEX_IM(inex); /* inex_im is in {-1, 0, 1} */
e2 = mpfr_get_exp (mpc_realref(z1));
- mpfr_sub (mpc_realref(z1), pi_over_2, mpc_realref(z1), GMP_RNDN);
+ mpfr_sub (mpc_realref(z1), pi_over_2, mpc_realref(z1), MPFR_RNDN);
if (!mpfr_zero_p (mpc_realref(z1)))
{
/* the error on x=Re(z1) is bounded by 1/2 ulp(x) + 2^(e1-p-1) +
@@ -213,10 +212,10 @@ mpc_acos (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
/* the error on x is bounded by 1/2 ulp(x) [1 + 2^e1] */
e1 = e1 <= 0 ? 0 : e1;
/* the error on x is bounded by 2^e1 * ulp(x) */
- mpfr_neg (mpc_imagref(z1), mpc_imagref(z1), GMP_RNDN); /* exact */
+ mpfr_neg (mpc_imagref(z1), mpc_imagref(z1), MPFR_RNDN); /* exact */
inex_im = -inex_im;
- if (mpfr_can_round (mpc_realref(z1), p - e1, GMP_RNDN, GMP_RNDZ,
- p_re + (MPC_RND_RE(rnd) == GMP_RNDN)))
+ if (mpfr_can_round (mpc_realref(z1), p - e1, MPFR_RNDN, MPFR_RNDZ,
+ p_re + (MPC_RND_RE(rnd) == MPFR_RNDN)))
break;
}
}
diff --git a/src/acosh.c b/src/acosh.c
index a4eef4c..782f555 100644
--- a/src/acosh.c
+++ b/src/acosh.c
@@ -1,6 +1,6 @@
/* mpc_acosh -- inverse hyperbolic cosine of a complex number.
-Copyright (C) 2009, 2011 INRIA
+Copyright (C) 2009, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -46,7 +46,7 @@ mpc_acosh (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
if (mpfr_signbit (mpc_imagref (op)))
{
inex = mpc_acos (a, op,
- RNDC (INV_RND (MPC_RND_IM (rnd)), MPC_RND_RE (rnd)));
+ MPC_RND (INV_RND (MPC_RND_IM (rnd)), MPC_RND_RE (rnd)));
/* change a to -i*a, i.e., -y+i*x to x+i*y */
tmp[0] = mpc_realref (a)[0];
@@ -58,7 +58,7 @@ mpc_acosh (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
else
{
inex = mpc_acos (a, op,
- RNDC (MPC_RND_IM (rnd), INV_RND(MPC_RND_RE (rnd))));
+ MPC_RND (MPC_RND_IM (rnd), INV_RND(MPC_RND_RE (rnd))));
/* change a to i*a, i.e., y-i*x to x+i*y */
tmp[0] = mpc_realref (a)[0];
diff --git a/src/asin.c b/src/asin.c
index bd4e313..2d18489 100644
--- a/src/asin.c
+++ b/src/asin.c
@@ -1,6 +1,6 @@
/* mpc_asin -- arcsine of a complex number.
-Copyright (C) 2009, 2010, 2011 INRIA
+Copyright (C) 2009, 2010, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -38,7 +38,7 @@ mpc_asin (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
}
else if (mpfr_zero_p (mpc_realref (op)))
{
- mpfr_set (mpc_realref (rop), mpc_realref (op), GMP_RNDN);
+ mpfr_set (mpc_realref (rop), mpc_realref (op), MPFR_RNDN);
mpfr_set_nan (mpc_imagref (rop));
}
else
@@ -62,7 +62,7 @@ mpc_asin (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
mpfr_set_inf (mpc_imagref (rop), (mpfr_signbit (mpc_imagref (op)) ? -1 : 1));
if (inf_im)
- mpfr_div_2ui (mpc_realref (rop), mpc_realref (rop), 1, GMP_RNDN);
+ mpfr_div_2ui (mpc_realref (rop), mpc_realref (rop), 1, MPFR_RNDN);
}
else
{
@@ -116,7 +116,7 @@ mpc_asin (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
{
inex_im = mpfr_set_ui (mpc_imagref (rop), 0, MPC_RND_IM (rnd));
if (s_im)
- mpfr_neg (mpc_imagref (rop), mpc_imagref (rop), GMP_RNDN);
+ mpfr_neg (mpc_imagref (rop), mpc_imagref (rop), MPFR_RNDN);
inex_re = mpfr_asin (mpc_realref (rop), mpc_realref (op), MPC_RND_RE (rnd));
}
@@ -129,9 +129,9 @@ mpc_asin (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
int inex_im;
int s;
s = mpfr_signbit (mpc_realref (op));
- mpfr_set_ui (mpc_realref (rop), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (rop), 0, MPFR_RNDN);
if (s)
- mpfr_neg (mpc_realref (rop), mpc_realref (rop), GMP_RNDN);
+ mpfr_neg (mpc_realref (rop), mpc_realref (rop), MPFR_RNDN);
inex_im = mpfr_asinh (mpc_imagref (rop), mpc_imagref (op), MPC_RND_IM (rnd));
return MPC_INEX (0, inex_im);
@@ -158,8 +158,8 @@ mpc_asin (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
/* err(x) <= 1/2 ulp(x), err(y) <= 1/2 ulp(y) */
/* z1 <- 1-z1 */
ex = mpfr_get_exp (mpc_realref(z1));
- mpfr_ui_sub (mpc_realref(z1), 1, mpc_realref(z1), GMP_RNDN);
- mpfr_neg (mpc_imagref(z1), mpc_imagref(z1), GMP_RNDN);
+ mpfr_ui_sub (mpc_realref(z1), 1, mpc_realref(z1), MPFR_RNDN);
+ mpfr_neg (mpc_imagref(z1), mpc_imagref(z1), MPFR_RNDN);
ex = ex - mpfr_get_exp (mpc_realref(z1));
ex = (ex <= 0) ? 0 : ex;
/* err(x) <= 2^ex * ulp(x) */
@@ -186,8 +186,8 @@ mpc_asin (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
/* z1 <- i*z + z1 */
ex = mpfr_get_exp (mpc_realref(z1));
ey = mpfr_get_exp (mpc_imagref(z1));
- mpfr_sub (mpc_realref(z1), mpc_realref(z1), mpc_imagref(op), GMP_RNDN);
- mpfr_add (mpc_imagref(z1), mpc_imagref(z1), mpc_realref(op), GMP_RNDN);
+ mpfr_sub (mpc_realref(z1), mpc_realref(z1), mpc_imagref(op), MPFR_RNDN);
+ mpfr_add (mpc_imagref(z1), mpc_imagref(z1), mpc_realref(op), MPFR_RNDN);
if (mpfr_cmp_ui (mpc_realref(z1), 0) == 0 || mpfr_cmp_ui (mpc_imagref(z1), 0) == 0)
continue;
ex -= mpfr_get_exp (mpc_realref(z1)); /* cancellation in x */
@@ -201,7 +201,7 @@ mpc_asin (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
ey = mpfr_get_exp (mpc_imagref(z1));
ex = (ex >= ey) ? ex : ey;
err += ex - p; /* revert to absolute error <= 2^err */
- mpc_log (z1, z1, GMP_RNDN);
+ mpc_log (z1, z1, MPFR_RNDN);
err -= ex - 1; /* 1/|t| <= 1/|z| <= 2^(1-ex) */
/* express err in terms of ulp(z1) */
ey = mpfr_get_exp (mpc_realref(z1)) <= mpfr_get_exp (mpc_imagref(z1))
@@ -211,11 +211,11 @@ mpc_asin (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
err = (err <= 0) ? 1 : err + 1;
/* z1 <- -i*z1 */
mpfr_swap (mpc_realref(z1), mpc_imagref(z1));
- mpfr_neg (mpc_imagref(z1), mpc_imagref(z1), GMP_RNDN);
- if (mpfr_can_round (mpc_realref(z1), p - err, GMP_RNDN, GMP_RNDZ,
- p_re + (rnd_re == GMP_RNDN)) &&
- mpfr_can_round (mpc_imagref(z1), p - err, GMP_RNDN, GMP_RNDZ,
- p_im + (rnd_im == GMP_RNDN)))
+ mpfr_neg (mpc_imagref(z1), mpc_imagref(z1), MPFR_RNDN);
+ if (mpfr_can_round (mpc_realref(z1), p - err, MPFR_RNDN, MPFR_RNDZ,
+ p_re + (rnd_re == MPFR_RNDN)) &&
+ mpfr_can_round (mpc_imagref(z1), p - err, MPFR_RNDN, MPFR_RNDZ,
+ p_im + (rnd_im == MPFR_RNDN)))
break;
}
diff --git a/src/asinh.c b/src/asinh.c
index 89477a6..2807a8b 100644
--- a/src/asinh.c
+++ b/src/asinh.c
@@ -1,6 +1,6 @@
/* mpc_asinh -- inverse hyperbolic sine of a complex number.
-Copyright (C) 2009, 2011 INRIA
+Copyright (C) 2009, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -37,7 +37,7 @@ mpc_asinh (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
mpc_init3 (a, MPC_PREC_IM(rop), MPC_PREC_RE(rop));
inex = mpc_asin (a, z,
- RNDC (INV_RND (MPC_RND_IM (rnd)), MPC_RND_RE (rnd)));
+ MPC_RND (INV_RND (MPC_RND_IM (rnd)), MPC_RND_RE (rnd)));
/* if a = asin(i*op) = x+i*y, and we want y-i*x */
diff --git a/src/atan.c b/src/atan.c
index c47c4ef..70e1726 100644
--- a/src/atan.c
+++ b/src/atan.c
@@ -32,11 +32,11 @@ set_pi_over_2 (mpfr_ptr rop, int s, mpfr_rnd_t rnd)
int inex;
inex = mpfr_const_pi (rop, s < 0 ? INV_RND (rnd) : rnd);
- mpfr_div_2ui (rop, rop, 1, GMP_RNDN);
+ mpfr_div_2ui (rop, rop, 1, MPFR_RNDN);
if (s < 0)
{
inex = -inex;
- mpfr_neg (rop, rop, GMP_RNDN);
+ mpfr_neg (rop, rop, MPFR_RNDN);
}
return inex;
@@ -64,7 +64,7 @@ mpc_atan (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
mpfr_set_nan (mpc_realref (rop));
if (mpfr_zero_p (mpc_imagref (op)) || mpfr_inf_p (mpc_imagref (op)))
{
- mpfr_set_ui (mpc_imagref (rop), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_imagref (rop), 0, MPFR_RNDN);
if (s_im)
mpc_conj (rop, rop, MPC_RNDNN);
}
@@ -76,7 +76,7 @@ mpc_atan (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
if (mpfr_inf_p (mpc_realref (op)))
{
inex_re = set_pi_over_2 (mpc_realref (rop), -s_re, MPC_RND_RE (rnd));
- mpfr_set_ui (mpc_imagref (rop), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_imagref (rop), 0, MPFR_RNDN);
}
else
{
@@ -91,9 +91,9 @@ mpc_atan (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
{
inex_re = set_pi_over_2 (mpc_realref (rop), -s_re, MPC_RND_RE (rnd));
- mpfr_set_ui (mpc_imagref (rop), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_imagref (rop), 0, MPFR_RNDN);
if (s_im)
- mpc_conj (rop, rop, GMP_RNDN);
+ mpc_conj (rop, rop, MPFR_RNDN);
return MPC_INEX (inex_re, 0);
}
@@ -103,9 +103,9 @@ mpc_atan (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
{
inex_re = mpfr_atan (mpc_realref (rop), mpc_realref (op), MPC_RND_RE (rnd));
- mpfr_set_ui (mpc_imagref (rop), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_imagref (rop), 0, MPFR_RNDN);
if (s_im)
- mpc_conj (rop, rop, GMP_RNDN);
+ mpc_conj (rop, rop, MPFR_RNDN);
return MPC_INEX (inex_re, 0);
}
@@ -125,9 +125,9 @@ mpc_atan (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
/* atan(+0+iy) = +0 +i*atanh(y), if |y| < 1
atan(-0+iy) = -0 +i*atanh(y), if |y| < 1 */
- mpfr_set_ui (mpc_realref (rop), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (rop), 0, MPFR_RNDN);
if (s_re)
- mpfr_neg (mpc_realref (rop), mpc_realref (rop), GMP_RNDN);
+ mpfr_neg (mpc_realref (rop), mpc_realref (rop), MPFR_RNDN);
inex_im = mpfr_atanh (mpc_imagref (rop), mpc_imagref (op), MPC_RND_IM (rnd));
}
@@ -164,7 +164,7 @@ mpc_atan (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
{
p += mpc_ceil_log2 (p) + 2;
mpfr_set_prec (y, p);
- rnd_away = s_im == 0 ? GMP_RNDU : GMP_RNDD;
+ rnd_away = s_im == 0 ? MPFR_RNDU : MPFR_RNDD;
inex_im = mpfr_ui_div (y, 1, mpc_imagref (op), rnd_away);
/* FIXME: should we consider the case with unreasonably huge
precision prec(y)>3*exp_min, where atanh(1/Im(op)) could be
@@ -176,8 +176,8 @@ mpc_atan (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
inex_im |= mpfr_atanh (y, y, rnd_away);
ok = inex_im == 0
- || mpfr_can_round (y, p - 2, rnd_away, GMP_RNDZ,
- p_im + (rnd_im == GMP_RNDN));
+ || mpfr_can_round (y, p - 2, rnd_away, MPFR_RNDZ,
+ p_im + (rnd_im == MPFR_RNDN));
} while (ok == 0);
inex_re = set_pi_over_2 (mpc_realref (rop), -s_re, MPC_RND_RE (rnd));
@@ -196,7 +196,6 @@ mpc_atan (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
mpfr_t minus_op_re;
mpfr_exp_t op_re_exp, op_im_exp;
mpfr_rnd_t rnd1, rnd2;
- int loops = 0;
mpfr_inits2 (MPFR_PREC_MIN, a, b, x, y, (mpfr_ptr) 0);
@@ -227,8 +226,8 @@ mpc_atan (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
/* p: working precision */
p = (op_im_exp > 0 || prec > SAFE_ABS (mpfr_prec_t, op_im_exp)) ? prec
: (prec - op_im_exp);
- rnd1 = mpfr_sgn (mpc_realref (op)) > 0 ? GMP_RNDD : GMP_RNDU;
- rnd2 = mpfr_sgn (mpc_realref (op)) < 0 ? GMP_RNDU : GMP_RNDD;
+ rnd1 = mpfr_sgn (mpc_realref (op)) > 0 ? MPFR_RNDD : MPFR_RNDU;
+ rnd2 = mpfr_sgn (mpc_realref (op)) < 0 ? MPFR_RNDU : MPFR_RNDD;
do
{
@@ -250,7 +249,7 @@ mpc_atan (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
}
else
err = mpfr_get_exp (a); /* err = Exp(a) with the notations above */
- mpfr_atan2 (x, mpc_realref (op), a, GMP_RNDU);
+ mpfr_atan2 (x, mpc_realref (op), a, MPFR_RNDU);
/* b = lower bound for atan (-x/(1+y)): for x negative, we need a
lower bound on -x/(1+y), i.e., an upper bound on 1+y */
@@ -265,21 +264,21 @@ mpc_atan (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
}
else
expo = mpfr_get_exp (a); /* expo = Exp(c) with the notations above */
- mpfr_atan2 (b, minus_op_re, a, GMP_RNDD);
+ mpfr_atan2 (b, minus_op_re, a, MPFR_RNDD);
err = err < expo ? err : expo; /* err = min(Exp(a),Exp(c)) */
- mpfr_sub (x, x, b, GMP_RNDU);
+ mpfr_sub (x, x, b, MPFR_RNDU);
err = 5 + op_re_exp - err - mpfr_get_exp (x);
/* error is bounded by [1 + 2^err] ulp(e) */
err = err < 0 ? 1 : err + 1;
- mpfr_div_2ui (x, x, 1, GMP_RNDU);
+ mpfr_div_2ui (x, x, 1, MPFR_RNDU);
/* Note: using RND2=RNDD guarantees that if x is exactly representable
on prec + ... bits, mpfr_can_round will return 0 */
- ok = mpfr_can_round (x, p - err, GMP_RNDU, GMP_RNDD,
- prec + (MPC_RND_RE (rnd) == GMP_RNDN));
+ ok = mpfr_can_round (x, p - err, MPFR_RNDU, MPFR_RNDD,
+ prec + (MPC_RND_RE (rnd) == MPFR_RNDN));
} while (ok == 0);
/* Imaginary part
@@ -305,7 +304,6 @@ mpc_atan (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
*/
err = 2;
p = prec; /* working precision */
- rnd1 = mpfr_cmp_si (mpc_imagref (op), -1) > 0 ? GMP_RNDU : GMP_RNDD;
do
{
@@ -315,23 +313,27 @@ mpc_atan (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
mpfr_set_prec (y, p);
/* a = upper bound for log(x^2 + (1+y)^2) */
- mpfr_add_ui (a, mpc_imagref (op), 1, rnd1);
- mpfr_sqr (a, a, GMP_RNDU);
- mpfr_sqr (y, mpc_realref (op), GMP_RNDU);
- mpfr_add (a, a, y, GMP_RNDU);
- mpfr_log (a, a, GMP_RNDU);
+ mpfr_add_ui (a, mpc_imagref (op), 1, MPFR_RNDA);
+ mpfr_sqr (a, a, MPFR_RNDU);
+ mpfr_sqr (y, mpc_realref (op), MPFR_RNDU);
+ mpfr_add (a, a, y, MPFR_RNDU);
+ mpfr_log (a, a, MPFR_RNDU);
/* b = lower bound for log(x^2 + (1-y)^2) */
- mpfr_ui_sub (b, 1, mpc_imagref (op), GMP_RNDZ);
- mpfr_sqr (b, b, GMP_RNDU);
- /* mpfr_sqr (y, mpc_realref (op), GMP_RNDZ); */
+ mpfr_ui_sub (b, 1, mpc_imagref (op), MPFR_RNDZ); /* round to zero */
+ mpfr_sqr (b, b, MPFR_RNDZ);
+ /* we could write mpfr_sqr (y, mpc_realref (op), MPFR_RNDZ) but it is
+ more efficient to reuse the value of y (x^2) above and subtract
+ one ulp */
mpfr_nextbelow (y);
- mpfr_add (b, b, y, GMP_RNDZ);
- mpfr_log (b, b, GMP_RNDZ);
+ mpfr_add (b, b, y, MPFR_RNDZ);
+ mpfr_log (b, b, MPFR_RNDZ);
- mpfr_sub (y, a, b, GMP_RNDU);
+ mpfr_sub (y, a, b, MPFR_RNDU);
if (mpfr_zero_p (y))
+ /* FIXME: happens when x and y have very different magnitudes;
+ could be handled more efficiently */
ok = 0;
else
{
@@ -344,12 +346,16 @@ mpc_atan (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
else
err = (expo < 0) ? 1 : expo + 2;
- mpfr_div_2ui (y, y, 2, GMP_RNDN);
- if (mpfr_zero_p (y))
- err = 2; /* underflow */
+ mpfr_div_2ui (y, y, 2, MPFR_RNDN);
+ MPC_ASSERT (!mpfr_zero_p (y));
+ /* FIXME: underflow. Since the main term of the Taylor series
+ in y=0 is 1/(x^2+1) * y, this means that y is very small
+ and/or x very large; but then the mpfr_zero_p (y) above
+ should be true. This needs a proof, or better yet,
+ special code. */
- ok = mpfr_can_round (y, p - err, GMP_RNDU, GMP_RNDD,
- prec + (MPC_RND_IM (rnd) == GMP_RNDN));
+ ok = mpfr_can_round (y, p - err, MPFR_RNDU, MPFR_RNDD,
+ prec + (MPC_RND_IM (rnd) == MPFR_RNDN));
}
} while (ok == 0);
diff --git a/src/atanh.c b/src/atanh.c
index 3e1c448..e5716cc 100644
--- a/src/atanh.c
+++ b/src/atanh.c
@@ -1,6 +1,6 @@
/* mpc_atanh -- inverse hyperbolic tangent of a complex number.
-Copyright (C) 2009, 2011 INRIA
+Copyright (C) 2009, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -36,7 +36,7 @@ mpc_atanh (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
mpc_init3 (a, MPC_PREC_IM(rop), MPC_PREC_RE(rop));
inex = mpc_atan (a, z,
- RNDC (INV_RND (MPC_RND_IM (rnd)), MPC_RND_RE (rnd)));
+ MPC_RND (INV_RND (MPC_RND_IM (rnd)), MPC_RND_RE (rnd)));
/* change a to -i*a, i.e., x+i*y to y-i*x */
tmp[0] = mpc_realref (a)[0];
diff --git a/src/div.c b/src/div.c
index c96832d..1dabebc 100644
--- a/src/div.c
+++ b/src/div.c
@@ -68,28 +68,28 @@ mpc_div_inf_fin (mpc_ptr rop, mpc_srcptr z, mpc_srcptr w)
if (a == 1)
if (b == 1) {
- mpfr_add (sign, mpc_realref (w), mpc_imagref (w), GMP_RNDN);
+ mpfr_add (sign, mpc_realref (w), mpc_imagref (w), MPFR_RNDN);
x = MPC_MPFR_SIGN (sign);
- mpfr_sub (sign, mpc_realref (w), mpc_imagref (w), GMP_RNDN);
+ mpfr_sub (sign, mpc_realref (w), mpc_imagref (w), MPFR_RNDN);
y = MPC_MPFR_SIGN (sign);
}
else { /* b == -1 */
- mpfr_sub (sign, mpc_realref (w), mpc_imagref (w), GMP_RNDN);
+ mpfr_sub (sign, mpc_realref (w), mpc_imagref (w), MPFR_RNDN);
x = MPC_MPFR_SIGN (sign);
- mpfr_add (sign, mpc_realref (w), mpc_imagref (w), GMP_RNDN);
+ mpfr_add (sign, mpc_realref (w), mpc_imagref (w), MPFR_RNDN);
y = -MPC_MPFR_SIGN (sign);
}
else /* a == -1 */
if (b == 1) {
- mpfr_sub (sign, mpc_imagref (w), mpc_realref (w), GMP_RNDN);
+ mpfr_sub (sign, mpc_imagref (w), mpc_realref (w), MPFR_RNDN);
x = MPC_MPFR_SIGN (sign);
- mpfr_add (sign, mpc_realref (w), mpc_imagref (w), GMP_RNDN);
+ mpfr_add (sign, mpc_realref (w), mpc_imagref (w), MPFR_RNDN);
y = MPC_MPFR_SIGN (sign);
}
else { /* b == -1 */
- mpfr_add (sign, mpc_realref (w), mpc_imagref (w), GMP_RNDN);
+ mpfr_add (sign, mpc_realref (w), mpc_imagref (w), MPFR_RNDN);
x = -MPC_MPFR_SIGN (sign);
- mpfr_sub (sign, mpc_imagref (w), mpc_realref (w), GMP_RNDN);
+ mpfr_sub (sign, mpc_imagref (w), mpc_realref (w), MPFR_RNDN);
y = MPC_MPFR_SIGN (sign);
}
mpfr_clear (sign);
@@ -121,25 +121,25 @@ mpc_div_fin_inf (mpc_ptr rop, mpc_srcptr z, mpc_srcptr w)
mpfr_init2 (x, 2);
mpfr_init2 (y, 2);
mpfr_init2 (zero, 2);
- mpfr_set_ui (zero, 0ul, GMP_RNDN);
+ mpfr_set_ui (zero, 0ul, MPFR_RNDN);
mpfr_init2 (a, mpfr_get_prec (mpc_realref (z)));
mpfr_init2 (b, mpfr_get_prec (mpc_imagref (z)));
- mpfr_set_ui (c, (mpfr_inf_p (mpc_realref (w)) ? 1 : 0), GMP_RNDN);
- MPFR_COPYSIGN (c, c, mpc_realref (w), GMP_RNDN);
- mpfr_set_ui (d, (mpfr_inf_p (mpc_imagref (w)) ? 1 : 0), GMP_RNDN);
- MPFR_COPYSIGN (d, d, mpc_imagref (w), GMP_RNDN);
+ mpfr_set_ui (c, (mpfr_inf_p (mpc_realref (w)) ? 1 : 0), MPFR_RNDN);
+ MPFR_COPYSIGN (c, c, mpc_realref (w), MPFR_RNDN);
+ mpfr_set_ui (d, (mpfr_inf_p (mpc_imagref (w)) ? 1 : 0), MPFR_RNDN);
+ MPFR_COPYSIGN (d, d, mpc_imagref (w), MPFR_RNDN);
- mpfr_mul (a, mpc_realref (z), c, GMP_RNDN); /* exact */
- mpfr_mul (b, mpc_imagref (z), d, GMP_RNDN);
- mpfr_add (x, a, b, GMP_RNDN);
+ mpfr_mul (a, mpc_realref (z), c, MPFR_RNDN); /* exact */
+ mpfr_mul (b, mpc_imagref (z), d, MPFR_RNDN);
+ mpfr_add (x, a, b, MPFR_RNDN);
- mpfr_mul (b, mpc_imagref (z), c, GMP_RNDN);
- mpfr_mul (a, mpc_realref (z), d, GMP_RNDN);
- mpfr_sub (y, b, a, GMP_RNDN);
+ mpfr_mul (b, mpc_imagref (z), c, MPFR_RNDN);
+ mpfr_mul (a, mpc_realref (z), d, MPFR_RNDN);
+ mpfr_sub (y, b, a, MPFR_RNDN);
- MPFR_COPYSIGN (mpc_realref (rop), zero, x, GMP_RNDN);
- MPFR_COPYSIGN (mpc_imagref (rop), zero, y, GMP_RNDN);
+ MPFR_COPYSIGN (mpc_realref (rop), zero, x, MPFR_RNDN);
+ MPFR_COPYSIGN (mpc_imagref (rop), zero, y, MPFR_RNDN);
mpfr_clear (c);
mpfr_clear (d);
@@ -173,10 +173,10 @@ mpc_div_real (mpc_ptr rop, mpc_srcptr z, mpc_srcptr w, mpc_rnd_t rnd)
inexact flags */
if (mpfr_zero_p (mpc_realref (rop)))
mpfr_setsign (mpc_realref (rop), mpc_realref (rop), (zrs != wrs && zis != wis),
- GMP_RNDN); /* exact */
+ MPFR_RNDN); /* exact */
if (mpfr_zero_p (mpc_imagref (rop)))
mpfr_setsign (mpc_imagref (rop), mpc_imagref (rop), (zis != wrs && zrs == wis),
- GMP_RNDN);
+ MPFR_RNDN);
return MPC_INEX(inex_re, inex_im);
}
@@ -204,7 +204,7 @@ mpc_div_imag (mpc_ptr rop, mpc_srcptr z, mpc_srcptr w, mpc_rnd_t rnd)
wloc[0] = mpc_imagref(w)[0]; /* copies mpfr struct IM(w) into wloc */
inex_re = mpfr_div (mpc_realref(dest), mpc_imagref(z), wloc, MPC_RND_RE(rnd));
- mpfr_neg (wloc, wloc, GMP_RNDN);
+ mpfr_neg (wloc, wloc, MPFR_RNDN);
/* changes the sign only in wloc, not in w; no need to correct later */
inex_im = mpfr_div (mpc_imagref(dest), mpc_realref(z), wloc, MPC_RND_IM(rnd));
@@ -221,10 +221,10 @@ mpc_div_imag (mpc_ptr rop, mpc_srcptr z, mpc_srcptr w, mpc_rnd_t rnd)
inexact flags */
if (mpfr_zero_p (mpc_realref (rop)))
mpfr_setsign (mpc_realref (rop), mpc_realref (rop), (zrs != wrs && zis != wis),
- GMP_RNDN); /* exact */
+ MPFR_RNDN); /* exact */
if (imag_z)
mpfr_setsign (mpc_imagref (rop), mpc_imagref (rop), (zis != wrs && zrs == wis),
- GMP_RNDN);
+ MPFR_RNDN);
return MPC_INEX(inex_re, inex_im);
}
@@ -292,11 +292,11 @@ mpc_div (mpc_ptr a, mpc_srcptr b, mpc_srcptr c, mpc_rnd_t rnd)
/* first compute norm(c) */
mpfr_clear_underflow ();
mpfr_clear_overflow ();
- inexact_norm = mpc_norm (q, c, GMP_RNDU);
+ inexact_norm = mpc_norm (q, c, MPFR_RNDU);
underflow_norm = mpfr_underflow_p ();
overflow_norm = mpfr_overflow_p ();
if (underflow_norm)
- mpfr_set_ui (q, 0ul, GMP_RNDN);
+ mpfr_set_ui (q, 0ul, MPFR_RNDN);
/* to obtain divisions by 0 later on */
/* now compute b*conjugate(c) */
@@ -312,69 +312,77 @@ mpc_div (mpc_ptr a, mpc_srcptr b, mpc_srcptr c, mpc_rnd_t rnd)
hopefully, the side-effects of mpc_mul do indeed raise the
mpfr exceptions */
if (overflow_prod) {
+ int isinf = 0;
tmpsgn = mpfr_sgn (mpc_realref(res));
if (tmpsgn > 0)
- mpfr_nextabove (mpc_realref(res));
+ {
+ mpfr_nextabove (mpc_realref(res));
+ isinf = mpfr_inf_p (mpc_realref(res));
+ mpfr_nextbelow (mpc_realref(res));
+ }
else if (tmpsgn < 0)
- mpfr_nextbelow (mpc_realref(res));
- if (mpfr_inf_p (mpc_realref(res)))
+ {
+ mpfr_nextbelow (mpc_realref(res));
+ isinf = mpfr_inf_p (mpc_realref(res));
+ mpfr_nextabove (mpc_realref(res));
+ }
+ if (isinf)
{
mpfr_set_inf (mpc_realref(res), tmpsgn);
overflow_re = 1;
}
- else
- if (tmpsgn > 0)
- mpfr_nextbelow (mpc_realref(res));
- else if (tmpsgn < 0)
- mpfr_nextabove (mpc_realref(res));
tmpsgn = mpfr_sgn (mpc_imagref(res));
+ isinf = 0;
if (tmpsgn > 0)
- mpfr_nextabove (mpc_imagref(res));
+ {
+ mpfr_nextabove (mpc_imagref(res));
+ isinf = mpfr_inf_p (mpc_imagref(res));
+ mpfr_nextbelow (mpc_imagref(res));
+ }
else if (tmpsgn < 0)
- mpfr_nextbelow (mpc_imagref(res));
- if (mpfr_inf_p (mpc_imagref(res)))
+ {
+ mpfr_nextbelow (mpc_imagref(res));
+ isinf = mpfr_inf_p (mpc_imagref(res));
+ mpfr_nextabove (mpc_imagref(res));
+ }
+ if (isinf)
{
mpfr_set_inf (mpc_imagref(res), tmpsgn);
overflow_im = 1;
}
- else
- if (tmpsgn > 0)
- mpfr_nextbelow (mpc_imagref(res));
- else if (tmpsgn < 0)
- mpfr_nextabove (mpc_imagref(res));
mpc_set (a, res, rnd);
goto end;
}
/* divide the product by the norm */
if (inexact_norm == 0 && (inexact_re == 0 || inexact_im == 0)) {
- /* The division has good chances to be exact in at least one part. */
- /* Since this can cause problems when not rounding to the nearest, */
- /* we use the division code of mpfr, which handles the situation. */
+ /* The division has good chances to be exact in at least one part. */
+ /* Since this can cause problems when not rounding to the nearest, */
+ /* we use the division code of mpfr, which handles the situation. */
mpfr_clear_underflow ();
mpfr_clear_overflow ();
- inexact_re |= mpfr_div (mpc_realref (res), mpc_realref (res), q, GMP_RNDZ);
+ inexact_re |= mpfr_div (mpc_realref (res), mpc_realref (res), q, MPFR_RNDZ);
underflow_re = mpfr_underflow_p ();
overflow_re = mpfr_overflow_p ();
ok_re = !inexact_re || underflow_re || overflow_re
- || mpfr_can_round (mpc_realref (res), prec - 4, GMP_RNDN,
- GMP_RNDZ, MPC_PREC_RE(a) + (rnd_re == GMP_RNDN));
+ || mpfr_can_round (mpc_realref (res), prec - 4, MPFR_RNDN,
+ MPFR_RNDZ, MPC_PREC_RE(a) + (rnd_re == MPFR_RNDN));
if (ok_re) /* compute imaginary part */ {
mpfr_clear_underflow ();
mpfr_clear_overflow ();
- inexact_im |= mpfr_div (mpc_imagref (res), mpc_imagref (res), q, GMP_RNDZ);
+ inexact_im |= mpfr_div (mpc_imagref (res), mpc_imagref (res), q, MPFR_RNDZ);
underflow_im = mpfr_underflow_p ();
overflow_im = mpfr_overflow_p ();
ok_im = !inexact_im || underflow_im || overflow_im
- || mpfr_can_round (mpc_imagref (res), prec - 4, GMP_RNDN,
- GMP_RNDZ, MPC_PREC_IM(a) + (rnd_im == GMP_RNDN));
+ || mpfr_can_round (mpc_imagref (res), prec - 4, MPFR_RNDN,
+ MPFR_RNDZ, MPC_PREC_IM(a) + (rnd_im == MPFR_RNDN));
}
}
else {
/* The division is inexact, so for efficiency reasons we invert q */
/* only once and multiply by the inverse. */
- if (mpfr_ui_div (q, 1ul, q, GMP_RNDZ) || inexact_norm) {
+ if (mpfr_ui_div (q, 1ul, q, MPFR_RNDZ) || inexact_norm) {
/* if 1/q is inexact, the approximations of the real and
imaginary part below will be inexact, unless RE(res)
or IM(res) is zero */
@@ -383,22 +391,22 @@ mpc_div (mpc_ptr a, mpc_srcptr b, mpc_srcptr c, mpc_rnd_t rnd)
}
mpfr_clear_underflow ();
mpfr_clear_overflow ();
- inexact_re |= mpfr_mul (mpc_realref (res), mpc_realref (res), q, GMP_RNDZ);
+ inexact_re |= mpfr_mul (mpc_realref (res), mpc_realref (res), q, MPFR_RNDZ);
underflow_re = mpfr_underflow_p ();
overflow_re = mpfr_overflow_p ();
ok_re = !inexact_re || underflow_re || overflow_re
- || mpfr_can_round (mpc_realref (res), prec - 4, GMP_RNDN,
- GMP_RNDZ, MPC_PREC_RE(a) + (rnd_re == GMP_RNDN));
+ || mpfr_can_round (mpc_realref (res), prec - 4, MPFR_RNDN,
+ MPFR_RNDZ, MPC_PREC_RE(a) + (rnd_re == MPFR_RNDN));
if (ok_re) /* compute imaginary part */ {
mpfr_clear_underflow ();
mpfr_clear_overflow ();
- inexact_im |= mpfr_mul (mpc_imagref (res), mpc_imagref (res), q, GMP_RNDZ);
+ inexact_im |= mpfr_mul (mpc_imagref (res), mpc_imagref (res), q, MPFR_RNDZ);
underflow_im = mpfr_underflow_p ();
overflow_im = mpfr_overflow_p ();
ok_im = !inexact_im || underflow_im || overflow_im
- || mpfr_can_round (mpc_imagref (res), prec - 4, GMP_RNDN,
- GMP_RNDZ, MPC_PREC_IM(a) + (rnd_im == GMP_RNDN));
+ || mpfr_can_round (mpc_imagref (res), prec - 4, MPFR_RNDN,
+ MPFR_RNDZ, MPC_PREC_IM(a) + (rnd_im == MPFR_RNDN));
}
}
} while ((!ok_re || !ok_im) && !underflow_norm && !overflow_norm
@@ -416,16 +424,16 @@ mpc_div (mpc_ptr a, mpc_srcptr b, mpc_srcptr c, mpc_rnd_t rnd)
inexact_re = mpfr_sgn (mpc_realref (res));
}
else if (underflow_re || (overflow_norm && !overflow_prod)) {
- mpfr_set_zero (mpc_realref (a), mpfr_sgn (mpc_realref (res)));
- inexact_re = -mpfr_sgn (mpc_realref (res));
+ inexact_re = mpfr_signbit (mpc_realref (res)) ? 1 : -1;
+ mpfr_set_zero (mpc_realref (a), -inexact_re);
}
if (overflow_im || (underflow_norm && !underflow_prod)) {
mpfr_set_inf (mpc_imagref (a), mpfr_sgn (mpc_imagref (res)));
inexact_im = mpfr_sgn (mpc_imagref (res));
}
else if (underflow_im || (overflow_norm && !overflow_prod)) {
- mpfr_set_zero (mpc_imagref (a), mpfr_sgn (mpc_imagref (res)));
- inexact_im = -mpfr_sgn (mpc_imagref (res));
+ inexact_im = mpfr_signbit (mpc_imagref (res)) ? 1 : -1;
+ mpfr_set_zero (mpc_imagref (a), -inexact_im);
}
mpc_clear (res);
diff --git a/src/div_2exp.c b/src/div_2si.c
index 22e67e4..511f2cb 100644
--- a/src/div_2exp.c
+++ b/src/div_2si.c
@@ -1,6 +1,6 @@
-/* mpc_div_2exp -- Divide a complex number by 2^e.
+/* mpc_div_2si -- Divide a complex number by 2^e.
-Copyright (C) 2002, 2009, 2011 INRIA
+Copyright (C) 2012 INRIA
This file is part of GNU MPC.
@@ -21,12 +21,12 @@ along with this program. If not, see http://www.gnu.org/licenses/ .
#include "mpc-impl.h"
int
-mpc_div_2exp (mpc_ptr a, mpc_srcptr b, unsigned long int c, mpc_rnd_t rnd)
+mpc_div_2si (mpc_ptr a, mpc_srcptr b, long int c, mpc_rnd_t rnd)
{
int inex_re, inex_im;
- inex_re = mpfr_div_2exp (mpc_realref(a), mpc_realref(b), c, MPC_RND_RE(rnd));
- inex_im = mpfr_div_2exp (mpc_imagref(a), mpc_imagref(b), c, MPC_RND_IM(rnd));
+ inex_re = mpfr_div_2si (mpc_realref(a), mpc_realref(b), c, MPC_RND_RE(rnd));
+ inex_im = mpfr_div_2si (mpc_imagref(a), mpc_imagref(b), c, MPC_RND_IM(rnd));
return MPC_INEX(inex_re, inex_im);
}
diff --git a/src/mul_2exp.c b/src/div_2ui.c
index ff2efe2..cd53855 100644
--- a/src/mul_2exp.c
+++ b/src/div_2ui.c
@@ -1,6 +1,6 @@
-/* mpc_mul_2exp -- Multiply a complex number by 2^e.
+/* mpc_div_2ui -- Divide a complex number by 2^e.
-Copyright (C) 2002, 2009, 2011 INRIA
+Copyright (C) 2002, 2009, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -21,12 +21,12 @@ along with this program. If not, see http://www.gnu.org/licenses/ .
#include "mpc-impl.h"
int
-mpc_mul_2exp (mpc_ptr a, mpc_srcptr b, unsigned long int c, mpc_rnd_t rnd)
+mpc_div_2ui (mpc_ptr a, mpc_srcptr b, unsigned long int c, mpc_rnd_t rnd)
{
int inex_re, inex_im;
- inex_re = mpfr_mul_2exp (mpc_realref(a), mpc_realref(b), c, MPC_RND_RE(rnd));
- inex_im = mpfr_mul_2exp (mpc_imagref(a), mpc_imagref(b), c, MPC_RND_IM(rnd));
+ inex_re = mpfr_div_2ui (mpc_realref(a), mpc_realref(b), c, MPC_RND_RE(rnd));
+ inex_im = mpfr_div_2ui (mpc_imagref(a), mpc_imagref(b), c, MPC_RND_IM(rnd));
return MPC_INEX(inex_re, inex_im);
}
diff --git a/src/div_fr.c b/src/div_fr.c
index d5ea240..447c078 100644
--- a/src/div_fr.c
+++ b/src/div_fr.c
@@ -1,6 +1,6 @@
/* mpc_div_fr -- Divide a complex number by a floating-point number.
-Copyright (C) 2002, 2008, 2009, 2010, 2011 INRIA
+Copyright (C) 2002, 2008, 2009, 2010, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -31,7 +31,7 @@ mpc_div_fr (mpc_ptr a, mpc_srcptr b, mpfr_srcptr c, mpc_rnd_t rnd)
inex_re = mpfr_div (real, mpc_realref(b), c, MPC_RND_RE(rnd));
inex_im = mpfr_div (mpc_imagref(a), mpc_imagref(b), c, MPC_RND_IM(rnd));
- mpfr_set (mpc_realref (a), real, GMP_RNDN);
+ mpfr_set (mpc_realref (a), real, MPFR_RNDN);
mpfr_clear (real);
diff --git a/src/exp.c b/src/exp.c
index 3646225..06faff3 100644
--- a/src/exp.c
+++ b/src/exp.c
@@ -1,6 +1,6 @@
/* mpc_exp -- exponential of a complex number.
-Copyright (C) 2002, 2009, 2010, 2011 INRIA
+Copyright (C) 2002, 2009, 2010, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -88,15 +88,15 @@ mpc_exp (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
mpfr_init2 (n, 2);
if (mpfr_signbit (mpc_realref (op)))
- mpfr_set_ui (n, 0, GMP_RNDN);
+ mpfr_set_ui (n, 0, MPFR_RNDN);
else
mpfr_set_inf (n, +1);
if (mpfr_inf_p (mpc_imagref (op)))
{
- inex_re = mpfr_set (mpc_realref (rop), n, GMP_RNDN);
+ inex_re = mpfr_set (mpc_realref (rop), n, MPFR_RNDN);
if (mpfr_signbit (mpc_realref (op)))
- inex_im = mpfr_set (mpc_imagref (rop), n, GMP_RNDN);
+ inex_im = mpfr_set (mpc_imagref (rop), n, MPFR_RNDN);
else
{
mpfr_set_nan (mpc_imagref (rop));
@@ -109,9 +109,9 @@ mpc_exp (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
mpfr_init2 (c, 2);
mpfr_init2 (s, 2);
- mpfr_sin_cos (s, c, mpc_imagref (op), GMP_RNDN);
- inex_re = mpfr_copysign (mpc_realref (rop), n, c, GMP_RNDN);
- inex_im = mpfr_copysign (mpc_imagref (rop), n, s, GMP_RNDN);
+ mpfr_sin_cos (s, c, mpc_imagref (op), MPFR_RNDN);
+ inex_re = mpfr_copysign (mpc_realref (rop), n, c, MPFR_RNDN);
+ inex_im = mpfr_copysign (mpc_imagref (rop), n, s, MPFR_RNDN);
mpfr_clear (s);
mpfr_clear (c);
@@ -159,18 +159,18 @@ mpc_exp (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
could be represented in the precision of rop. */
mpfr_clear_overflow ();
mpfr_clear_underflow ();
- mpfr_exp (x, mpc_realref(op), GMP_RNDN); /* error <= 0.5ulp */
- mpfr_sin_cos (z, y, mpc_imagref(op), GMP_RNDN); /* errors <= 0.5ulp */
- mpfr_mul (y, y, x, GMP_RNDN); /* error <= 2ulp */
+ mpfr_exp (x, mpc_realref(op), MPFR_RNDN); /* error <= 0.5ulp */
+ mpfr_sin_cos (z, y, mpc_imagref(op), MPFR_RNDN); /* errors <= 0.5ulp */
+ mpfr_mul (y, y, x, MPFR_RNDN); /* error <= 2ulp */
ok = mpfr_overflow_p () || mpfr_zero_p (x)
- || mpfr_can_round (y, prec - 2, GMP_RNDN, GMP_RNDZ,
- MPC_PREC_RE(rop) + (MPC_RND_RE(rnd) == GMP_RNDN));
+ || mpfr_can_round (y, prec - 2, MPFR_RNDN, MPFR_RNDZ,
+ MPC_PREC_RE(rop) + (MPC_RND_RE(rnd) == MPFR_RNDN));
if (ok) /* compute imaginary part */
{
- mpfr_mul (z, z, x, GMP_RNDN);
+ mpfr_mul (z, z, x, MPFR_RNDN);
ok = mpfr_overflow_p () || mpfr_zero_p (x)
- || mpfr_can_round (z, prec - 2, GMP_RNDN, GMP_RNDZ,
- MPC_PREC_IM(rop) + (MPC_RND_IM(rnd) == GMP_RNDN));
+ || mpfr_can_round (z, prec - 2, MPFR_RNDN, MPFR_RNDZ,
+ MPC_PREC_IM(rop) + (MPC_RND_IM(rnd) == MPFR_RNDN));
}
}
while (ok == 0);
diff --git a/src/fma.c b/src/fma.c
index d4be40f..3512caf 100644
--- a/src/fma.c
+++ b/src/fma.c
@@ -51,10 +51,10 @@ mpc_fma_naive (mpc_ptr r, mpc_srcptr a, mpc_srcptr b, mpc_srcptr c, mpc_rnd_t rn
mpfr_init2 (ima_reb, mpfr_get_prec (mpc_imagref(a)) + mpfr_get_prec (mpc_realref(b)));
mpfr_init2 (ima_imb, mpfr_get_prec (mpc_imagref(a)) + mpfr_get_prec (mpc_imagref(b)));
- mpfr_mul (rea_reb, mpc_realref(a), mpc_realref(b), GMP_RNDZ); /* exact */
- mpfr_mul (rea_imb, mpc_realref(a), mpc_imagref(b), GMP_RNDZ); /* exact */
- mpfr_mul (ima_reb, mpc_imagref(a), mpc_realref(b), GMP_RNDZ); /* exact */
- mpfr_mul (ima_imb, mpc_imagref(a), mpc_imagref(b), GMP_RNDZ); /* exact */
+ mpfr_mul (rea_reb, mpc_realref(a), mpc_realref(b), MPFR_RNDZ); /* exact */
+ mpfr_mul (rea_imb, mpc_realref(a), mpc_imagref(b), MPFR_RNDZ); /* exact */
+ mpfr_mul (ima_reb, mpc_imagref(a), mpc_realref(b), MPFR_RNDZ); /* exact */
+ mpfr_mul (ima_imb, mpc_imagref(a), mpc_imagref(b), MPFR_RNDZ); /* exact */
/* Re(r) <- rea_reb - ima_imb + Re(c) */
@@ -67,7 +67,7 @@ mpc_fma_naive (mpc_ptr r, mpc_srcptr a, mpc_srcptr b, mpc_srcptr c, mpc_rnd_t rn
if (pre12 <= pre13 && pre12 <= pre23) /* (rea_reb - ima_imb) + Re(c) */
{
mpfr_init2 (tmp, pre12);
- mpfr_sub (tmp, rea_reb, ima_imb, GMP_RNDZ); /* exact */
+ mpfr_sub (tmp, rea_reb, ima_imb, MPFR_RNDZ); /* exact */
inex_re = mpfr_add (mpc_realref(r), tmp, mpc_realref(c), MPC_RND_RE(rnd));
/* the only possible bad overlap is between r and c, but since we are
only touching the real part of both, it is ok */
@@ -75,7 +75,7 @@ mpc_fma_naive (mpc_ptr r, mpc_srcptr a, mpc_srcptr b, mpc_srcptr c, mpc_rnd_t rn
else if (pre13 <= pre23) /* (rea_reb + Re(c)) - ima_imb */
{
mpfr_init2 (tmp, pre13);
- mpfr_add (tmp, rea_reb, mpc_realref(c), GMP_RNDZ); /* exact */
+ mpfr_add (tmp, rea_reb, mpc_realref(c), MPFR_RNDZ); /* exact */
inex_re = mpfr_sub (mpc_realref(r), tmp, ima_imb, MPC_RND_RE(rnd));
/* the only possible bad overlap is between r and c, but since we are
only touching the real part of both, it is ok */
@@ -83,7 +83,7 @@ mpc_fma_naive (mpc_ptr r, mpc_srcptr a, mpc_srcptr b, mpc_srcptr c, mpc_rnd_t rn
else /* rea_reb + (Re(c) - ima_imb) */
{
mpfr_init2 (tmp, pre23);
- mpfr_sub (tmp, mpc_realref(c), ima_imb, GMP_RNDZ); /* exact */
+ mpfr_sub (tmp, mpc_realref(c), ima_imb, MPFR_RNDZ); /* exact */
inex_re = mpfr_add (mpc_realref(r), tmp, rea_reb, MPC_RND_RE(rnd));
/* the only possible bad overlap is between r and c, but since we are
only touching the real part of both, it is ok */
@@ -99,7 +99,7 @@ mpc_fma_naive (mpc_ptr r, mpc_srcptr a, mpc_srcptr b, mpc_srcptr c, mpc_rnd_t rn
if (pim12 <= pim13 && pim12 <= pim23) /* (rea_imb + ima_reb) + Im(c) */
{
mpfr_set_prec (tmp, pim12);
- mpfr_add (tmp, rea_imb, ima_reb, GMP_RNDZ); /* exact */
+ mpfr_add (tmp, rea_imb, ima_reb, MPFR_RNDZ); /* exact */
inex_im = mpfr_add (mpc_imagref(r), tmp, mpc_imagref(c), MPC_RND_IM(rnd));
/* the only possible bad overlap is between r and c, but since we are
only touching the imaginary part of both, it is ok */
@@ -107,7 +107,7 @@ mpc_fma_naive (mpc_ptr r, mpc_srcptr a, mpc_srcptr b, mpc_srcptr c, mpc_rnd_t rn
else if (pim13 <= pim23) /* (rea_imb + Im(c)) + ima_reb */
{
mpfr_set_prec (tmp, pim13);
- mpfr_add (tmp, rea_imb, mpc_imagref(c), GMP_RNDZ); /* exact */
+ mpfr_add (tmp, rea_imb, mpc_imagref(c), MPFR_RNDZ); /* exact */
inex_im = mpfr_add (mpc_imagref(r), tmp, ima_reb, MPC_RND_IM(rnd));
/* the only possible bad overlap is between r and c, but since we are
only touching the imaginary part of both, it is ok */
@@ -115,7 +115,7 @@ mpc_fma_naive (mpc_ptr r, mpc_srcptr a, mpc_srcptr b, mpc_srcptr c, mpc_rnd_t rn
else /* rea_imb + (Im(c) + ima_reb) */
{
mpfr_set_prec (tmp, pre23);
- mpfr_add (tmp, mpc_imagref(c), ima_reb, GMP_RNDZ); /* exact */
+ mpfr_add (tmp, mpc_imagref(c), ima_reb, MPFR_RNDZ); /* exact */
inex_im = mpfr_add (mpc_imagref(r), tmp, rea_imb, MPC_RND_IM(rnd));
/* the only possible bad overlap is between r and c, but since we are
only touching the imaginary part of both, it is ok */
@@ -159,19 +159,19 @@ mpc_fma (mpc_ptr r, mpc_srcptr a, mpc_srcptr b, mpc_srcptr c, mpc_rnd_t rnd)
break;
diffre = mpfr_get_exp (mpc_realref(ab));
diffim = mpfr_get_exp (mpc_imagref(ab));
+ mpc_add (ab, ab, c, MPC_RNDZZ);
if (mpfr_zero_p (mpc_realref(ab)) || mpfr_zero_p (mpc_imagref(ab)))
break;
- mpc_add (ab, ab, c, MPC_RNDZZ);
diffre -= mpfr_get_exp (mpc_realref(ab));
diffim -= mpfr_get_exp (mpc_imagref(ab));
diffre = (diffre > 0 ? diffre + 1 : 1);
diffim = (diffim > 0 ? diffim + 1 : 1);
- okre = diffre > wpre ? 0 : mpfr_can_round (mpc_realref(ab),
- wpre - diffre, GMP_RNDN, GMP_RNDZ,
- pre + (MPC_RND_RE (rnd) == GMP_RNDN));
- okim = diffim > wpim ? 0 : mpfr_can_round (mpc_imagref(ab),
- wpim - diffim, GMP_RNDN, GMP_RNDZ,
- pim + (MPC_RND_IM (rnd) == GMP_RNDN));
+ okre = diffre > (mpfr_exp_t) wpre ? 0 : mpfr_can_round (mpc_realref(ab),
+ wpre - diffre, MPFR_RNDN, MPFR_RNDZ,
+ pre + (MPC_RND_RE (rnd) == MPFR_RNDN));
+ okim = diffim > (mpfr_exp_t) wpim ? 0 : mpfr_can_round (mpc_imagref(ab),
+ wpim - diffim, MPFR_RNDN, MPFR_RNDZ,
+ pim + (MPC_RND_IM (rnd) == MPFR_RNDN));
if (okre && okim)
{
inex = mpc_set (r, ab, rnd);
diff --git a/src/fr_div.c b/src/fr_div.c
index e57eced..4c0536f 100644
--- a/src/fr_div.c
+++ b/src/fr_div.c
@@ -1,6 +1,6 @@
/* mpc_fr_div -- Divide a floating-point number by a complex number.
-Copyright (C) 2008, 2009, 2011 INRIA
+Copyright (C) 2008, 2009, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -29,7 +29,7 @@ mpc_fr_div (mpc_ptr a, mpfr_srcptr b, mpc_srcptr c, mpc_rnd_t rnd)
mpc_realref (bc)[0] = b [0];
mpfr_init (mpc_imagref (bc));
/* we consider the operand b to have imaginary part +0 */
- mpfr_set_ui (mpc_imagref (bc), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_imagref (bc), 0, MPFR_RNDN);
inexact = mpc_div (a, bc, c, rnd);
diff --git a/src/get_version.c b/src/get_version.c
index 1c429c0..e3b95a1 100644
--- a/src/get_version.c
+++ b/src/get_version.c
@@ -1,6 +1,6 @@
/* mpc_get_version -- MPC version
-Copyright (C) 2008, 2009, 2010, 2011 INRIA
+Copyright (C) 2008, 2009, 2010, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -20,29 +20,8 @@ along with this program. If not, see http://www.gnu.org/licenses/ .
#include "mpc-impl.h"
-#if MPFR_VERSION_MAJOR < 3
-/* The following are functions defined for compatibility with mpfr < 3;
- logically, they should be defined in a separate file, but then gcc
- complains about an empty translation unit with mpfr >= 3. */
-
-void
-mpfr_set_zero (mpfr_ptr z, int s)
-{
- mpfr_set_ui (z, 0ul, GMP_RNDN);
- if (s < 0)
- mpfr_neg (z, z, GMP_RNDN);
-}
-
-int
-mpfr_regular_p (mpfr_srcptr z)
-{
- return (mpfr_number_p (z) && !mpfr_zero_p (z));
-}
-#endif /* mpfr < 3 */
-
-
const char *
mpc_get_version (void)
{
- return "1.0.0dev";
+ return "1.1dev";
}
diff --git a/src/log.c b/src/log.c
index 2927f68..bfa83fa 100644
--- a/src/log.c
+++ b/src/log.c
@@ -23,12 +23,16 @@ along with this program. If not, see http://www.gnu.org/licenses/ .
int
mpc_log (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd){
- int ok=0;
- mpfr_t w;
+ int ok, underflow = 0;
+ mpfr_srcptr x, y;
+ mpfr_t v, w;
mpfr_prec_t prec;
- int loops = 0;
+ int loops;
int re_cmp, im_cmp;
int inex_re, inex_im;
+ int err;
+ mpfr_exp_t expw;
+ int sgnw;
/* special values: NaN and infinities */
if (!mpc_fin_p (op)) {
@@ -96,7 +100,7 @@ mpc_log (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd){
inex_re = mpfr_log (mpc_realref (rop), mpc_imagref (op), MPC_RND_RE (rnd));
inex_im = mpfr_const_pi (mpc_imagref (rop), MPC_RND_IM (rnd));
/* division by 2 does not change the ternary flag */
- mpfr_div_2ui (mpc_imagref (rop), mpc_imagref (rop), 1, GMP_RNDN);
+ mpfr_div_2ui (mpc_imagref (rop), mpc_imagref (rop), 1, MPFR_RNDN);
}
else {
w [0] = *mpc_imagref (op);
@@ -104,45 +108,110 @@ mpc_log (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd){
inex_re = mpfr_log (mpc_realref (rop), w, MPC_RND_RE (rnd));
inex_im = mpfr_const_pi (mpc_imagref (rop), INV_RND (MPC_RND_IM (rnd)));
/* division by 2 does not change the ternary flag */
- mpfr_div_2ui (mpc_imagref (rop), mpc_imagref (rop), 1, GMP_RNDN);
- mpfr_neg (mpc_imagref (rop), mpc_imagref (rop), GMP_RNDN);
+ mpfr_div_2ui (mpc_imagref (rop), mpc_imagref (rop), 1, MPFR_RNDN);
+ mpfr_neg (mpc_imagref (rop), mpc_imagref (rop), MPFR_RNDN);
inex_im = -inex_im; /* negate the ternary flag */
}
return MPC_INEX(inex_re, inex_im);
}
prec = MPC_PREC_RE(rop);
- mpfr_init2 (w, prec);
- /* let op = x + iy; log = 1/2 log (x^2 + y^2) + i atan2 (y, x) */
- /* loop for the real part: log (x^2 + y^2) */
- do {
- loops ++;
- prec += (loops <= 2) ? mpc_ceil_log2 (prec) + 4 : prec / 2;
+ mpfr_init2 (w, 2);
+ /* let op = x + iy; log = 1/2 log (x^2 + y^2) + i atan2 (y, x) */
+ /* loop for the real part: 1/2 log (x^2 + y^2), fast, but unsafe */
+ /* implementation */
+ ok = 0;
+ for (loops = 1; !ok && loops <= 2; loops++) {
+ prec += mpc_ceil_log2 (prec) + 4;
mpfr_set_prec (w, prec);
- /* w is rounded down */
- mpc_norm (w, op, GMP_RNDD);
- /* error 1 ulp */
- MPC_ASSERT (!mpfr_inf_p (w));
- /* FIXME: intermediate overflow; the logarithm may be representable */
-
- mpfr_log (w, w, GMP_RNDD);
- /* generic error of log: (2^(2 - exp(w)) + 1) ulp */
-
- if (mpfr_get_exp (w) >= 2)
- ok = mpfr_can_round (w, prec - 2, GMP_RNDD,
- MPC_RND_RE(rnd), MPC_PREC_RE(rop));
- else
- ok = mpfr_can_round (w, prec - 3 + mpfr_get_exp (w), GMP_RNDD,
- MPC_RND_RE(rnd), MPC_PREC_RE(rop));
- } while (ok == 0);
+ mpc_abs (w, op, MPFR_RNDN);
+ /* error 0.5 ulp */
+ if (mpfr_inf_p (w))
+ /* intermediate overflow; the logarithm may be representable.
+ Intermediate underflow is impossible. */
+ break;
+
+ mpfr_log (w, w, MPFR_RNDN);
+ /* generic error of log: (2^(- exp(w)) + 0.5) ulp */
+
+ if (mpfr_zero_p (w))
+ /* impossible to round, switch to second algorithm */
+ break;
+
+ err = MPC_MAX (-mpfr_get_exp (w), 0) + 1;
+ /* number of lost digits */
+ ok = mpfr_can_round (w, prec - err, MPFR_RNDN, MPFR_RNDZ,
+ mpfr_get_prec (mpc_realref (rop)) + (MPC_RND_RE (rnd) == MPFR_RNDN));
+ }
+
+ if (!ok) {
+ prec = MPC_PREC_RE(rop);
+ mpfr_init2 (v, 2);
+ /* compute 1/2 log (x^2 + y^2) = log |x| + 1/2 * log (1 + (y/x)^2)
+ if |x| >= |y|; otherwise, exchange x and y */
+ if (mpfr_cmpabs (mpc_realref (op), mpc_imagref (op)) >= 0) {
+ x = mpc_realref (op);
+ y = mpc_imagref (op);
+ }
+ else {
+ x = mpc_imagref (op);
+ y = mpc_realref (op);
+ }
+
+ do {
+ prec += mpc_ceil_log2 (prec) + 4;
+ mpfr_set_prec (v, prec);
+ mpfr_set_prec (w, prec);
+
+ mpfr_div (v, y, x, MPFR_RNDD); /* error 1 ulp */
+ mpfr_sqr (v, v, MPFR_RNDD);
+ /* generic error of multiplication:
+ 1 + 2*1*(2+1*2^(1-prec)) <= 5.0625 since prec >= 6 */
+ mpfr_log1p (v, v, MPFR_RNDD);
+ /* error 1 + 4*5.0625 = 21.25 , see algorithms.tex */
+ mpfr_div_2ui (v, v, 1, MPFR_RNDD);
+ /* If the result is 0, then there has been an underflow somewhere. */
+
+ mpfr_abs (w, x, MPFR_RNDN); /* exact */
+ mpfr_log (w, w, MPFR_RNDN); /* error 0.5 ulp */
+ expw = mpfr_get_exp (w);
+ sgnw = mpfr_signbit (w);
+
+ mpfr_add (w, w, v, MPFR_RNDN);
+ if (!sgnw) /* v is positive, so no cancellation;
+ error 22.25 ulp; error counts lost bits */
+ err = 5;
+ else
+ err = MPC_MAX (5 + mpfr_get_exp (v),
+ /* 21.25 ulp (v) rewritten in ulp (result, now in w) */
+ -1 + expw - mpfr_get_exp (w)
+ /* 0.5 ulp (previous w), rewritten in ulp (result) */
+ ) + 2;
+
+ /* handle one special case: |x|=1, and (y/x)^2 underflows;
+ then 1/2*log(x^2+y^2) \approx 1/2*y^2 also underflows. */
+ if ( (mpfr_cmp_si (x, -1) == 0 || mpfr_cmp_ui (x, 1) == 0)
+ && mpfr_zero_p (w))
+ underflow = 1;
+
+ } while (!underflow &&
+ !mpfr_can_round (w, prec - err, MPFR_RNDN, MPFR_RNDZ,
+ mpfr_get_prec (mpc_realref (rop)) + (MPC_RND_RE (rnd) == MPFR_RNDN)));
+ mpfr_clear (v);
+ }
/* imaginary part */
inex_im = mpfr_atan2 (mpc_imagref (rop), mpc_imagref (op), mpc_realref (op),
MPC_RND_IM (rnd));
- /* set the real part; cannot be done before when rop==op */
- inex_re = mpfr_div_2ui (mpc_realref(rop), w, 1ul, MPC_RND_RE (rnd));
+ /* set the real part; cannot be done before if rop==op */
+ if (underflow)
+ /* create underflow in result */
+ inex_re = mpfr_set_ui_2exp (mpc_realref (rop), 1,
+ mpfr_get_emin_min () - 2, MPC_RND_RE (rnd));
+ else
+ inex_re = mpfr_set (mpc_realref (rop), w, MPC_RND_RE (rnd));
mpfr_clear (w);
return MPC_INEX(inex_re, inex_im);
}
diff --git a/src/log10.c b/src/log10.c
index e5972cc..6b7e687 100644
--- a/src/log10.c
+++ b/src/log10.c
@@ -39,8 +39,8 @@ mpc_log10_aux (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd, int flag, int nb)
mpfr_init2 (log10, prec);
while (ok == 0)
{
- mpfr_set_ui (log10, 10, GMP_RNDN); /* exact since prec >= 4 */
- mpfr_log (log10, log10, GMP_RNDN);
+ mpfr_set_ui (log10, 10, MPFR_RNDN); /* exact since prec >= 4 */
+ mpfr_log (log10, log10, MPFR_RNDN);
/* In each case we have two roundings, thus the final value is
x * (1+u)^2 where x is the exact value, and |u| <= 2^(-prec-1).
Thus the error is always less than 3 ulps. */
@@ -49,40 +49,40 @@ mpc_log10_aux (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd, int flag, int nb)
case 0: /* imag <- atan2(y/x) */
mpfr_atan2 (mpc_imagref (tmp), mpc_imagref (op), mpc_realref (op),
MPC_RND_IM (rnd));
- mpfr_div (mpc_imagref (tmp), mpc_imagref (tmp), log10, GMP_RNDN);
- ok = mpfr_can_round (mpc_imagref (tmp), prec - 2, GMP_RNDN,
- GMP_RNDZ, MPC_PREC_IM(rop) +
- (MPC_RND_IM (rnd) == GMP_RNDN));
+ mpfr_div (mpc_imagref (tmp), mpc_imagref (tmp), log10, MPFR_RNDN);
+ ok = mpfr_can_round (mpc_imagref (tmp), prec - 2, MPFR_RNDN,
+ MPFR_RNDZ, MPC_PREC_IM(rop) +
+ (MPC_RND_IM (rnd) == MPFR_RNDN));
if (ok)
ret = mpfr_set (mpc_imagref (rop), mpc_imagref (tmp),
MPC_RND_IM (rnd));
break;
case 1: /* real <- log(x) */
mpfr_log (mpc_realref (tmp), mpc_realref (op), MPC_RND_RE (rnd));
- mpfr_div (mpc_realref (tmp), mpc_realref (tmp), log10, GMP_RNDN);
- ok = mpfr_can_round (mpc_realref (tmp), prec - 2, GMP_RNDN,
- GMP_RNDZ, MPC_PREC_RE(rop) +
- (MPC_RND_RE (rnd) == GMP_RNDN));
+ mpfr_div (mpc_realref (tmp), mpc_realref (tmp), log10, MPFR_RNDN);
+ ok = mpfr_can_round (mpc_realref (tmp), prec - 2, MPFR_RNDN,
+ MPFR_RNDZ, MPC_PREC_RE(rop) +
+ (MPC_RND_RE (rnd) == MPFR_RNDN));
if (ok)
ret = mpfr_set (mpc_realref (rop), mpc_realref (tmp),
MPC_RND_RE (rnd));
break;
case 2: /* imag <- pi */
mpfr_const_pi (mpc_imagref (tmp), MPC_RND_IM (rnd));
- mpfr_div (mpc_imagref (tmp), mpc_imagref (tmp), log10, GMP_RNDN);
- ok = mpfr_can_round (mpc_imagref (tmp), prec - 2, GMP_RNDN,
- GMP_RNDZ, MPC_PREC_IM(rop) +
- (MPC_RND_IM (rnd) == GMP_RNDN));
+ mpfr_div (mpc_imagref (tmp), mpc_imagref (tmp), log10, MPFR_RNDN);
+ ok = mpfr_can_round (mpc_imagref (tmp), prec - 2, MPFR_RNDN,
+ MPFR_RNDZ, MPC_PREC_IM(rop) +
+ (MPC_RND_IM (rnd) == MPFR_RNDN));
if (ok)
ret = mpfr_set (mpc_imagref (rop), mpc_imagref (tmp),
MPC_RND_IM (rnd));
break;
case 3: /* real <- log(y) */
mpfr_log (mpc_realref (tmp), mpc_imagref (op), MPC_RND_RE (rnd));
- mpfr_div (mpc_realref (tmp), mpc_realref (tmp), log10, GMP_RNDN);
- ok = mpfr_can_round (mpc_realref (tmp), prec - 2, GMP_RNDN,
- GMP_RNDZ, MPC_PREC_RE(rop) +
- (MPC_RND_RE (rnd) == GMP_RNDN));
+ mpfr_div (mpc_realref (tmp), mpc_realref (tmp), log10, MPFR_RNDN);
+ ok = mpfr_can_round (mpc_realref (tmp), prec - 2, MPFR_RNDN,
+ MPFR_RNDZ, MPC_PREC_RE(rop) +
+ (MPC_RND_RE (rnd) == MPFR_RNDN));
if (ok)
ret = mpfr_set (mpc_realref (rop), mpc_realref (tmp),
MPC_RND_RE (rnd));
@@ -184,7 +184,7 @@ mpc_log10 (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
inex_re = mpfr_set_ui (mpc_realref (rop), 0, MPC_RND_RE (rnd));
else
inex_re = mpc_log10_aux (rop, ww, rnd, 0, 1);
- inex_im = mpc_log10_aux (rop, op, RNDC(0,rnd_im), 1, 2);
+ inex_im = mpc_log10_aux (rop, op, MPC_RND (0,rnd_im), 1, 2);
if (negative_zero)
{
mpc_conj (rop, rop, MPC_RNDNN);
@@ -200,7 +200,7 @@ mpc_log10 (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
inex_re = mpc_log10_aux (rop, op, rnd, 0, 3);
inex_im = mpc_log10_aux (rop, op, rnd, 1, 2);
/* division by 2 does not change the ternary flag */
- mpfr_div_2ui (mpc_imagref (rop), mpc_imagref (rop), 1, GMP_RNDN);
+ mpfr_div_2ui (mpc_imagref (rop), mpc_imagref (rop), 1, MPFR_RNDN);
}
else
{
@@ -208,11 +208,11 @@ mpc_log10 (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
ww->im[0] = *mpc_imagref (op);
MPFR_CHANGE_SIGN (ww->im);
inex_re = mpc_log10_aux (rop, ww, rnd, 0, 3);
- invrnd = RNDC(0, INV_RND (MPC_RND_IM (rnd)));
+ invrnd = MPC_RND (0, INV_RND (MPC_RND_IM (rnd)));
inex_im = mpc_log10_aux (rop, op, invrnd, 1, 2);
/* division by 2 does not change the ternary flag */
- mpfr_div_2ui (mpc_imagref (rop), mpc_imagref (rop), 1, GMP_RNDN);
- mpfr_neg (mpc_imagref (rop), mpc_imagref (rop), GMP_RNDN);
+ mpfr_div_2ui (mpc_imagref (rop), mpc_imagref (rop), 1, MPFR_RNDN);
+ mpfr_neg (mpc_imagref (rop), mpc_imagref (rop), MPFR_RNDN);
inex_im = -inex_im; /* negate the ternary flag */
}
return MPC_INEX(inex_re, inex_im);
@@ -231,12 +231,12 @@ mpc_log10 (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
mpc_set_prec (ww, prec);
mpc_log (ww, op, MPC_RNDNN);
- mpfr_set_ui (w, 10, GMP_RNDN); /* exact since prec >= 4 */
- mpfr_log (w, w, GMP_RNDN);
+ mpfr_set_ui (w, 10, MPFR_RNDN); /* exact since prec >= 4 */
+ mpfr_log (w, w, MPFR_RNDN);
mpc_div_fr (ww, ww, w, MPC_RNDNN);
- ok = mpfr_can_round (mpc_realref (ww), prec - 2, GMP_RNDN, GMP_RNDZ,
- MPC_PREC_RE(rop) + (MPC_RND_RE (rnd) == GMP_RNDN));
+ ok = mpfr_can_round (mpc_realref (ww), prec - 2, MPFR_RNDN, MPFR_RNDZ,
+ MPC_PREC_RE(rop) + (MPC_RND_RE (rnd) == MPFR_RNDN));
/* Special code to deal with cases where the real part of log10(x+i*y)
is exact, like x=3 and y=1. Since Re(log10(x+i*y)) = log10(x^2+y^2)/2
@@ -254,39 +254,39 @@ mpc_log10 (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
mpfr_integer_p (mpc_imagref (op)))
{
mpz_t x, y;
- unsigned long s;
+ unsigned long s, v;
mpz_init (x);
mpz_init (y);
- mpfr_get_z (x, mpc_realref (op), GMP_RNDN); /* exact */
- mpfr_get_z (y, mpc_imagref (op), GMP_RNDN); /* exact */
+ mpfr_get_z (x, mpc_realref (op), MPFR_RNDN); /* exact */
+ mpfr_get_z (y, mpc_imagref (op), MPFR_RNDN); /* exact */
mpz_mul (x, x, x);
mpz_mul (y, y, y);
mpz_add (x, x, y); /* x^2+y^2 */
- s = mpz_sizeinbase (x, 10); /* always exact or 1 too big */
- /* since s is the number of digits of x in base 10 (or one more),
- we subtract 1 since we want to check whether x = 10^s */
- s --;
- mpz_ui_pow_ui (y, 10, s);
- if (mpz_cmp (y, x) > 0) /* might be 1 too big */
+ v = mpz_scan1 (x, 0);
+ /* if x = 10^s then necessarily s = v */
+ s = mpz_sizeinbase (x, 10);
+ /* since s is either the number of digits of x or one more,
+ then x = 10^(s-1) or 10^(s-2) */
+ if (s == v + 1 || s == v + 2)
{
- mpz_divexact_ui (y, y, 10);
- s --;
- }
- if (mpz_cmp (y, x) == 0) /* Re(log10(x+i*y)) is exactly s/2 */
- {
- /* we reset the precision of Re(ww) so that s can be
- represented exactly */
- mpfr_set_prec (mpc_realref (ww), sizeof(unsigned long)*CHAR_BIT);
- mpfr_set_ui_2exp (mpc_realref (ww), s, -1, GMP_RNDN); /* exact */
- ok = 1;
+ mpz_div_2exp (x, x, v);
+ mpz_ui_pow_ui (y, 5, v);
+ if (mpz_cmp (y, x) == 0) /* Re(log10(x+i*y)) is exactly v/2 */
+ {
+ /* we reset the precision of Re(ww) so that v can be
+ represented exactly */
+ mpfr_set_prec (mpc_realref (ww), sizeof(unsigned long)*CHAR_BIT);
+ mpfr_set_ui_2exp (mpc_realref (ww), v, -1, MPFR_RNDN); /* exact */
+ ok = 1;
+ }
}
mpz_clear (x);
mpz_clear (y);
}
- ok = ok && mpfr_can_round (mpc_imagref (ww), prec-2, GMP_RNDN, GMP_RNDZ,
- MPC_PREC_IM(rop) + (MPC_RND_IM (rnd) == GMP_RNDN));
+ ok = ok && mpfr_can_round (mpc_imagref (ww), prec-2, MPFR_RNDN, MPFR_RNDZ,
+ MPC_PREC_IM(rop) + (MPC_RND_IM (rnd) == MPFR_RNDN));
}
inex_re = mpfr_set (mpc_realref(rop), mpc_realref (ww), MPC_RND_RE (rnd));
diff --git a/src/mpc-impl.h b/src/mpc-impl.h
index c3ca9af..5664955 100644
--- a/src/mpc-impl.h
+++ b/src/mpc-impl.h
@@ -55,46 +55,18 @@ along with this program. If not, see http://www.gnu.org/licenses/ .
#define MPFR_SIGNBIT(x) (mpfr_signbit (x) ? -1 : 1)
#define MPC_MPFR_SIGN(x) (mpfr_zero_p (x) ? 0 : MPFR_SIGNBIT (x))
/* should be called MPFR_SIGN, but this is taken in mpfr.h */
-#define MPFR_CHANGE_SIGN(x) mpfr_neg(x,x,GMP_RNDN)
+#define MPFR_CHANGE_SIGN(x) mpfr_neg(x,x,MPFR_RNDN)
#define MPFR_COPYSIGN(x,y,z,rnd) (mpfr_nan_p (z) ? \
mpfr_setsign (x, y, 0, rnd) : \
mpfr_copysign (x, y, z, rnd))
/* work around spurious signs in nan */
-#define MPFR_ADD_ONE_ULP(x) mpfr_add_one_ulp (x, GMP_RNDN)
-#define MPFR_SUB_ONE_ULP(x) mpfr_sub_one_ulp (x, GMP_RNDN)
+#define MPFR_ADD_ONE_ULP(x) mpfr_add_one_ulp (x, MPFR_RNDN)
+#define MPFR_SUB_ONE_ULP(x) mpfr_sub_one_ulp (x, MPFR_RNDN)
/* drop unused rounding mode from macroes */
#define MPFR_SWAP(a,b) do { mpfr_srcptr tmp; tmp = a; a = b; b = tmp; } while (0)
/*
- * Macro implementing rounding away from zero, to ease compatibility with
- * mpfr < 3. f is the complete function call with a rounding mode of
- * MPFR_RNDA, rop the name of the variable containing the result; it is
- * already contained in f, but needs to be repeated so that the macro can
- * modify the variable.
- * Usage: replace each call to a function such as
- * mpfr_add (rop, a, b, MPFR_RNDA)
- * by
- * ROUND_AWAY (mpfr_add (rop, a, b, MPFR_RNDA), rop)
-*/
-#if MPFR_VERSION_MAJOR < 3
- /* round towards zero, add 1 ulp if not exact */
-#define MPFR_RNDA GMP_RNDZ
-#define ROUND_AWAY(f,rop) \
- ((f) ? MPFR_ADD_ONE_ULP (rop), MPFR_SIGNBIT (rop) : 0)
-#else
-#define ROUND_AWAY(f,rop) \
- (f)
-#endif /* mpfr < 3 */
-
-#if MPFR_VERSION_MAJOR < 3
-/* declare missing functions, defined in get_version.c */
-__MPC_DECLSPEC void mpfr_set_zero (mpfr_ptr, int);
-__MPC_DECLSPEC int mpfr_regular_p (mpfr_srcptr);
-#endif /* mpfr < 3 */
-
-
-/*
* MPC macros
*/
@@ -103,7 +75,7 @@ __MPC_DECLSPEC int mpfr_regular_p (mpfr_srcptr);
#define MPC_MAX_PREC(x) MPC_MAX(MPC_PREC_RE(x), MPC_PREC_IM(x))
#define INV_RND(r) \
- (((r) == GMP_RNDU) ? GMP_RNDD : (((r) == GMP_RNDD) ? GMP_RNDU : (r)))
+ (((r) == MPFR_RNDU) ? MPFR_RNDD : (((r) == MPFR_RNDD) ? MPFR_RNDU : (r)))
#define mpc_inf_p(z) (mpfr_inf_p(mpc_realref(z))||mpfr_inf_p(mpc_imagref(z)))
/* Convention in C99 (G.3): z is regarded as an infinity if at least one of
@@ -137,6 +109,27 @@ __MPC_DECLSPEC int mpfr_regular_p (mpfr_srcptr);
} while (0)
#endif
+
+/*
+ * Debug macros
+ */
+
+#define MPC_OUT(x) \
+do { \
+ printf (#x "[%lu,%lu]=", (unsigned long int) MPC_PREC_RE (x), \
+ (unsigned long int) MPC_PREC_IM (x)); \
+ mpc_out_str (stdout, 2, 0, x, MPC_RNDNN); \
+ printf ("\n"); \
+} while (0)
+
+#define MPFR_OUT(x) \
+do { \
+ printf (#x "[%lu]=", (unsigned long int) mpfr_get_prec (x)); \
+ mpfr_out_str (stdout, 2, 0, x, MPFR_RNDN); \
+ printf ("\n"); \
+} while (0)
+
+
/*
* Constants
*/
diff --git a/src/mpc.h b/src/mpc.h
index 179ca29..044176d 100644
--- a/src/mpc.h
+++ b/src/mpc.h
@@ -24,16 +24,11 @@ along with this program. If not, see http://www.gnu.org/licenses/ .
#include "gmp.h"
#include "mpfr.h"
-/* Backwards compatibility with mpfr<3.0.0 */
-#ifndef mpfr_exp_t
-#define mpfr_exp_t mp_exp_t
-#endif
-
/* Define MPC version number */
#define MPC_VERSION_MAJOR 1
-#define MPC_VERSION_MINOR 0
+#define MPC_VERSION_MINOR 1
#define MPC_VERSION_PATCHLEVEL 0
-#define MPC_VERSION_STRING "1.0.0dev"
+#define MPC_VERSION_STRING "1.1dev"
/* Macros dealing with MPC VERSION */
#define MPC_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
@@ -74,29 +69,29 @@ along with this program. If not, see http://www.gnu.org/licenses/ .
we reserve four bits for a real rounding mode. */
typedef int mpc_rnd_t;
-#define RNDC(r1,r2) (((int)(r1)) + ((int)(r2) << 4))
+#define MPC_RND(r1,r2) (((int)(r1)) + ((int)(r2) << 4))
#define MPC_RND_RE(x) ((mpfr_rnd_t)((x) & 0x0F))
#define MPC_RND_IM(x) ((mpfr_rnd_t)((x) >> 4))
-#define MPC_RNDNN RNDC(GMP_RNDN,GMP_RNDN)
-#define MPC_RNDNZ RNDC(GMP_RNDN,GMP_RNDZ)
-#define MPC_RNDNU RNDC(GMP_RNDN,GMP_RNDU)
-#define MPC_RNDND RNDC(GMP_RNDN,GMP_RNDD)
+#define MPC_RNDNN MPC_RND (MPFR_RNDN,MPFR_RNDN)
+#define MPC_RNDNZ MPC_RND (MPFR_RNDN,MPFR_RNDZ)
+#define MPC_RNDNU MPC_RND (MPFR_RNDN,MPFR_RNDU)
+#define MPC_RNDND MPC_RND (MPFR_RNDN,MPFR_RNDD)
-#define MPC_RNDZN RNDC(GMP_RNDZ,GMP_RNDN)
-#define MPC_RNDZZ RNDC(GMP_RNDZ,GMP_RNDZ)
-#define MPC_RNDZU RNDC(GMP_RNDZ,GMP_RNDU)
-#define MPC_RNDZD RNDC(GMP_RNDZ,GMP_RNDD)
+#define MPC_RNDZN MPC_RND (MPFR_RNDZ,MPFR_RNDN)
+#define MPC_RNDZZ MPC_RND (MPFR_RNDZ,MPFR_RNDZ)
+#define MPC_RNDZU MPC_RND (MPFR_RNDZ,MPFR_RNDU)
+#define MPC_RNDZD MPC_RND (MPFR_RNDZ,MPFR_RNDD)
-#define MPC_RNDUN RNDC(GMP_RNDU,GMP_RNDN)
-#define MPC_RNDUZ RNDC(GMP_RNDU,GMP_RNDZ)
-#define MPC_RNDUU RNDC(GMP_RNDU,GMP_RNDU)
-#define MPC_RNDUD RNDC(GMP_RNDU,GMP_RNDD)
+#define MPC_RNDUN MPC_RND (MPFR_RNDU,MPFR_RNDN)
+#define MPC_RNDUZ MPC_RND (MPFR_RNDU,MPFR_RNDZ)
+#define MPC_RNDUU MPC_RND (MPFR_RNDU,MPFR_RNDU)
+#define MPC_RNDUD MPC_RND (MPFR_RNDU,MPFR_RNDD)
-#define MPC_RNDDN RNDC(GMP_RNDD,GMP_RNDN)
-#define MPC_RNDDZ RNDC(GMP_RNDD,GMP_RNDZ)
-#define MPC_RNDDU RNDC(GMP_RNDD,GMP_RNDU)
-#define MPC_RNDDD RNDC(GMP_RNDD,GMP_RNDD)
+#define MPC_RNDDN MPC_RND (MPFR_RNDD,MPFR_RNDN)
+#define MPC_RNDDZ MPC_RND (MPFR_RNDD,MPFR_RNDZ)
+#define MPC_RNDDU MPC_RND (MPFR_RNDD,MPFR_RNDU)
+#define MPC_RNDDD MPC_RND (MPFR_RNDD,MPFR_RNDD)
/* Definitions of types and their semantics */
@@ -151,8 +146,10 @@ __MPC_DECLSPEC int mpc_div_fr (mpc_ptr, mpc_srcptr, mpfr_srcptr, mpc_rnd_t);
__MPC_DECLSPEC int mpc_fr_div (mpc_ptr, mpfr_srcptr, mpc_srcptr, mpc_rnd_t);
__MPC_DECLSPEC int mpc_div_ui (mpc_ptr, mpc_srcptr, unsigned long int, mpc_rnd_t);
__MPC_DECLSPEC int mpc_ui_div (mpc_ptr, unsigned long int, mpc_srcptr, mpc_rnd_t);
-__MPC_DECLSPEC int mpc_div_2exp (mpc_ptr, mpc_srcptr, unsigned long int, mpc_rnd_t);
-__MPC_DECLSPEC int mpc_mul_2exp (mpc_ptr, mpc_srcptr, unsigned long int, mpc_rnd_t);
+__MPC_DECLSPEC int mpc_div_2ui (mpc_ptr, mpc_srcptr, unsigned long int, mpc_rnd_t);
+__MPC_DECLSPEC int mpc_mul_2ui (mpc_ptr, mpc_srcptr, unsigned long int, mpc_rnd_t);
+__MPC_DECLSPEC int mpc_div_2si (mpc_ptr, mpc_srcptr, long int, mpc_rnd_t);
+__MPC_DECLSPEC int mpc_mul_2si (mpc_ptr, mpc_srcptr, long int, mpc_rnd_t);
__MPC_DECLSPEC int mpc_conj (mpc_ptr, mpc_srcptr, mpc_rnd_t);
__MPC_DECLSPEC int mpc_neg (mpc_ptr, mpc_srcptr, mpc_rnd_t);
__MPC_DECLSPEC int mpc_norm (mpfr_ptr, mpc_srcptr, mpfr_rnd_t);
diff --git a/src/mul.c b/src/mul.c
index 2be9b8d..3927888 100644
--- a/src/mul.c
+++ b/src/mul.c
@@ -125,11 +125,11 @@ mul_real (mpc_ptr z, mpc_srcptr x, mpc_srcptr y, mpc_rnd_t rnd)
/* Signs of zeroes may be wrong. Their correction does not change the
inexact flag. */
if (mpfr_zero_p (mpc_realref (z)))
- mpfr_setsign (mpc_realref (z), mpc_realref (z), MPC_RND_RE(rnd) == GMP_RNDD
- || (xrs != yrs && xis == yis), GMP_RNDN);
+ mpfr_setsign (mpc_realref (z), mpc_realref (z), MPC_RND_RE(rnd) == MPFR_RNDD
+ || (xrs != yrs && xis == yis), MPFR_RNDN);
if (mpfr_zero_p (mpc_imagref (z)))
- mpfr_setsign (mpc_imagref (z), mpc_imagref (z), MPC_RND_IM (rnd) == GMP_RNDD
- || (xrs != yis && xis != yrs), GMP_RNDN);
+ mpfr_setsign (mpc_imagref (z), mpc_imagref (z), MPC_RND_IM (rnd) == MPFR_RNDD
+ || (xrs != yis && xis != yrs), MPFR_RNDN);
return inex;
}
@@ -154,15 +154,15 @@ mul_imag (mpc_ptr z, mpc_srcptr x, mpc_srcptr y, mpc_rnd_t rnd)
inex_re = -mpfr_mul (mpc_realref (rop), mpc_imagref (x), mpc_imagref (y),
INV_RND (MPC_RND_RE (rnd)));
- mpfr_neg (mpc_realref (rop), mpc_realref (rop), GMP_RNDN); /* exact */
+ mpfr_neg (mpc_realref (rop), mpc_realref (rop), MPFR_RNDN); /* exact */
inex_im = mpfr_mul (mpc_imagref (rop), mpc_realref (x), mpc_imagref (y),
MPC_RND_IM (rnd));
mpc_set (z, rop, MPC_RNDNN);
/* Sign of zeroes may be wrong (note that Re(z) cannot be zero) */
if (mpfr_zero_p (mpc_imagref (z)))
- mpfr_setsign (mpc_imagref (z), mpc_imagref (z), MPC_RND_IM (rnd) == GMP_RNDD
- || sign, GMP_RNDN);
+ mpfr_setsign (mpc_imagref (z), mpc_imagref (z), MPC_RND_IM (rnd) == MPFR_RNDD
+ || sign, MPFR_RNDN);
if (overlap)
mpc_clear (rop);
@@ -187,10 +187,10 @@ mpfr_fmma (mpfr_ptr z, mpfr_srcptr a, mpfr_srcptr b, mpfr_srcptr c,
/* u=a*b, v=sign*c*d exactly */
mpfr_init2 (u, mpfr_get_prec (a) + mpfr_get_prec (b));
mpfr_init2 (v, mpfr_get_prec (c) + mpfr_get_prec (d));
- mpfr_mul (u, a, b, GMP_RNDN);
- mpfr_mul (v, c, d, GMP_RNDN);
+ mpfr_mul (u, a, b, MPFR_RNDN);
+ mpfr_mul (v, c, d, MPFR_RNDN);
if (sign < 0)
- mpfr_neg (v, v, GMP_RNDN);
+ mpfr_neg (v, v, MPFR_RNDN);
/* tentatively compute z as u+v; here we need z to be distinct
from a, b, c, d to not lose the latter */
@@ -198,7 +198,7 @@ mpfr_fmma (mpfr_ptr z, mpfr_srcptr a, mpfr_srcptr b, mpfr_srcptr c,
if (mpfr_inf_p (z)) {
/* replace by "correctly rounded overflow" */
- mpfr_set_si (z, (mpfr_signbit (z) ? -1 : 1), GMP_RNDN);
+ mpfr_set_si (z, (mpfr_signbit (z) ? -1 : 1), MPFR_RNDN);
inex = mpfr_mul_2ui (z, z, mpfr_get_emax (), rnd);
}
else if (mpfr_zero_p (u) && !mpfr_zero_p (v)) {
@@ -238,13 +238,13 @@ mpfr_fmma (mpfr_ptr z, mpfr_srcptr a, mpfr_srcptr b, mpfr_srcptr c,
mpz_add_si (ev, ev, (long int) ed);
/* recompute u and v and move exponents to eu and ev */
- mpfr_mul (u, a, b, GMP_RNDN);
+ mpfr_mul (u, a, b, MPFR_RNDN);
/* exponent of u is non-positive */
mpz_sub_ui (eu, eu, (unsigned long int) (-mpfr_get_exp (u)));
mpfr_set_exp (u, (mpfr_prec_t) 0);
- mpfr_mul (v, c, d, GMP_RNDN);
+ mpfr_mul (v, c, d, MPFR_RNDN);
if (sign < 0)
- mpfr_neg (v, v, GMP_RNDN);
+ mpfr_neg (v, v, MPFR_RNDN);
mpz_sub_ui (ev, ev, (unsigned long int) (-mpfr_get_exp (v)));
mpfr_set_exp (v, (mpfr_prec_t) 0);
@@ -426,23 +426,23 @@ mpc_mul_karatsuba (mpc_ptr rop, mpc_srcptr op1, mpc_srcptr op2, mpc_rnd_t rnd)
mpfr_init2 (u, 2);
mpfr_init2 (x, 2);
- inexact = mpfr_mul (v, a, d, GMP_RNDN);
+ inexact = mpfr_mul (v, a, d, MPFR_RNDN);
if (inexact) {
/* over- or underflow */
ok = 0;
goto clear;
}
if (mul_a == -1)
- mpfr_neg (v, v, GMP_RNDN);
+ mpfr_neg (v, v, MPFR_RNDN);
- inexact = mpfr_mul (w, b, c, GMP_RNDN);
+ inexact = mpfr_mul (w, b, c, MPFR_RNDN);
if (inexact) {
/* over- or underflow */
ok = 0;
goto clear;
}
if (mul_c == -1)
- mpfr_neg (w, w, GMP_RNDN);
+ mpfr_neg (w, w, MPFR_RNDN);
/* compute sign(v-w) */
sign_x = mpfr_cmp_abs (v, w);
@@ -477,21 +477,21 @@ mpc_mul_karatsuba (mpc_ptr rop, mpc_srcptr op1, mpc_srcptr op2, mpc_rnd_t rnd)
/* first compute away(b +/- a) and store it in u */
inexact = (mul_a == -1 ?
- ROUND_AWAY (mpfr_sub (u, b, a, MPFR_RNDA), u) :
- ROUND_AWAY (mpfr_add (u, b, a, MPFR_RNDA), u));
+ mpfr_sub (u, b, a, MPFR_RNDA) :
+ mpfr_add (u, b, a, MPFR_RNDA));
/* then compute away(+/-c - d) and store it in x */
inexact |= (mul_c == -1 ?
- ROUND_AWAY (mpfr_add (x, c, d, MPFR_RNDA), x) :
- ROUND_AWAY (mpfr_sub (x, c, d, MPFR_RNDA), x));
+ mpfr_add (x, c, d, MPFR_RNDA) :
+ mpfr_sub (x, c, d, MPFR_RNDA));
if (mul_c == -1)
- mpfr_neg (x, x, GMP_RNDN);
+ mpfr_neg (x, x, MPFR_RNDN);
if (inexact == 0)
- mpfr_prec_round (u, prec_u = 2 * prec, GMP_RNDN);
+ mpfr_prec_round (u, prec_u = 2 * prec, MPFR_RNDN);
/* compute away(u*x) and store it in u */
- inexact |= ROUND_AWAY (mpfr_mul (u, u, x, MPFR_RNDA), u);
+ inexact |= mpfr_mul (u, u, x, MPFR_RNDA);
/* (a+b)*(c-d) */
/* if all computations are exact up to here, it may be that
@@ -508,20 +508,20 @@ mpc_mul_karatsuba (mpc_ptr rop, mpc_srcptr op1, mpc_srcptr op2, mpc_rnd_t rnd)
if (prec_x > prec_u)
prec_x = prec_u;
if (prec_x > prec)
- mpfr_prec_round (x, prec_x, GMP_RNDN);
+ mpfr_prec_round (x, prec_x, MPFR_RNDN);
}
- rnd_u = (sign_u > 0) ? GMP_RNDU : GMP_RNDD;
+ rnd_u = (sign_u > 0) ? MPFR_RNDU : MPFR_RNDD;
inexact |= mpfr_sub (x, v, w, rnd_u); /* ad - bc */
/* in case u=0, ensure that rnd_u rounds x away from zero */
if (mpfr_sgn (u) == 0)
- rnd_u = (mpfr_sgn (x) > 0) ? GMP_RNDU : GMP_RNDD;
+ rnd_u = (mpfr_sgn (x) > 0) ? MPFR_RNDU : MPFR_RNDD;
inexact |= mpfr_add (u, u, x, rnd_u); /* ac - bd */
ok = inexact == 0 ||
- mpfr_can_round (u, prec_u - 3, rnd_u, GMP_RNDZ,
- prec_re + (rnd_re == GMP_RNDN));
+ mpfr_can_round (u, prec_u - 3, rnd_u, MPFR_RNDZ,
+ prec_re + (rnd_re == MPFR_RNDN));
/* this ensures both we can round correctly and determine the correct
inexact flag (for rounding to nearest) */
}
diff --git a/src/mul_2si.c b/src/mul_2si.c
new file mode 100644
index 0000000..14d0ca2
--- /dev/null
+++ b/src/mul_2si.c
@@ -0,0 +1,32 @@
+/* mpc_mul_2si -- Multiply a complex number by 2^e.
+
+Copyright (C) 2012 INRIA
+
+This file is part of GNU MPC.
+
+GNU MPC 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 3 of the License, or (at your
+option) any later version.
+
+GNU MPC 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 this program. If not, see http://www.gnu.org/licenses/ .
+*/
+
+#include "mpc-impl.h"
+
+int
+mpc_mul_2si (mpc_ptr a, mpc_srcptr b, long int c, mpc_rnd_t rnd)
+{
+ int inex_re, inex_im;
+
+ inex_re = mpfr_mul_2si (mpc_realref(a), mpc_realref(b), c, MPC_RND_RE(rnd));
+ inex_im = mpfr_mul_2si (mpc_imagref(a), mpc_imagref(b), c, MPC_RND_IM(rnd));
+
+ return MPC_INEX(inex_re, inex_im);
+}
diff --git a/src/mul_2ui.c b/src/mul_2ui.c
new file mode 100644
index 0000000..46aa788
--- /dev/null
+++ b/src/mul_2ui.c
@@ -0,0 +1,32 @@
+/* mpc_mul_2ui -- Multiply a complex number by 2^e.
+
+Copyright (C) 2002, 2009, 2011, 2012 INRIA
+
+This file is part of GNU MPC.
+
+GNU MPC 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 3 of the License, or (at your
+option) any later version.
+
+GNU MPC 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 this program. If not, see http://www.gnu.org/licenses/ .
+*/
+
+#include "mpc-impl.h"
+
+int
+mpc_mul_2ui (mpc_ptr a, mpc_srcptr b, unsigned long int c, mpc_rnd_t rnd)
+{
+ int inex_re, inex_im;
+
+ inex_re = mpfr_mul_2ui (mpc_realref(a), mpc_realref(b), c, MPC_RND_RE(rnd));
+ inex_im = mpfr_mul_2ui (mpc_imagref(a), mpc_imagref(b), c, MPC_RND_IM(rnd));
+
+ return MPC_INEX(inex_re, inex_im);
+}
diff --git a/src/mul_fr.c b/src/mul_fr.c
index bd3574d..437b3ca 100644
--- a/src/mul_fr.c
+++ b/src/mul_fr.c
@@ -1,6 +1,6 @@
/* mpc_mul_fr -- Multiply a complex number by a floating-point number.
-Copyright (C) 2002, 2008, 2009, 2010, 2011 INRIA
+Copyright (C) 2002, 2008, 2009, 2010, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -34,7 +34,7 @@ mpc_mul_fr (mpc_ptr a, mpc_srcptr b, mpfr_srcptr c, mpc_rnd_t rnd)
inex_re = mpfr_mul (real, mpc_realref(b), c, MPC_RND_RE(rnd));
inex_im = mpfr_mul (mpc_imagref(a), mpc_imagref(b), c, MPC_RND_IM(rnd));
- mpfr_set (mpc_realref (a), real, GMP_RNDN); /* exact */
+ mpfr_set (mpc_realref (a), real, MPFR_RNDN); /* exact */
if (c == mpc_realref (a))
mpfr_clear (real);
diff --git a/src/mul_i.c b/src/mul_i.c
index 591b0c6..511b051 100644
--- a/src/mul_i.c
+++ b/src/mul_i.c
@@ -1,6 +1,6 @@
/* mpc_mul_i -- Multiply a complex number by plus or minus i.
-Copyright (C) 2005, 2009, 2010, 2011 INRIA
+Copyright (C) 2005, 2009, 2010, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -35,8 +35,8 @@ mpc_mul_i (mpc_ptr a, mpc_srcptr b, int sign, mpc_rnd_t rnd)
mpfr_swap (mpc_realref (a), mpc_imagref (a));
else
{
- mpfr_set (mpc_realref (a), mpc_imagref (b), GMP_RNDN);
- mpfr_set (mpc_imagref (a), mpc_realref (b), GMP_RNDN);
+ mpfr_set (mpc_realref (a), mpc_imagref (b), MPFR_RNDN);
+ mpfr_set (mpc_imagref (a), mpc_realref (b), MPFR_RNDN);
}
if (sign >= 0)
MPFR_CHANGE_SIGN (mpc_realref (a));
diff --git a/src/norm.c b/src/norm.c
index ab413b6..eca833f 100644
--- a/src/norm.c
+++ b/src/norm.c
@@ -1,6 +1,6 @@
/* mpc_norm -- Square of the norm of a complex number.
-Copyright (C) 2002, 2005, 2008, 2009, 2010, 2011 INRIA
+Copyright (C) 2002, 2005, 2008, 2009, 2010, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -77,8 +77,8 @@ mpc_norm (mpfr_ptr a, mpc_srcptr b, mpfr_rnd_t rnd)
mpfr_set_prec (u, prec_u);
mpfr_set_prec (v, prec_v);
- inexact = mpfr_sqr (u, mpc_realref(b), GMP_RNDD); /* err <= 1 ulp in prec */
- inexact |= mpfr_sqr (v, mpc_imagref(b), GMP_RNDD); /* err <= 1 ulp in prec */
+ inexact = mpfr_sqr (u, mpc_realref(b), MPFR_RNDD); /* err <= 1 ulp in prec */
+ inexact |= mpfr_sqr (v, mpc_imagref(b), MPFR_RNDD); /* err <= 1 ulp in prec */
/* If loops = max_loops, inexact should be 0 here, except in case
of underflow or overflow.
@@ -86,12 +86,12 @@ mpc_norm (mpfr_ptr a, mpc_srcptr b, mpfr_rnd_t rnd)
while-loop since it only remains to add u and v into a. */
if (inexact) {
mpfr_set_prec (res, prec);
- mpfr_add (res, u, v, GMP_RNDD); /* err <= 3 ulp in prec */
+ mpfr_add (res, u, v, MPFR_RNDD); /* err <= 3 ulp in prec */
}
} while (loops < max_loops && inexact != 0
- && !mpfr_can_round (res, prec - 2, GMP_RNDD, GMP_RNDU,
- mpfr_get_prec (a) + (rnd == GMP_RNDN)));
+ && !mpfr_can_round (res, prec - 2, MPFR_RNDD, MPFR_RNDU,
+ mpfr_get_prec (a) + (rnd == MPFR_RNDN)));
if (!inexact)
/* squarings were exact, neither underflow nor overflow */
@@ -100,7 +100,7 @@ mpc_norm (mpfr_ptr a, mpc_srcptr b, mpfr_rnd_t rnd)
since the norm is larger, there is an overflow for the norm */
else if (mpfr_overflow_p ()) {
/* replace by "correctly rounded overflow" */
- mpfr_set_ui (a, 1ul, GMP_RNDN);
+ mpfr_set_ui (a, 1ul, MPFR_RNDN);
inexact = mpfr_mul_2ui (a, a, mpfr_get_emax (), rnd);
}
else if (mpfr_underflow_p ()) {
@@ -123,14 +123,14 @@ mpc_norm (mpfr_ptr a, mpc_srcptr b, mpfr_rnd_t rnd)
&& mpfr_get_exp (u) - 2 * (mpfr_exp_t) prec_u > emin
&& mpfr_get_exp (u) > -10) {
mpfr_set_prec (v, MPFR_PREC_MIN);
- mpfr_set_ui_2exp (v, 1, emin - 1, GMP_RNDZ);
+ mpfr_set_ui_2exp (v, 1, emin - 1, MPFR_RNDZ);
inexact = mpfr_add (a, u, v, rnd);
}
else if (!mpfr_zero_p (v)
&& mpfr_get_exp (v) - 2 * (mpfr_exp_t) prec_v > emin
&& mpfr_get_exp (v) > -10) {
mpfr_set_prec (u, MPFR_PREC_MIN);
- mpfr_set_ui_2exp (u, 1, emin - 1, GMP_RNDZ);
+ mpfr_set_ui_2exp (u, 1, emin - 1, MPFR_RNDZ);
inexact = mpfr_add (a, u, v, rnd);
}
else {
@@ -145,17 +145,17 @@ mpc_norm (mpfr_ptr a, mpc_srcptr b, mpfr_rnd_t rnd)
integer overflow */
if (mpfr_zero_p (u)) {
/* recompute the scaled value exactly */
- mpfr_mul_2ui (u, mpc_realref (b), scale, GMP_RNDN);
- mpfr_sqr (u, u, GMP_RNDN);
+ mpfr_mul_2ui (u, mpc_realref (b), scale, MPFR_RNDN);
+ mpfr_sqr (u, u, MPFR_RNDN);
}
else /* just scale */
- mpfr_mul_2ui (u, u, 2*scale, GMP_RNDN);
+ mpfr_mul_2ui (u, u, 2*scale, MPFR_RNDN);
if (mpfr_zero_p (v)) {
- mpfr_mul_2ui (v, mpc_imagref (b), scale, GMP_RNDN);
- mpfr_sqr (v, v, GMP_RNDN);
+ mpfr_mul_2ui (v, mpc_imagref (b), scale, MPFR_RNDN);
+ mpfr_sqr (v, v, MPFR_RNDN);
}
else
- mpfr_mul_2ui (v, v, 2*scale, GMP_RNDN);
+ mpfr_mul_2ui (v, v, 2*scale, MPFR_RNDN);
inexact = mpfr_add (a, u, v, rnd);
mpfr_clear_underflow ();
diff --git a/src/pow.c b/src/pow.c
index 92abca7..4b394ea 100644
--- a/src/pow.c
+++ b/src/pow.c
@@ -137,7 +137,7 @@ fix_sign (mpc_ptr z, int sign_eps, int sign_a, mpfr_srcptr y)
MPC_ASSERT (ymod4 == 1 || ymod4 == 3);
if ((ymod4 == 3 && sign_eps == 0) ||
(ymod4 == 1 && sign_eps == 1))
- mpfr_neg (mpc_realref(z), mpc_realref(z), GMP_RNDZ);
+ mpfr_neg (mpc_realref(z), mpc_realref(z), MPFR_RNDZ);
}
else if (mpfr_zero_p (mpc_imagref(z)))
{
@@ -147,7 +147,7 @@ fix_sign (mpc_ptr z, int sign_eps, int sign_a, mpfr_srcptr y)
MPC_ASSERT (ymod4 == 0 || ymod4 == 2);
if ((ymod4 == 0 && sign_a == sign_eps) ||
(ymod4 == 2 && sign_a != sign_eps))
- mpfr_neg (mpc_imagref(z), mpc_imagref(z), GMP_RNDZ);
+ mpfr_neg (mpc_imagref(z), mpc_imagref(z), MPFR_RNDZ);
}
end:
@@ -187,7 +187,7 @@ mpc_pow_exact (mpc_ptr z, mpc_srcptr x, mpfr_srcptr y, mpc_rnd_t rnd,
{
z_is_y = 1;
mpfr_init2 (copy_of_y, mpfr_get_prec (y));
- mpfr_set (copy_of_y, y, GMP_RNDN);
+ mpfr_set (copy_of_y, y, MPFR_RNDN);
}
mpz_init (my);
@@ -202,7 +202,7 @@ mpc_pow_exact (mpc_ptr z, mpc_srcptr x, mpfr_srcptr y, mpc_rnd_t rnd,
t = mpz_scan1 (my, 0);
ey += (mpfr_exp_t) t;
mpz_tdiv_q_2exp (my, my, t);
- /* y = my*2^ey */
+ /* y = my*2^ey with my odd */
if (x_imag)
{
@@ -229,7 +229,6 @@ mpc_pow_exact (mpc_ptr z, mpc_srcptr x, mpfr_srcptr y, mpc_rnd_t rnd,
mpz_mul_2exp (d, d, (unsigned long int) (ed - ec));
if ((mpfr_prec_t) mpz_sizeinbase (d, 2) > maxprec)
goto end;
- ed = ec;
}
else if (ed < ec)
{
@@ -484,7 +483,7 @@ mpc_pow (mpc_ptr z, mpc_srcptr x, mpc_srcptr y, mpc_rnd_t rnd)
mpc_t t, u;
mpfr_prec_t p, pr, pi, maxprec;
int saved_underflow, saved_overflow;
-
+
/* save the underflow or overflow flags from MPFR */
saved_underflow = mpfr_underflow_p ();
saved_overflow = mpfr_overflow_p ();
@@ -513,7 +512,7 @@ mpc_pow (mpc_ptr z, mpc_srcptr x, mpc_srcptr y, mpc_rnd_t rnd)
cx1 > 0 if |x| > 1
*/
mpfr_init (n);
- inex = mpc_norm (n, x, GMP_RNDN);
+ inex = mpc_norm (n, x, MPFR_RNDN);
cx1 = mpfr_cmp_ui (n, 1);
if (cx1 == 0 && inex != 0)
cx1 = -inex;
@@ -526,7 +525,7 @@ mpc_pow (mpc_ptr z, mpc_srcptr x, mpc_srcptr y, mpc_rnd_t rnd)
/* warning: mpc_set_ui_ui does not set Im(z) to -0 if Im(rnd)=RNDD */
ret = mpc_set_ui_ui (z, 1, 0, rnd);
- if (MPC_RND_IM (rnd) == GMP_RNDD || sign_zi)
+ if (MPC_RND_IM (rnd) == MPFR_RNDD || sign_zi)
mpc_conj (z, z, MPC_RNDNN);
mpfr_clear (n);
@@ -575,7 +574,7 @@ mpc_pow (mpc_ptr z, mpc_srcptr x, mpc_srcptr y, mpc_rnd_t rnd)
Note that the sign must also be set explicitly when rnd=RNDD
because mpfr_set_ui(z_i, 0, rnd) always sets z_i to +0.
*/
- if (MPC_RND_IM (rnd) == GMP_RNDD || s1 != s2)
+ if (MPC_RND_IM (rnd) == MPFR_RNDD || s1 != s2)
mpc_conj (z, z, MPC_RNDNN);
goto end;
}
@@ -601,7 +600,7 @@ mpc_pow (mpc_ptr z, mpc_srcptr x, mpc_srcptr y, mpc_rnd_t rnd)
Note that the sign must also be set explicitly when rnd=RNDD
because mpfr_set_ui(z_i, 0, rnd) always sets z_i to +0.
*/
- if (MPC_RND_IM(rnd) == GMP_RNDD || s1 != s2)
+ if (MPC_RND_IM(rnd) == MPFR_RNDD || s1 != s2)
mpfr_neg (mpc_imagref(z), mpc_imagref(z), MPC_RND_IM(rnd));
goto end;
}
@@ -614,8 +613,8 @@ mpc_pow (mpc_ptr z, mpc_srcptr x, mpc_srcptr y, mpc_rnd_t rnd)
(a) x is negative and y is half-an-integer
(b) x = -1 and Re(y) is half-an-integer
*/
- if (mpfr_cmp_ui (mpc_realref(x), 0) < 0 && is_odd (mpc_realref(y), 1) &&
- (y_real || mpfr_cmp_si (mpc_realref(x), -1) == 0))
+ if ((mpfr_cmp_ui (mpc_realref(x), 0) < 0) && is_odd (mpc_realref(y), 1)
+ && (y_real || mpfr_cmp_si (mpc_realref(x), -1) == 0))
z_imag = 1;
}
else /* x non real */
@@ -651,8 +650,8 @@ mpc_pow (mpc_ptr z, mpc_srcptr x, mpc_srcptr y, mpc_rnd_t rnd)
p = 64;
mpc_init2 (u, p);
mpc_init2 (t, p);
- pr += MPC_RND_RE(rnd) == GMP_RNDN;
- pi += MPC_RND_IM(rnd) == GMP_RNDN;
+ pr += MPC_RND_RE(rnd) == MPFR_RNDN;
+ pi += MPC_RND_IM(rnd) == MPFR_RNDN;
maxprec = MPC_MAX_PREC (z);
x_imag = mpfr_zero_p (mpc_realref(x));
for (loop = 0;; loop++)
@@ -703,8 +702,8 @@ mpc_pow (mpc_ptr z, mpc_srcptr x, mpc_srcptr y, mpc_rnd_t rnd)
(see algorithms.tex) plus one due to the exponent difference: if
z = a + I*b, where the relative error on z is at most 2^(-p), and
EXP(a) = EXP(b) + k, the relative error on b is at most 2^(k-p) */
- if ((z_imag || (p > q + 3 + dr && mpfr_can_round (mpc_realref(u), p - q - 3 - dr, GMP_RNDN, GMP_RNDZ, pr))) &&
- (z_real || (p > q + 3 + di && mpfr_can_round (mpc_imagref(u), p - q - 3 - di, GMP_RNDN, GMP_RNDZ, pi))))
+ if ((z_imag || (p > q + 3 + dr && mpfr_can_round (mpc_realref(u), p - q - 3 - dr, MPFR_RNDN, MPFR_RNDZ, pr))) &&
+ (z_real || (p > q + 3 + di && mpfr_can_round (mpc_imagref(u), p - q - 3 - di, MPFR_RNDN, MPFR_RNDZ, pi))))
break;
/* if Re(u) is not known to be zero, assume it is a normal number, i.e.,
@@ -751,7 +750,7 @@ mpc_pow (mpc_ptr z, mpc_srcptr x, mpc_srcptr y, mpc_rnd_t rnd)
sign_rex = mpfr_signbit (mpc_realref (x));
sign_imx = mpfr_signbit (mpc_imagref (x));
mpfr_init (n);
- inex = mpc_norm (n, x, GMP_RNDN);
+ inex = mpc_norm (n, x, MPFR_RNDN);
cx1 = mpfr_cmp_ui (n, 1);
if (cx1 == 0 && inex != 0)
cx1 = -inex;
@@ -762,7 +761,7 @@ mpc_pow (mpc_ptr z, mpc_srcptr x, mpc_srcptr y, mpc_rnd_t rnd)
/* copy RE(y) to n since if z==y we will destroy Re(y) below */
mpfr_set_prec (n, mpfr_get_prec (mpc_realref (y)));
- mpfr_set (n, mpc_realref (y), GMP_RNDN);
+ mpfr_set (n, mpc_realref (y), MPFR_RNDN);
ret = mpfr_set (mpc_realref(z), mpc_realref(u), MPC_RND_RE(rnd));
if (y_real && (x_real || x_imag))
{
@@ -777,7 +776,7 @@ mpc_pow (mpc_ptr z, mpc_srcptr x, mpc_srcptr y, mpc_rnd_t rnd)
{
ret = MPC_INEX (ret, mpfr_set_ui (mpc_imagref (z), 0, MPC_RND_IM (rnd)));
/* warning: mpfr_set_ui does not set Im(z) to -0 if Im(rnd) = RNDD */
- if (MPC_RND_IM (rnd) == GMP_RNDD || sign_zi)
+ if (MPC_RND_IM (rnd) == MPFR_RNDD || sign_zi)
mpc_conj (z, z, MPC_RNDNN);
}
diff --git a/src/pow_fr.c b/src/pow_fr.c
index 8c5d930..87e255b 100644
--- a/src/pow_fr.c
+++ b/src/pow_fr.c
@@ -1,6 +1,6 @@
/* mpc_pow_fr -- Raise a complex number to a floating-point power.
-Copyright (C) 2009, 2011 INRIA
+Copyright (C) 2009, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -29,7 +29,7 @@ mpc_pow_fr (mpc_ptr z, mpc_srcptr x, mpfr_srcptr y, mpc_rnd_t rnd)
/* avoid copying the significand of y by copying only the struct */
mpc_realref(yy)[0] = y[0];
mpfr_init2 (mpc_imagref(yy), MPFR_PREC_MIN);
- mpfr_set_ui (mpc_imagref(yy), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_imagref(yy), 0, MPFR_RNDN);
inex = mpc_pow (z, x, yy, rnd);
mpfr_clear (mpc_imagref(yy));
return inex;
diff --git a/src/pow_ui.c b/src/pow_ui.c
index da82a94..fb59310 100644
--- a/src/pow_ui.c
+++ b/src/pow_ui.c
@@ -131,10 +131,10 @@ mpc_pow_usi (mpc_ptr z, mpc_srcptr x, unsigned long y, int sign,
/* the factor on the imaginary part is 2+2^(diff+2) <= 4 for diff <= -1
and < 2^(diff+3) for diff >= 0 */
ei = (diff <= -1) ? l0 + 3 : l0 + diff + 3;
- if (mpfr_can_round (mpc_realref(t), p - er, GMP_RNDN, GMP_RNDZ,
- MPC_PREC_RE(z) + (MPC_RND_RE(rnd) == GMP_RNDN))
- && mpfr_can_round (mpc_imagref(t), p - ei, GMP_RNDN, GMP_RNDZ,
- MPC_PREC_IM(z) + (MPC_RND_IM(rnd) == GMP_RNDN))) {
+ if (mpfr_can_round (mpc_realref(t), p - er, MPFR_RNDN, MPFR_RNDZ,
+ MPC_PREC_RE(z) + (MPC_RND_RE(rnd) == MPFR_RNDN))
+ && mpfr_can_round (mpc_imagref(t), p - ei, MPFR_RNDN, MPFR_RNDZ,
+ MPC_PREC_IM(z) + (MPC_RND_IM(rnd) == MPFR_RNDN))) {
inex = mpc_set (z, t, rnd);
done = 1;
}
diff --git a/src/sin_cos.c b/src/sin_cos.c
index 0cff45a..0bb00cf 100644
--- a/src/sin_cos.c
+++ b/src/sin_cos.c
@@ -1,6 +1,6 @@
/* mpc_sin_cos -- combined sine and cosine of a complex number.
-Copyright (C) 2010, 2011 INRIA
+Copyright (C) 2010, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -81,7 +81,7 @@ mpc_sin_cos_nonfinite (mpc_ptr rop_sin, mpc_ptr rop_cos, mpc_srcptr op,
mpfr_t s, c;
mpfr_init2 (s, 2);
mpfr_init2 (c, 2);
- mpfr_sin_cos (s, c, mpc_realref (op_loc), GMP_RNDZ);
+ mpfr_sin_cos (s, c, mpc_realref (op_loc), MPFR_RNDZ);
mpfr_set_inf (mpc_realref (rop_sin), MPFR_SIGN (s));
mpfr_set_inf (mpc_imagref (rop_sin), MPFR_SIGN (c)*MPFR_SIGN (mpc_imagref (op_loc)));
mpfr_clear (s);
@@ -157,7 +157,7 @@ mpc_sin_cos_nonfinite (mpc_ptr rop_sin, mpc_ptr rop_cos, mpc_srcptr op,
mpfr_t s, c;
mpfr_init2 (c, 2);
mpfr_init2 (s, 2);
- mpfr_sin_cos (s, c, mpc_realref (op_loc), GMP_RNDN);
+ mpfr_sin_cos (s, c, mpc_realref (op_loc), MPFR_RNDN);
mpfr_set_inf (mpc_realref (rop_cos), mpfr_sgn (c));
mpfr_set_inf (mpc_imagref (rop_cos),
(mpfr_sgn (mpc_imagref (op_loc)) == mpfr_sgn (s) ? -1 : +1));
@@ -203,7 +203,7 @@ mpc_sin_cos_real (mpc_ptr rop_sin, mpc_ptr rop_cos, mpc_srcptr op,
arbitrary rounding mode will work. */
if (rop_sin != NULL) {
- mpfr_set (mpc_realref (rop_sin), s, GMP_RNDN); /* exact */
+ mpfr_set (mpc_realref (rop_sin), s, MPFR_RNDN); /* exact */
inex_sin_re = inex_s;
mpfr_set_zero (mpc_imagref (rop_sin),
( ( sign_im && !mpfr_signbit(c))
@@ -211,7 +211,7 @@ mpc_sin_cos_real (mpc_ptr rop_sin, mpc_ptr rop_cos, mpc_srcptr op,
}
if (rop_cos != NULL) {
- mpfr_set (mpc_realref (rop_cos), c, GMP_RNDN); /* exact */
+ mpfr_set (mpc_realref (rop_cos), c, MPFR_RNDN); /* exact */
inex_cos_re = inex_c;
mpfr_set_zero (mpc_imagref (rop_cos),
( ( sign_im && mpfr_signbit(s))
@@ -245,7 +245,7 @@ mpc_sin_cos_imag (mpc_ptr rop_sin, mpc_ptr rop_cos, mpc_srcptr op,
if (rop_sin != NULL) {
/* sin(+-O +i*y) = +-0 +i*sinh(y) */
- mpfr_set (mpc_realref(rop_sin), mpc_realref(op_loc), GMP_RNDN);
+ mpfr_set (mpc_realref(rop_sin), mpc_realref(op_loc), MPFR_RNDN);
inex_sin_im = mpfr_sinh (mpc_imagref(rop_sin), mpc_imagref(op_loc), MPC_RND_IM(rnd_sin));
}
@@ -325,43 +325,43 @@ mpc_sin_cos (mpc_ptr rop_sin, mpc_ptr rop_cos, mpc_srcptr op,
mpfr_set_prec (sch, prec);
mpfr_set_prec (csh, prec);
- mpfr_sin_cos (s, c, mpc_realref(op), GMP_RNDN);
- mpfr_sinh_cosh (sh, ch, mpc_imagref(op), GMP_RNDN);
+ mpfr_sin_cos (s, c, mpc_realref(op), MPFR_RNDN);
+ mpfr_sinh_cosh (sh, ch, mpc_imagref(op), MPFR_RNDN);
if (rop_sin != NULL) {
/* real part of sine */
- mpfr_mul (sch, s, ch, GMP_RNDN);
+ mpfr_mul (sch, s, ch, MPFR_RNDN);
ok = (!mpfr_number_p (sch))
- || mpfr_can_round (sch, prec - 2, GMP_RNDN, GMP_RNDZ,
+ || mpfr_can_round (sch, prec - 2, MPFR_RNDN, MPFR_RNDZ,
MPC_PREC_RE (rop_sin)
- + (MPC_RND_RE (rnd_sin) == GMP_RNDN));
+ + (MPC_RND_RE (rnd_sin) == MPFR_RNDN));
if (ok) {
/* imaginary part of sine */
- mpfr_mul (csh, c, sh, GMP_RNDN);
+ mpfr_mul (csh, c, sh, MPFR_RNDN);
ok = (!mpfr_number_p (csh))
- || mpfr_can_round (csh, prec - 2, GMP_RNDN, GMP_RNDZ,
+ || mpfr_can_round (csh, prec - 2, MPFR_RNDN, MPFR_RNDZ,
MPC_PREC_IM (rop_sin)
- + (MPC_RND_IM (rnd_sin) == GMP_RNDN));
+ + (MPC_RND_IM (rnd_sin) == MPFR_RNDN));
}
}
if (rop_cos != NULL && ok) {
/* real part of cosine */
- mpfr_mul (c, c, ch, GMP_RNDN);
+ mpfr_mul (c, c, ch, MPFR_RNDN);
ok = (!mpfr_number_p (c))
- || mpfr_can_round (c, prec - 2, GMP_RNDN, GMP_RNDZ,
+ || mpfr_can_round (c, prec - 2, MPFR_RNDN, MPFR_RNDZ,
MPC_PREC_RE (rop_cos)
- + (MPC_RND_RE (rnd_cos) == GMP_RNDN));
+ + (MPC_RND_RE (rnd_cos) == MPFR_RNDN));
if (ok) {
/* imaginary part of cosine */
- mpfr_mul (s, s, sh, GMP_RNDN);
- mpfr_neg (s, s, GMP_RNDN);
+ mpfr_mul (s, s, sh, MPFR_RNDN);
+ mpfr_neg (s, s, MPFR_RNDN);
ok = (!mpfr_number_p (s))
- || mpfr_can_round (s, prec - 2, GMP_RNDN, GMP_RNDZ,
+ || mpfr_can_round (s, prec - 2, MPFR_RNDN, MPFR_RNDZ,
MPC_PREC_IM (rop_cos)
- + (MPC_RND_IM (rnd_cos) == GMP_RNDN));
+ + (MPC_RND_IM (rnd_cos) == MPFR_RNDN));
}
}
} while (ok == 0);
diff --git a/src/sinh.c b/src/sinh.c
index ac5fdd9..509cc57 100644
--- a/src/sinh.c
+++ b/src/sinh.c
@@ -1,6 +1,6 @@
/* mpc_sinh -- hyperbolic sine of a complex number.
-Copyright (C)2008, 2009, 2011 INRIA
+Copyright (C)2008, 2009, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -36,7 +36,7 @@ mpc_sinh (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
mpc_realref (sin_z)[0] = mpc_imagref (rop)[0];
mpc_imagref (sin_z)[0] = mpc_realref (rop)[0];
- inex = mpc_sin (sin_z, z, RNDC (MPC_RND_IM (rnd), MPC_RND_RE (rnd)));
+ inex = mpc_sin (sin_z, z, MPC_RND (MPC_RND_IM (rnd), MPC_RND_RE (rnd)));
/* sin_z and rop parts share the same significands, copy the rest now. */
mpc_realref (rop)[0] = mpc_imagref (sin_z)[0];
diff --git a/src/sqr.c b/src/sqr.c
index 770cadc..f7d35fd 100644
--- a/src/sqr.c
+++ b/src/sqr.c
@@ -36,8 +36,8 @@ mpfr_fsss (mpfr_ptr z, mpfr_srcptr a, mpfr_srcptr c, mpfr_rnd_t rnd)
/* u=a^2, v=c^2 exactly */
mpfr_init2 (u, 2*mpfr_get_prec (a));
mpfr_init2 (v, 2*mpfr_get_prec (c));
- mpfr_sqr (u, a, GMP_RNDN);
- mpfr_sqr (v, c, GMP_RNDN);
+ mpfr_sqr (u, a, MPFR_RNDN);
+ mpfr_sqr (v, c, MPFR_RNDN);
/* tentatively compute z as u-v; here we need z to be distinct
from a and c to not lose the latter */
@@ -45,7 +45,7 @@ mpfr_fsss (mpfr_ptr z, mpfr_srcptr a, mpfr_srcptr c, mpfr_rnd_t rnd)
if (mpfr_inf_p (z)) {
/* replace by "correctly rounded overflow" */
- mpfr_set_si (z, (mpfr_signbit (z) ? -1 : 1), GMP_RNDN);
+ mpfr_set_si (z, (mpfr_signbit (z) ? -1 : 1), MPFR_RNDN);
inex = mpfr_mul_2ui (z, z, mpfr_get_emax (), rnd);
}
else if (mpfr_zero_p (u) && !mpfr_zero_p (v)) {
@@ -81,11 +81,11 @@ mpfr_fsss (mpfr_ptr z, mpfr_srcptr a, mpfr_srcptr c, mpfr_rnd_t rnd)
mpz_mul_2exp (ev, ev, 1);
/* recompute u and v and move exponents to eu and ev */
- mpfr_sqr (u, a, GMP_RNDN);
+ mpfr_sqr (u, a, MPFR_RNDN);
/* exponent of u is non-positive */
mpz_sub_ui (eu, eu, (unsigned long int) (-mpfr_get_exp (u)));
mpfr_set_exp (u, (mpfr_prec_t) 0);
- mpfr_sqr (v, c, GMP_RNDN);
+ mpfr_sqr (v, c, MPFR_RNDN);
mpz_sub_ui (ev, ev, (unsigned long int) (-mpfr_get_exp (v)));
mpfr_set_exp (v, (mpfr_prec_t) 0);
if (mpfr_nan_p (z)) {
@@ -210,7 +210,7 @@ mpc_sqr (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
if (mpfr_zero_p (mpc_imagref(op))) {
int same_sign = mpfr_signbit (mpc_realref (op)) == mpfr_signbit (mpc_imagref (op));
inex_re = mpfr_sqr (mpc_realref(rop), mpc_realref(op), MPC_RND_RE(rnd));
- inex_im = mpfr_set_ui (mpc_imagref(rop), 0ul, GMP_RNDN);
+ inex_im = mpfr_set_ui (mpc_imagref(rop), 0ul, MPFR_RNDN);
if (!same_sign)
mpc_conj (rop, rop, MPC_RNDNN);
return MPC_INEX(inex_re, inex_im);
@@ -218,8 +218,8 @@ mpc_sqr (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
if (mpfr_zero_p (mpc_realref(op))) {
int same_sign = mpfr_signbit (mpc_realref (op)) == mpfr_signbit (mpc_imagref (op));
inex_re = -mpfr_sqr (mpc_realref(rop), mpc_imagref(op), INV_RND (MPC_RND_RE(rnd)));
- mpfr_neg (mpc_realref(rop), mpc_realref(rop), GMP_RNDN);
- inex_im = mpfr_set_ui (mpc_imagref(rop), 0ul, GMP_RNDN);
+ mpfr_neg (mpc_realref(rop), mpc_realref(rop), MPFR_RNDN);
+ inex_im = mpfr_set_ui (mpc_imagref(rop), 0ul, MPFR_RNDN);
if (!same_sign)
mpc_conj (rop, rop, MPC_RNDNN);
return MPC_INEX(inex_re, inex_im);
@@ -228,7 +228,7 @@ mpc_sqr (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
if (rop == op)
{
mpfr_init2 (x, MPC_PREC_RE (op));
- mpfr_set (x, op->re, GMP_RNDN);
+ mpfr_set (x, op->re, MPFR_RNDN);
}
else
x [0] = op->re [0];
@@ -266,23 +266,20 @@ mpc_sqr (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
/* The error is bounded above by 1 ulp. */
/* We first let inexact be 1 if the real part is not computed */
/* exactly and determine the sign later. */
- inexact = ROUND_AWAY (mpfr_add (u, x, mpc_imagref (op), MPFR_RNDA), u)
- | ROUND_AWAY (mpfr_sub (v, x, mpc_imagref (op), MPFR_RNDA), v);
+ inexact = mpfr_add (u, x, mpc_imagref (op), MPFR_RNDA)
+ | mpfr_sub (v, x, mpc_imagref (op), MPFR_RNDA);
/* compute the real part as u*v, rounded away */
/* determine also the sign of inex_re */
if (mpfr_sgn (u) == 0 || mpfr_sgn (v) == 0) {
/* as we have rounded away, the result is exact */
- mpfr_set_ui (mpc_realref (rop), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (rop), 0, MPFR_RNDN);
inex_re = 0;
ok = 1;
}
else {
- mpfr_rnd_t rnd_away;
- /* FIXME: can be replaced by MPFR_RNDA in mpfr >= 3 */
- rnd_away = (mpfr_sgn (u) * mpfr_sgn (v) > 0 ? GMP_RNDU : GMP_RNDD);
- inexact |= ROUND_AWAY (mpfr_mul (u, u, v, MPFR_RNDA), u); /* error 5 */
+ inexact |= mpfr_mul (u, u, v, MPFR_RNDA); /* error 5 */
if (mpfr_get_exp (u) == emin || mpfr_inf_p (u)) {
/* under- or overflow */
inex_re = mpfr_fsss (rop->re, x, op->im, MPC_RND_RE (rnd));
@@ -290,8 +287,8 @@ mpc_sqr (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
}
else {
ok = (!inexact) | mpfr_can_round (u, prec - 3,
- rnd_away, GMP_RNDZ,
- MPC_PREC_RE (rop) + (MPC_RND_RE (rnd) == GMP_RNDN));
+ MPFR_RNDA, MPFR_RNDZ,
+ MPC_PREC_RE (rop) + (MPC_RND_RE (rnd) == MPFR_RNDN));
if (ok) {
inex_re = mpfr_set (mpc_realref (rop), u, MPC_RND_RE (rnd));
if (inex_re == 0)
@@ -311,7 +308,7 @@ mpc_sqr (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
mpfr_clear_underflow ();
inex_im = mpfr_mul (rop->im, x, op->im, MPC_RND_IM (rnd));
if (!mpfr_underflow_p ())
- inex_im |= mpfr_mul_2exp (rop->im, rop->im, 1, MPC_RND_IM (rnd));
+ inex_im |= mpfr_mul_2ui (rop->im, rop->im, 1, MPC_RND_IM (rnd));
/* We must not multiply by 2 if rop->im has been set to the smallest
representable number. */
if (saved_underflow)
diff --git a/src/sqrt.c b/src/sqrt.c
index 9250c27..01753cc 100644
--- a/src/sqrt.c
+++ b/src/sqrt.c
@@ -1,6 +1,6 @@
/* mpc_sqrt -- Take the square root of a complex number.
-Copyright (C) 2002, 2008, 2009, 2010, 2011 INRIA
+Copyright (C) 2002, 2008, 2009, 2010, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -46,7 +46,7 @@ mpc_sqrt (mpc_ptr a, mpc_srcptr b, mpc_rnd_t rnd)
at the target precision */
const int im_sgn = mpfr_signbit (mpc_imagref (b)) == 0 ? 0 : -1;
/* we need to know the sign of Im(b) when it is +/-0 */
- const mpfr_rnd_t r = im_sgn ? GMP_RNDD : GMP_RNDU;
+ const mpfr_rnd_t r = im_sgn ? MPFR_RNDD : MPFR_RNDU;
/* rounding mode used when computing t */
/* special values */
@@ -68,7 +68,7 @@ mpc_sqrt (mpc_ptr a, mpc_srcptr b, mpc_rnd_t rnd)
{
/* sqrt(-Inf +i*y) = +0 +i*Inf, when y positive */
/* sqrt(-Inf +i*y) = +0 -i*Inf, when y positive */
- mpfr_set_ui (mpc_realref (a), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (a), 0, MPFR_RNDN);
mpfr_set_inf (mpc_imagref (a), im_sgn);
return MPC_INEX (0, 0);
}
@@ -87,7 +87,7 @@ mpc_sqrt (mpc_ptr a, mpc_srcptr b, mpc_rnd_t rnd)
/* sqrt(+Inf +i*y) = +Inf +i*0, when y positive */
/* sqrt(+Inf +i*y) = +Inf -i*0, when y positive */
mpfr_set_inf (mpc_realref (a), +1);
- mpfr_set_ui (mpc_imagref (a), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_imagref (a), 0, MPFR_RNDN);
if (im_sgn)
mpc_conj (a, a, MPC_RNDNN);
return MPC_INEX (0, 0);
@@ -125,7 +125,7 @@ mpc_sqrt (mpc_ptr a, mpc_srcptr b, mpc_rnd_t rnd)
else if (re_cmp > 0)
{
inex_w = mpfr_sqrt (mpc_realref (a), mpc_realref (b), MPC_RND_RE (rnd));
- mpfr_set_ui (mpc_imagref (a), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_imagref (a), 0, MPFR_RNDN);
if (im_sgn)
mpc_conj (a, a, MPC_RNDNN);
return MPC_INEX (inex_w, 0);
@@ -133,16 +133,16 @@ mpc_sqrt (mpc_ptr a, mpc_srcptr b, mpc_rnd_t rnd)
else
{
mpfr_init2 (w, MPC_PREC_RE (b));
- mpfr_neg (w, mpc_realref (b), GMP_RNDN);
+ mpfr_neg (w, mpc_realref (b), MPFR_RNDN);
if (im_sgn)
{
inex_w = -mpfr_sqrt (mpc_imagref (a), w, INV_RND (MPC_RND_IM (rnd)));
- mpfr_neg (mpc_imagref (a), mpc_imagref (a), GMP_RNDN);
+ mpfr_neg (mpc_imagref (a), mpc_imagref (a), MPFR_RNDN);
}
else
inex_w = mpfr_sqrt (mpc_imagref (a), w, MPC_RND_IM (rnd));
- mpfr_set_ui (mpc_realref (a), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (a), 0, MPFR_RNDN);
mpfr_clear (w);
return MPC_INEX (0, inex_w);
}
@@ -155,7 +155,7 @@ mpc_sqrt (mpc_ptr a, mpc_srcptr b, mpc_rnd_t rnd)
y[0] = mpc_imagref (b)[0];
/* If y/2 underflows, so does sqrt(y/2) */
- mpfr_div_2ui (y, y, 1, GMP_RNDN);
+ mpfr_div_2ui (y, y, 1, MPFR_RNDN);
if (im_cmp > 0)
{
inex_w = mpfr_sqrt (mpc_realref (a), y, MPC_RND_RE (rnd));
@@ -163,10 +163,10 @@ mpc_sqrt (mpc_ptr a, mpc_srcptr b, mpc_rnd_t rnd)
}
else
{
- mpfr_neg (y, y, GMP_RNDN);
+ mpfr_neg (y, y, MPFR_RNDN);
inex_w = mpfr_sqrt (mpc_realref (a), y, MPC_RND_RE (rnd));
inex_t = -mpfr_sqrt (mpc_imagref (a), y, INV_RND (MPC_RND_IM (rnd)));
- mpfr_neg (mpc_imagref (a), mpc_imagref (a), GMP_RNDN);
+ mpfr_neg (mpc_imagref (a), mpc_imagref (a), MPFR_RNDN);
}
return MPC_INEX (inex_w, inex_t);
}
@@ -180,9 +180,9 @@ mpc_sqrt (mpc_ptr a, mpc_srcptr b, mpc_rnd_t rnd)
rnd_w = MPC_RND_RE (rnd);
prec_w = MPC_PREC_RE (a);
rnd_t = MPC_RND_IM(rnd);
- if (rnd_t == GMP_RNDZ)
- /* force GMP_RNDD or GMP_RNDUP, using sign(t) = sign(y) */
- rnd_t = (im_cmp > 0 ? GMP_RNDD : GMP_RNDU);
+ if (rnd_t == MPFR_RNDZ)
+ /* force MPFR_RNDD or MPFR_RNDUP, using sign(t) = sign(y) */
+ rnd_t = (im_cmp > 0 ? MPFR_RNDD : MPFR_RNDU);
prec_t = MPC_PREC_IM (a);
}
else {
@@ -191,14 +191,14 @@ mpc_sqrt (mpc_ptr a, mpc_srcptr b, mpc_rnd_t rnd)
if (im_cmp > 0) {
rnd_w = MPC_RND_IM(rnd);
rnd_t = MPC_RND_RE(rnd);
- if (rnd_t == GMP_RNDZ)
- rnd_t = GMP_RNDD;
+ if (rnd_t == MPFR_RNDZ)
+ rnd_t = MPFR_RNDD;
}
else {
rnd_w = INV_RND(MPC_RND_IM (rnd));
rnd_t = INV_RND(MPC_RND_RE (rnd));
- if (rnd_t == GMP_RNDZ)
- rnd_t = GMP_RNDU;
+ if (rnd_t == MPFR_RNDZ)
+ rnd_t = MPFR_RNDU;
}
}
@@ -211,30 +211,30 @@ mpc_sqrt (mpc_ptr a, mpc_srcptr b, mpc_rnd_t rnd)
/* let b = x + iy */
/* w = sqrt ((|x| + sqrt (x^2 + y^2)) / 2), rounded down */
/* total error bounded by 3 ulps */
- inex_w = mpc_abs (w, b, GMP_RNDD);
+ inex_w = mpc_abs (w, b, MPFR_RNDD);
if (re_cmp < 0)
- inex_w |= mpfr_sub (w, w, mpc_realref (b), GMP_RNDD);
+ inex_w |= mpfr_sub (w, w, mpc_realref (b), MPFR_RNDD);
else
- inex_w |= mpfr_add (w, w, mpc_realref (b), GMP_RNDD);
- inex_w |= mpfr_div_2ui (w, w, 1, GMP_RNDD);
- inex_w |= mpfr_sqrt (w, w, GMP_RNDD);
+ inex_w |= mpfr_add (w, w, mpc_realref (b), MPFR_RNDD);
+ inex_w |= mpfr_div_2ui (w, w, 1, MPFR_RNDD);
+ inex_w |= mpfr_sqrt (w, w, MPFR_RNDD);
repr_w = mpfr_min_prec (w) <= prec_w;
if (!repr_w)
/* use the usual trick for obtaining the ternary value */
- ok_w = mpfr_can_round (w, prec - 2, GMP_RNDD, GMP_RNDU,
- prec_w + (rnd_w == GMP_RNDN));
+ ok_w = mpfr_can_round (w, prec - 2, MPFR_RNDD, MPFR_RNDU,
+ prec_w + (rnd_w == MPFR_RNDN));
else {
/* w is representable in the target precision and thus cannot be
rounded up */
- if (rnd_w == GMP_RNDN)
+ if (rnd_w == MPFR_RNDN)
/* If w can be rounded to nearest, then actually no rounding
occurs, and the ternary value is known from inex_w. */
- ok_w = mpfr_can_round (w, prec - 2, GMP_RNDD, GMP_RNDN, prec_w);
+ ok_w = mpfr_can_round (w, prec - 2, MPFR_RNDD, MPFR_RNDN, prec_w);
else
/* If w can be rounded down, then any direct rounding and the
ternary flag can be determined from inex_w. */
- ok_w = mpfr_can_round (w, prec - 2, GMP_RNDD, GMP_RNDD, prec_w);
+ ok_w = mpfr_can_round (w, prec - 2, MPFR_RNDD, MPFR_RNDD, prec_w);
}
if (!inex_w || ok_w) {
@@ -249,11 +249,11 @@ mpc_sqrt (mpc_ptr a, mpc_srcptr b, mpc_rnd_t rnd)
if (!repr_t)
/* As for w; since t was rounded away, we check whether rounding to 0
is possible. */
- ok_t = mpfr_can_round (t, prec - 3, r, GMP_RNDZ,
- prec_t + (rnd_t == GMP_RNDN));
+ ok_t = mpfr_can_round (t, prec - 3, r, MPFR_RNDZ,
+ prec_t + (rnd_t == MPFR_RNDN));
else {
- if (rnd_t == GMP_RNDN)
- ok_t = mpfr_can_round (t, prec - 3, r, GMP_RNDN, prec_t);
+ if (rnd_t == MPFR_RNDN)
+ ok_t = mpfr_can_round (t, prec - 3, r, MPFR_RNDN, prec_t);
else
ok_t = mpfr_can_round (t, prec - 3, r, r, prec_t);
}
@@ -275,7 +275,7 @@ mpc_sqrt (mpc_ptr a, mpc_srcptr b, mpc_rnd_t rnd)
}
if (repr_w && inex_w) {
- if (rnd_w == GMP_RNDN) {
+ if (rnd_w == MPFR_RNDN) {
/* w has not been rounded with mpfr_set/mpfr_neg, determine ternary
value from inex_w instead */
if (re_cmp > 0)
@@ -289,7 +289,7 @@ mpc_sqrt (mpc_ptr a, mpc_srcptr b, mpc_rnd_t rnd)
/* determine ternary value, but also potentially add 1 ulp; can only
be done now when we are in the target precision */
if (re_cmp > 0) {
- if (rnd_w == GMP_RNDU) {
+ if (rnd_w == MPFR_RNDU) {
MPFR_ADD_ONE_ULP (mpc_realref (a));
inex_re = +1;
}
@@ -297,7 +297,7 @@ mpc_sqrt (mpc_ptr a, mpc_srcptr b, mpc_rnd_t rnd)
inex_re = -1;
}
else if (im_cmp > 0) {
- if (rnd_w == GMP_RNDU) {
+ if (rnd_w == MPFR_RNDU) {
MPFR_ADD_ONE_ULP (mpc_imagref (a));
inex_im = +1;
}
@@ -305,7 +305,7 @@ mpc_sqrt (mpc_ptr a, mpc_srcptr b, mpc_rnd_t rnd)
inex_im = -1;
}
else {
- if (rnd_w == GMP_RNDU) {
+ if (rnd_w == MPFR_RNDU) {
MPFR_ADD_ONE_ULP (mpc_imagref (a));
inex_im = -1;
}
@@ -315,7 +315,7 @@ mpc_sqrt (mpc_ptr a, mpc_srcptr b, mpc_rnd_t rnd)
}
}
if (repr_t && inex_t) {
- if (rnd_t == GMP_RNDN) {
+ if (rnd_t == MPFR_RNDN) {
if (re_cmp > 0)
inex_im = inex_t;
else if (im_cmp > 0)
@@ -329,11 +329,11 @@ mpc_sqrt (mpc_ptr a, mpc_srcptr b, mpc_rnd_t rnd)
inex_im = inex_t;
else {
inex_im = -inex_t;
- if ( (im_cmp > 0 && r == GMP_RNDD)
- || (im_cmp < 0 && r == GMP_RNDU))
- MPFR_ADD_ONE_ULP (mpc_imagref (a));
- else
- MPFR_SUB_ONE_ULP (mpc_imagref (a));
+ /* im_cmp > 0 implies that Im(b) > 0, thus im_sgn = 0
+ and r = MPFR_RNDU.
+ im_cmp < 0 implies that Im(b) < 0, thus im_sgn = -1
+ and r = MPFR_RNDD. */
+ MPFR_SUB_ONE_ULP (mpc_imagref (a));
}
}
else if (im_cmp > 0) {
@@ -341,21 +341,17 @@ mpc_sqrt (mpc_ptr a, mpc_srcptr b, mpc_rnd_t rnd)
inex_re = inex_t;
else {
inex_re = -inex_t;
- if (r == GMP_RNDD)
- MPFR_ADD_ONE_ULP (mpc_realref (a));
- else
- MPFR_SUB_ONE_ULP (mpc_realref (a));
+ /* im_cmp > 0 implies r = MPFR_RNDU (see above) */
+ MPFR_SUB_ONE_ULP (mpc_realref (a));
}
}
- else {
+ else { /* im_cmp < 0 */
if (rnd_t == r)
inex_re = -inex_t;
else {
inex_re = inex_t;
- if (r == GMP_RNDD)
- MPFR_SUB_ONE_ULP (mpc_realref (a));
- else
- MPFR_ADD_ONE_ULP (mpc_realref (a));
+ /* im_cmp < 0 implies r = MPFR_RNDD (see above) */
+ MPFR_SUB_ONE_ULP (mpc_realref (a));
}
}
}
diff --git a/src/strtoc.c b/src/strtoc.c
index b96ccee..81702e2 100644
--- a/src/strtoc.c
+++ b/src/strtoc.c
@@ -1,6 +1,6 @@
/* mpc_strtoc -- Read a complex number from a string.
-Copyright (C) 2009, 2010, 2011 INRIA
+Copyright (C) 2009, 2010, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -57,7 +57,7 @@ mpc_strtoc (mpc_ptr rop, const char *nptr, char **endptr, int base, mpc_rnd_t rn
p = end;
if (!bracketed)
- inex_im = mpfr_set_ui (mpc_imagref (rop), 0ul, GMP_RNDN);
+ inex_im = mpfr_set_ui (mpc_imagref (rop), 0ul, MPFR_RNDN);
else {
if (!isspace ((unsigned char)*p))
goto error;
diff --git a/src/tan.c b/src/tan.c
index 24cd92b..0764db8 100644
--- a/src/tan.c
+++ b/src/tan.c
@@ -1,6 +1,6 @@
/* mpc_tan -- tangent of a complex number.
-Copyright (C) 2008, 2009, 2010, 2011 INRIA
+Copyright (C) 2008, 2009, 2010, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -83,7 +83,7 @@ mpc_tan (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
int inex_im;
mpfr_set_ui (mpc_realref (rop), 0, MPC_RND_RE (rnd));
- mpfr_setsign (mpc_realref (rop), mpc_realref (rop), sign_re, GMP_RNDN);
+ mpfr_setsign (mpc_realref (rop), mpc_realref (rop), sign_re, MPFR_RNDN);
/* exact, unless 1 is not in exponent range */
inex_im = mpfr_set_si (mpc_imagref (rop),
@@ -111,10 +111,10 @@ mpc_tan (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
mpfr_init (c);
mpfr_init (s);
- mpfr_sin_cos (s, c, mpc_realref (op), GMP_RNDN);
+ mpfr_sin_cos (s, c, mpc_realref (op), MPFR_RNDN);
mpfr_set_ui (mpc_realref (rop), 0, MPC_RND_RE (rnd));
mpfr_setsign (mpc_realref (rop), mpc_realref (rop),
- mpfr_signbit (c) != mpfr_signbit (s), GMP_RNDN);
+ mpfr_signbit (c) != mpfr_signbit (s), MPFR_RNDN);
/* exact, unless 1 is not in exponent range */
inex_im = mpfr_set_si (mpc_imagref (rop),
(mpfr_signbit (mpc_imagref (op)) ? -1 : +1),
@@ -207,22 +207,22 @@ mpc_tan (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
sign(tan(Re(op)))*0 + sign(Im(op))*I,
where sign(tan(Re(op))) = sign(Re(x))*sign(Re(y)). */
int inex_re, inex_im;
- mpfr_set_ui (mpc_realref (rop), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (rop), 0, MPFR_RNDN);
if (mpfr_sgn (mpc_realref (x)) * mpfr_sgn (mpc_realref (y)) < 0)
{
- mpfr_neg (mpc_realref (rop), mpc_realref (rop), GMP_RNDN);
+ mpfr_neg (mpc_realref (rop), mpc_realref (rop), MPFR_RNDN);
inex_re = 1;
}
else
inex_re = -1; /* +0 is rounded down */
if (mpfr_sgn (mpc_imagref (op)) > 0)
{
- mpfr_set_ui (mpc_imagref (rop), 1, GMP_RNDN);
+ mpfr_set_ui (mpc_imagref (rop), 1, MPFR_RNDN);
inex_im = 1;
}
else
{
- mpfr_set_si (mpc_imagref (rop), -1, GMP_RNDN);
+ mpfr_set_si (mpc_imagref (rop), -1, MPFR_RNDN);
inex_im = -1;
}
inex = MPC_INEX(inex_re, inex_im);
@@ -261,15 +261,15 @@ mpc_tan (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
/* Can the real part be rounded? */
ok = (!mpfr_number_p (mpc_realref (x)))
- || mpfr_can_round (mpc_realref(x), prec - err, GMP_RNDN, GMP_RNDZ,
- MPC_PREC_RE(rop) + (MPC_RND_RE(rnd) == GMP_RNDN));
+ || mpfr_can_round (mpc_realref(x), prec - err, MPFR_RNDN, MPFR_RNDZ,
+ MPC_PREC_RE(rop) + (MPC_RND_RE(rnd) == MPFR_RNDN));
if (ok)
{
/* Can the imaginary part be rounded? */
ok = (!mpfr_number_p (mpc_imagref (x)))
- || mpfr_can_round (mpc_imagref(x), prec - 6, GMP_RNDN, GMP_RNDZ,
- MPC_PREC_IM(rop) + (MPC_RND_IM(rnd) == GMP_RNDN));
+ || mpfr_can_round (mpc_imagref(x), prec - 6, MPFR_RNDN, MPFR_RNDZ,
+ MPC_PREC_IM(rop) + (MPC_RND_IM(rnd) == MPFR_RNDN));
}
}
while (ok == 0);
diff --git a/src/tanh.c b/src/tanh.c
index cb4162b..78f2103 100644
--- a/src/tanh.c
+++ b/src/tanh.c
@@ -1,6 +1,6 @@
/* mpc_tanh -- hyperbolic tangent of a complex number.
-Copyright (C) 2008, 2009, 2011 INRIA
+Copyright (C) 2008, 2009, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -36,7 +36,7 @@ mpc_tanh (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd)
mpc_realref (tan_z)[0] = mpc_imagref (rop)[0];
mpc_imagref (tan_z)[0] = mpc_realref (rop)[0];
- inex = mpc_tan (tan_z, z, RNDC (MPC_RND_IM (rnd), MPC_RND_RE (rnd)));
+ inex = mpc_tan (tan_z, z, MPC_RND (MPC_RND_IM (rnd), MPC_RND_RE (rnd)));
/* tan_z and rop parts share the same significands, copy the rest now. */
mpc_realref (rop)[0] = mpc_imagref (tan_z)[0];
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ac572f6..6369c84 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,6 +1,6 @@
## tests/Makefile.am -- Process this file with automake to produce Makefile.in
##
-## Copyright (C) 2008, 2009, 2010, 2011 INRIA
+## Copyright (C) 2008, 2009, 2010, 2011, 2012 INRIA
##
## This file is part of GNU MPC.
##
@@ -28,9 +28,10 @@ AM_LDFLAGS = -no-install
LOADLIBES=$(DEFS) -I$(top_srcdir)/src -I$(top_builddir) $(CPPFLAGS) $(CFLAGS) -L$(top_builddir)/tests/.libs -lmpc-tests -lmpc -lm $(LIBS)
check_PROGRAMS = tabs tacos tacosh tadd tadd_fr tadd_si tadd_ui targ tasin \
-tasinh tatan tatanh tconj tcos tcosh tdiv tdiv_2exp tdiv_fr tdiv_ui texp tfma \
-tfr_div tfr_sub timag tio_str tlog tlog10 tmul tmul_2exp tmul_fr tmul_i \
-tmul_si tmul_ui tneg tnorm tpow tpow_ld tpow_d tpow_fr tpow_si tpow_ui tpow_z \
+tasinh tatan tatanh tconj tcos tcosh tdiv tdiv_2si tdiv_2ui tdiv_fr tdiv_ui \
+texp tfma tfr_div tfr_sub timag tio_str tlog tlog10 \
+tmul tmul_2si tmul_2ui tmul_fr tmul_i tmul_si tmul_ui \
+tneg tnorm tpow tpow_ld tpow_d tpow_fr 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
diff --git a/tests/atan.dat b/tests/atan.dat
index ddb4d43..f3ba3ec 100644
--- a/tests/atan.dat
+++ b/tests/atan.dat
@@ -1,6 +1,6 @@
# Data file for mpc_atan.
#
-# Copyright (C) 2009 INRIA
+# Copyright (C) 2009, 2012 INRIA
#
# This file is part of GNU MPC.
#
@@ -137,6 +137,14 @@
# general inputs
+ - 72 0x91EA521228BFC46ACAp-118 72 -0x9E96A01DBAD6470974p-73 72 0x84C3E02A5C6DEE8410p-118 72 -0x99B43C52A95A21C220p-73 U N
+- - 72 0x91EA521228BFC46AC9p-118 72 -0x9E96A01DBAD6470974p-73 72 0x84C3E02A5C6DEE8410p-118 72 -0x99B43C52A95A21C220p-73 D D
+- + 72 0x91EA521228BFC46AC9p-118 72 -0x9E96A01DBAD6470973p-73 72 0x84C3E02A5C6DEE8410p-118 72 -0x99B43C52A95A21C220p-73 D U
++ + 72 0x91EA521228BFC46ACAp-118 72 0x9E96A01DBAD6470974p-73 72 0x84C3E02A5C6DEE8410p-118 72 0x99B43C52A95A21C220p-73 U N
+- + 72 0x91EA521228BFC46AC9p-118 72 0x9E96A01DBAD6470974p-73 72 0x84C3E02A5C6DEE8410p-118 72 0x99B43C52A95A21C220p-73 D U
+- - 72 0x91EA521228BFC46AC9p-118 72 0x9E96A01DBAD6470973p-73 72 0x84C3E02A5C6DEE8410p-118 72 0x99B43C52A95A21C220p-73 D D
+ - 156 -0xC90FDAA22167B20DB08A0C3B1FF415CABE49624p-155 156 0xEA84E971BD52E49CCEE036E303D5ECB2D9D9B9Ap-222 156 -0xF0CE58073F866A53F25DB85DE8D503FBDD81051p-109 156 0xCF81D7C76BB9754A52056CB0F144B0C6700CC8Cp-128 N N
- - 2 0.75 2 -3 2 0x1p-7 2 -1 N N
- + 2 0.75 2 3 2 0x1p-7 2 1 N N
+
+# improve test coverage
++ - 57 -0x1.921fb54442d184 57 -0x8.a7e33db93ecf18@-34 57 -0xa.529626a89a1960@23 57 -0x3.9a5472b5709e74@14 N N
diff --git a/tests/div.dat b/tests/div.dat
index 2cffc7e..6f5e600 100644
--- a/tests/div.dat
+++ b/tests/div.dat
@@ -1,6 +1,6 @@
# Data file for mpc_div.
#
-# Copyright (C) 2008, 2009, 2010, 2011 INRIA
+# Copyright (C) 2008, 2009, 2010, 2011, 2012 INRIA
#
# This file is part of GNU MPC.
#
@@ -2478,3 +2478,9 @@
0 + 2 0 2 inf 10 0x3ffp1073741813 10 0x3ffp1073741813 10 0x2abp-10 10 -0x2abp-10 N N
# negative overflow
0 - 2 0 2 -inf 10 -0x3ffp1073741813 10 -0x3ffp1073741813 10 0x2abp-10 10 -0x2abp-10 N N
+
+# examples to exercise underflow
+# (1.5+i)*2^emin/(1-i) gives (0.25 + 1.25*i)*2^emin
+- - 2 0 2 0x1p-1073741823 2 0x3p-1073741824 2 0x1p-1073741823 2 1 2 -1 Z Z
+# (1.5+i)*2^emin/(1+i) gives (1.25 - 0.25*i)*2^emin
+- + 2 0x1p-1073741823 2 -0 2 0x3p-1073741824 2 0x1p-1073741823 2 1 2 1 Z Z
diff --git a/tests/log.dat b/tests/log.dat
index 57e3b35..ee95025 100644
--- a/tests/log.dat
+++ b/tests/log.dat
@@ -1,13 +1,13 @@
# Data test file for mpc_log.
#
-# Copyright (C) 2008, 2009, 2010 INRIA
+# Copyright (C) 2008, 2009, 2010, 2012 INRIA
#
# This file is part of GNU MPC.
#
# GNU MPC 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 3 of the License, or (at your
-#o ption) any later version.
+# option) any later version.
#
# GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
@@ -166,10 +166,25 @@
+ + 53 0x162E4301C0025p-23 2 0x1p0 2 0x1p67108864 2 0x1p67108864 U U
+ + 53 0xB1721802E8F1p-21 2 0x1p0 2 0x1p134217728 2 0x1p134217728 U U
+ + 53 0x2C5C85FF57581p-22 2 0x1p0 2 0x1p268435456 2 0x1p268435456 U U
-# Due to intermediate overflow, the following result has real part infinity
-# instead of the correct result. Since this may happen in other parts of the
-# library as well, we do not consider it a bug for the moment.
-# + + 53 0x58B90BFD4BCBFp-22 2 0x1p0 2 0x1p536870912 2 0x1p536870912 U U
-# log(-1 + i*eps) : infinite loop ?
-# 0 0 2 0 2 0b11 2 -1 2 0x1p-1073741813 N N
+# Example leading to intermediate overflow in x^2+y^2
++ + 53 0x58B90BFD4BCBFp-22 2 0x1p0 2 0x1p536870912 2 0x1p536870912 U U
++ + 53 0x58B90BFAA42A98p-25 2 0x1p0 2 0x3p1073741821 2 0x3p1073741821 U U
+# Example leading to intermediate underflow in x^2+y^2
+- - 53 -0x58B90BFB3775A8p-25 2 0x3p-2 2 0x1p-1073741824 2 0x1p-1073741824 D D
+
+# log (-1 + i*eps), looped in previous version
+- - 2 0 2 3 2 -1 2 0x1p-1073741813 N N
+- - 2 0 2 3 2 -1 2 0x1p-1073741813 D D
++ + 2 0x1p-1073741824 2 4 2 -1 2 0x1p-1073741813 U U
+# log(1 + i*eps), could cause similar problems
+- + 2 0 2 0x1p-1073741824 2 1 2 0x1p-1073741824 N N
+- - 2 0 2 0 2 1 2 0x1p-1073741824 D D
++ + 2 0x1p-1073741824 2 0x1p-1073741824 2 1 2 0x1p-1073741824 U U
+# log (eps + i)
+- - 2 0 2 0x3p-1 2 0x1p-1073741824 2 1 N N
+- - 2 0 2 0x3p-1 2 0x1p-1073741824 2 1 D D
++ + 2 0x1p-1073741824 2 2 2 0x1p-1073741824 2 1 U U
+
+# log (close to 1 + i*eps), improves test coverage
++ - 2 -0x1p-36 2 0x1p-1073741824 36 0x0.FFFFFFFFF 2 0x1p-1073741824 N N
diff --git a/tests/mpc-tests.h b/tests/mpc-tests.h
index bf3fec9..fe3e452 100644
--- a/tests/mpc-tests.h
+++ b/tests/mpc-tests.h
@@ -43,8 +43,15 @@ along with this program. If not, see http://www.gnu.org/licenses/ .
} \
} while (0)
+#if defined (__cplusplus)
+extern "C" {
+#endif
__MPC_DECLSPEC int mpc_mul_naive (mpc_ptr, mpc_srcptr, mpc_srcptr, mpc_rnd_t);
__MPC_DECLSPEC int mpc_mul_karatsuba (mpc_ptr, mpc_srcptr, mpc_srcptr, mpc_rnd_t);
+__MPC_DECLSPEC int mpc_fma_naive (mpc_ptr, mpc_srcptr, mpc_srcptr, mpc_srcptr, mpc_rnd_t);
+#if defined (__cplusplus)
+}
+#endif
/* end pieces copied from mpc-impl.h */
#define MPC_OUT(x) \
@@ -58,7 +65,7 @@ do { \
#define MPFR_OUT(x) \
do { \
printf (#x "[%lu]=", (unsigned long int) mpfr_get_prec (x)); \
- mpfr_out_str (stdout, 2, 0, x, GMP_RNDN); \
+ mpfr_out_str (stdout, 2, 0, x, MPFR_RNDN); \
printf ("\n"); \
} while (0)
diff --git a/tests/mul.dat b/tests/mul.dat
index 9ed14bd..13ea1e6 100755
--- a/tests/mul.dat
+++ b/tests/mul.dat
@@ -1,6 +1,6 @@
# Data file for mpc_mul
#
-# Copyright (C) 2008, 2010, 2011 INRIA
+# Copyright (C) 2008, 2010, 2011, 2012 INRIA
#
# This file is part of GNU MPC.
#
@@ -173,3 +173,6 @@
# improve code coverage: case where sign_x==0 in mpc_mul_karatsuba
0 0 2000 6 2000 8 2000 4 2000 2 2000 2 2000 1 N N
0 0 2000 0 2000 4 2000 2 2000 2 2000 1 2000 1 N N
+
++ 0 2 1 2 0x2p-536870913 2 1 2 0x1p-536870913 2 1 2 0x1p-536870913 N N
+0 - 2 0 2 1 2 0x1p-536870913 2 1 2 1 2 0x1p-536870913 N N
diff --git a/tests/pow.dat b/tests/pow.dat
index 15eab18..1105f59 100644
--- a/tests/pow.dat
+++ b/tests/pow.dat
@@ -454,3 +454,16 @@
- + 2 +0 2 -0 2 4 2 3 28 -744261116 2 +0 N N
- - 2 +0 2 +0 2 4 2 -3 28 -744261116 2 +0 N N
+# exact powers with non-integer exponent
+0 0 2 1 2 1 2 0 2 2 2 0.5 2 0 N N
+0 0 2 -2 2 2 2 0 2 2 2 1.5 2 0 N N
+0 0 2 1 2 64 12 -4095 2 128 2 0.5 2 0 N N
+0 0 3 5 2 3 2 16 4 30 2 0.5 2 0 N N
+0 0 7 97 7 99 6 -392 14 19206 2 0.5 2 0 N N
+0 0 6 63 6 61 5 248 18 7686 2 0.5 2 0 N N
+0 0 6 63 6 61 24 -59013092 17 3812256 2 0.25 2 0 N N
+
+0 + 2 0 2 0x3p-6 2 -1 2 0 2 0.5 2 1 N N
++ + 2 6 2 1 41 -0x2ce019e6f1e 36 0x1878418ba20 2 0.0625 2 0 N N
++ + 4 11 2 1 111 -0x73558286726957f922819cbeffff 109 0x1c484a8b32dbf409e966a8c00000 2 0x1p-5 2 0 N N
++ + 5 21 2 1 282 -0x24ea91ddba938e750d999f1075444e15d6ca0fff6a19c8cbefe6260261fd57effffffff 278 0x390aa828a3d933391ab999b0b0aa71aafbfc7b127fe30c84d107634940ba8000000000 2 0x1p-6 2 0 N N
diff --git a/tests/random.c b/tests/random.c
index aa06355..0730fee 100644
--- a/tests/random.c
+++ b/tests/random.c
@@ -1,6 +1,6 @@
/* random.c -- Handle seed for random numbers.
-// Copyright (C) 2008, 2009, 2010, 2011 INRIA
+// Copyright (C) 2008, 2009, 2010, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -140,9 +140,9 @@ test_default_random (mpc_ptr z, mpfr_exp_t emin, mpfr_exp_t emax,
zero_im_p = !zero_re_p;
}
if (zero_re_p)
- mpfr_set_ui (mpc_realref (z), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (z), 0, MPFR_RNDN);
if (zero_im_p)
- mpfr_set_ui (mpc_imagref (z), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_imagref (z), 0, MPFR_RNDN);
}
if (!mpfr_zero_p (mpc_realref (z)))
mpfr_set_exp (mpc_realref (z), (mpfr_exp_t) gmp_urandomm_ui (rands, range) + emin);
@@ -154,7 +154,7 @@ test_default_random (mpc_ptr z, mpfr_exp_t emin, mpfr_exp_t emax,
negative_probability = 256;
r = gmp_urandomb_ui (rands, 16);
if ((r & 0xFF) < negative_probability)
- mpfr_neg (mpc_realref (z), mpc_realref (z), GMP_RNDN);
+ mpfr_neg (mpc_realref (z), mpc_realref (z), MPFR_RNDN);
if (((r>>8) & 0xFF) < negative_probability)
- mpfr_neg (mpc_imagref (z), mpc_imagref (z), GMP_RNDN);
+ mpfr_neg (mpc_imagref (z), mpc_imagref (z), MPFR_RNDN);
}
diff --git a/tests/read_data.c b/tests/read_data.c
index a9f3648..c1cf677 100644
--- a/tests/read_data.c
+++ b/tests/read_data.c
@@ -1,6 +1,6 @@
/* read_data,c -- Read data file and check function.
-Copyright (C) 2008, 2009, 2010, 2011 INRIA
+Copyright (C) 2008, 2009, 2010, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -41,7 +41,7 @@ int nextchar;
: (inex) == -1 ? "-1" : "0"
static const char *mpfr_rnd_mode [] =
- { "GMP_RNDN", "GMP_RNDZ", "GMP_RNDU", "GMP_RNDD" };
+ { "MPFR_RNDN", "MPFR_RNDZ", "MPFR_RNDU", "MPFR_RNDD" };
const char *rnd_mode[] =
{ "MPC_RNDNN", "MPC_RNDZN", "MPC_RNDUN", "MPC_RNDDN",
@@ -238,16 +238,16 @@ read_mpfr_rounding_mode (FILE *fp, mpfr_rnd_t* rnd)
switch (nextchar)
{
case 'n': case 'N':
- *rnd = GMP_RNDN;
+ *rnd = MPFR_RNDN;
break;
case 'z': case 'Z':
- *rnd = GMP_RNDZ;
+ *rnd = MPFR_RNDZ;
break;
case 'u': case 'U':
- *rnd = GMP_RNDU;
+ *rnd = MPFR_RNDU;
break;
case 'd': case 'D':
- *rnd = GMP_RNDD;
+ *rnd = MPFR_RNDD;
break;
default:
printf ("Error: Unexpected rounding mode '%c' in file '%s' line %lu\n",
@@ -271,7 +271,7 @@ read_mpc_rounding_mode (FILE *fp, mpc_rnd_t* rnd)
mpfr_rnd_t re, im;
read_mpfr_rounding_mode (fp, &re);
read_mpfr_rounding_mode (fp, &im);
- *rnd = RNDC (re, im);
+ *rnd = MPC_RND (re, im);
}
void
@@ -382,7 +382,7 @@ read_mpfr_mantissa (FILE *fp, mpfr_ptr x)
exit (1);
}
ungetc (nextchar, fp);
- if (mpfr_inp_str (x, fp, 0, GMP_RNDN) == 0) {
+ if (mpfr_inp_str (x, fp, 0, MPFR_RNDN) == 0) {
printf ("Error: Impossible to read mpfr mantissa "
"in file '%s' line %lu\n",
pathname, line_number);
@@ -419,10 +419,10 @@ read_mpc (FILE *fp, mpc_ptr z, known_signs_t *ks)
static void
check_compatible (int inex, mpfr_t expected, mpfr_rnd_t rnd, const char *s)
{
- if ((rnd == GMP_RNDU && inex == -1) ||
- (rnd == GMP_RNDD && inex == +1) ||
- (rnd == GMP_RNDZ && !mpfr_signbit (expected) && inex == +1) ||
- (rnd == GMP_RNDZ && mpfr_signbit (expected) && inex == -1))
+ if ((rnd == MPFR_RNDU && inex == -1) ||
+ (rnd == MPFR_RNDD && inex == +1) ||
+ (rnd == MPFR_RNDZ && !mpfr_signbit (expected) && inex == +1) ||
+ (rnd == MPFR_RNDZ && mpfr_signbit (expected) && inex == -1))
{
if (s != NULL)
printf ("Incompatible ternary value '%c' (%s part) in file '%s' line %lu\n",
@@ -594,56 +594,56 @@ set_mpfr_flags (int counter)
static void
check_mpfr_flags (int counter)
{
- int old, new;
+ int old, neu;
old = (counter & 1) != 0;
- new = mpfr_underflow_p () != 0;
- if (old && (new == 0))
+ neu = mpfr_underflow_p () != 0;
+ if (old && (neu == 0))
{
printf ("Error, underflow flag has been modified from %d to %d\n",
- old, new);
+ old, neu);
exit (1);
}
old = (counter & 2) != 0;
- new = mpfr_overflow_p () != 0;
- if (old && (new == 0))
+ neu = mpfr_overflow_p () != 0;
+ if (old && (neu == 0))
{
printf ("Error, overflow flag has been modified from %d to %d\n",
- old, new);
+ old, neu);
exit (1);
}
#ifdef mpfr_divby0_p
old = (counter & 4) != 0;
- new = mpfr_divby0_p () != 0;
- if (old && (new == 0))
+ neu = mpfr_divby0_p () != 0;
+ if (old && (neu == 0))
{
printf ("Error, divby0 flag has been modified from %d to %d\n",
- old, new);
+ old, neu);
exit (1);
}
#endif
old = (counter & 8) != 0;
- new = mpfr_nanflag_p () != 0;
- if (old && (new == 0))
+ neu = mpfr_nanflag_p () != 0;
+ if (old && (neu == 0))
{
printf ("Error, nanflag flag has been modified from %d to %d\n",
- old, new);
+ old, neu);
exit (1);
}
old = (counter & 16) != 0;
- new = mpfr_inexflag_p () != 0;
- if (old && (new == 0))
+ neu = mpfr_inexflag_p () != 0;
+ if (old && (neu == 0))
{
printf ("Error, inexflag flag has been modified from %d to %d\n",
- old, new);
+ old, neu);
exit (1);
}
old = (counter & 32) != 0;
- new = mpfr_erangeflag_p () != 0;
- if (old && (new == 0))
+ neu = mpfr_erangeflag_p () != 0;
+ if (old && (neu == 0))
{
printf ("Error, erangeflag flag has been modified from %d to %d\n",
- old, new);
+ old, neu);
exit (1);
}
}
@@ -657,7 +657,7 @@ data_check (mpc_function function, const char *file_name)
int inex_re;
mpfr_t x1, x2;
- mpfr_rnd_t mpfr_rnd = GMP_RNDN;
+ mpfr_rnd_t mpfr_rnd = MPFR_RNDN;
int sign_real;
int inex_im;
diff --git a/tests/sqrt.dat b/tests/sqrt.dat
index 8a9e7ca..076f2af 100644
--- a/tests/sqrt.dat
+++ b/tests/sqrt.dat
@@ -123,6 +123,7 @@
- + 375 1 375 0xf.8a8aae3080b3dd665e316d262fd54c1ca22a83dc9acb92ef6p-202281177 375 1 375 0xf.8a8aae3080b3dd665e316d262fd54c1ca22a83dc9acb92ef6p-202281176 N N
+ + 375 0x1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004 375 0xf.8a8aae3080b3dd665e316d262fd54c1ca22a83dc9acb92ef6p-202281177 375 1 375 0xf.8a8aae3080b3dd665e316d262fd54c1ca22a83dc9acb92ef6p-202281176 U U
- - 375 1 375 0xf.8a8aae3080b3dd665e316d262fd54c1ca22a83dc9acb92ef5fffffffffffffffffffffffffffffffffffffffffffep-202281177 375 1 375 0xf.8a8aae3080b3dd665e316d262fd54c1ca22a83dc9acb92ef6p-202281176 D D
+- + 375 1 375 -0xf.8a8aae3080b3dd665e316d262fd54c1ca22a83dc9acb92ef5fffffffffffffffffffffffffffffffffffffffffffep-202281177 375 1 375 -0xf.8a8aae3080b3dd665e316d262fd54c1ca22a83dc9acb92ef6p-202281176 D U
- - 375 1 375 0xf.8a8aae3080b3dd665e316d262fd54c1ca22a83dc9acb92ef5fffffffffffffffffffffffffffffffffffffffffffep-202281177 375 1 375 0xf.8a8aae3080b3dd665e316d262fd54c1ca22a83dc9acb92ef6p-202281176 Z Z
- - 375 1 375 -0xf.8a8aae3080b3dd665e316d262fd54c1ca22a83dc9acb92ef6p-202281177 375 1 375 -0xf.8a8aae3080b3dd665e316d262fd54c1ca22a83dc9acb92ef6p-202281176 N N
+ + 375 0x1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004 375 -0xf.8a8aae3080b3dd665e316d262fd54c1ca22a83dc9acb92ef5fffffffffffffffffffffffffffffffffffffffffffep-202281177 375 1 375 -0xf.8a8aae3080b3dd665e316d262fd54c1ca22a83dc9acb92ef6p-202281176 U U
diff --git a/tests/tadd.c b/tests/tadd.c
index 1253b64..11a305b 100644
--- a/tests/tadd.c
+++ b/tests/tadd.c
@@ -1,6 +1,6 @@
/* tadd -- test file for mpc_add.
-Copyright (C) 2008, 2010, 2011 INRIA
+Copyright (C) 2008, 2010, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -37,7 +37,7 @@ check_ternary_value (void)
mpc_set_prec (y, prec);
mpc_set_ui (x, 1, MPC_RNDNN);
- mpc_mul_2exp (x, x, (unsigned long int) prec, MPC_RNDNN);
+ mpc_mul_2ui (x, x, (unsigned long int) prec, MPC_RNDNN);
mpc_set_ui (y, 1, MPC_RNDNN);
if (mpc_add (z, x, y, MPC_RNDNN) == 0)
diff --git a/tests/tadd_fr.c b/tests/tadd_fr.c
index d5ed163..0f1a5cf 100644
--- a/tests/tadd_fr.c
+++ b/tests/tadd_fr.c
@@ -1,6 +1,6 @@
/* tadd_fr -- test file for mpc_add_fr.
-Copyright (C) 2008, 2010 INRIA
+Copyright (C) 2008, 2010, 2012 INRIA
This file is part of GNU MPC.
@@ -37,7 +37,7 @@ check_ternary_value (mpfr_prec_t prec_max, mpfr_prec_t step)
mpfr_set_prec (f, prec);
mpc_set_ui (z, 1, MPC_RNDNN);
- mpfr_set_ui (f, 1, GMP_RNDN);
+ mpfr_set_ui (f, 1, MPFR_RNDN);
if (mpc_add_fr (z, z, f, MPC_RNDNZ))
{
printf ("Error in mpc_add_fr: 1+1 should be exact\n");
@@ -45,7 +45,7 @@ check_ternary_value (mpfr_prec_t prec_max, mpfr_prec_t step)
}
mpc_set_ui (z, 1, MPC_RNDNN);
- mpc_mul_2exp (z, z, (unsigned long int) prec, MPC_RNDNN);
+ mpc_mul_2ui (z, z, (unsigned long int) prec, MPC_RNDNN);
if (mpc_add_fr (z, z, f, MPC_RNDNN) == 0)
{
fprintf (stderr, "Error in mpc_add_fr: 2^prec+1 cannot be exact\n");
diff --git a/tests/tadd_si.c b/tests/tadd_si.c
index 20fb39d..da12a7a 100644
--- a/tests/tadd_si.c
+++ b/tests/tadd_si.c
@@ -1,6 +1,6 @@
/* tadd_si -- test file for mpc_add_si.
-Copyright (C) 2011 INRIA
+Copyright (C) 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -42,7 +42,7 @@ check_ternary_value (void)
exit (1);
}
- mpc_mul_2exp (z, z, (unsigned long int) prec, MPC_RNDNN);
+ mpc_mul_2ui (z, z, (unsigned long int) prec, MPC_RNDNN);
if (mpc_add_si (z, z, s, MPC_RNDNN) == 0) {
printf ("Error in mpc_add_si: 2^(prec+1)-1 cannot be exact\n");
exit (1);
diff --git a/tests/tadd_ui.c b/tests/tadd_ui.c
index 362ebde..4f8efea 100644
--- a/tests/tadd_ui.c
+++ b/tests/tadd_ui.c
@@ -1,6 +1,6 @@
/* tadd_ui -- test file for mpc_add_ui.
-Copyright (C) 2008, 2010 INRIA
+Copyright (C) 2008, 2010, 2012 INRIA
This file is part of GNU MPC.
@@ -41,7 +41,7 @@ check_ternary_value (void)
}
mpc_set_ui (z, 1, MPC_RNDNN);
- mpc_mul_2exp (z, z, (unsigned long int) prec, MPC_RNDNN);
+ mpc_mul_2ui (z, z, (unsigned long int) prec, MPC_RNDNN);
if (mpc_add_ui (z, z, 1, MPC_RNDNN) == 0)
{
printf ("Error in mpc_add_ui: 2^prec+1 cannot be exact\n");
diff --git a/tests/tan.dat b/tests/tan.dat
index d9ce811..ce4c097 100644
--- a/tests/tan.dat
+++ b/tests/tan.dat
@@ -125,6 +125,7 @@
# huge values
+ - 53 -0 53 -1 53 0x4580CBF242683p-3 53 -0x1B3E8A3660D279p-3 N N
+- - 53 +0 53 -1 53 -0x4580CBF242683p-3 53 -0x1B3E8A3660D279p-3 N N
+ + 53 -0 53 +1 53 -0x1B3E8A3660D279p-3 53 0x4580CBF242683p-3 N N
# some values taken from ttan.c
diff --git a/tests/tatan.c b/tests/tatan.c
index 8883588..ca93ec4 100644
--- a/tests/tatan.c
+++ b/tests/tatan.c
@@ -30,10 +30,10 @@ test_underflow (void)
mpfr_set_emin (-10);
mpc_init2 (z, 21);
- mpfr_set_si (mpc_realref(z), -1, GMP_RNDZ);
- mpfr_set_ui_2exp (mpc_imagref(z), 1, 20, GMP_RNDZ);
- mpfr_add_ui (mpc_imagref(z), mpc_imagref(z), 1, GMP_RNDZ);
- mpfr_div_2exp (mpc_imagref(z), mpc_imagref(z), 20, GMP_RNDZ);
+ mpfr_set_si (mpc_realref(z), -1, MPFR_RNDZ);
+ mpfr_set_ui_2exp (mpc_imagref(z), 1, 20, MPFR_RNDZ);
+ mpfr_add_ui (mpc_imagref(z), mpc_imagref(z), 1, MPFR_RNDZ);
+ mpfr_div_2exp (mpc_imagref(z), mpc_imagref(z), 20, MPFR_RNDZ);
mpc_atan (z, z, MPC_RNDNN);
if (mpfr_cmp_si_2exp (mpc_realref(z), -1066635, 20) != 0 ||
mpfr_cmp_si_2exp (mpc_imagref(z), 1687619, 22))
diff --git a/tests/tcos.c b/tests/tcos.c
index 66a85ba..dafc01d 100644
--- a/tests/tcos.c
+++ b/tests/tcos.c
@@ -1,6 +1,6 @@
/* tcos -- test file for mpc_cos.
-Copyright (C) 2008, 2009, 2011 INRIA
+Copyright (C) 2008, 2009, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -30,13 +30,13 @@ bug20090105 (void)
mpc_init2 (got, 324);
mpfr_set_str (mpc_realref(op), "-3.f1813b1487372434fea4414a520f65a343a16d0ec1ffb"
- "b2b880154db8d63377ce788fc4215c450300@1", 16, GMP_RNDN);
+ "b2b880154db8d63377ce788fc4215c450300@1", 16, MPFR_RNDN);
mpfr_set_str (mpc_imagref(op), "-2.b7a0c80bcacf1ccbbac614bf53a58b672b1b503161bee"
- "59a82e46a23570b652f7ba5f01ef766d1c50", 16,GMP_RNDN);
+ "59a82e46a23570b652f7ba5f01ef766d1c50", 16,MPFR_RNDN);
mpfr_set_str (mpc_realref(expected), "7.57c5b08a2b11b660d906a354289b0724b9c4b237"
- "95abe33424e8d9858e534bd5d776ddd18e34b0240", 16, GMP_RNDN);
+ "95abe33424e8d9858e534bd5d776ddd18e34b0240", 16, MPFR_RNDN);
mpfr_set_str (mpc_imagref(expected), "-1.f41a389646d068e0263561cb3c5d1df763945ad"
- "ed9339f2a98387a3c4f97dbfd8a08b7d0af2f11b46", 16,GMP_RNDN);
+ "ed9339f2a98387a3c4f97dbfd8a08b7d0af2f11b46", 16,MPFR_RNDN);
mpc_cos (got, op, MPC_RNDNN);
if (mpc_cmp (got, expected) != 0)
diff --git a/tests/tcosh.c b/tests/tcosh.c
index 57b5601..0d6a9da 100644
--- a/tests/tcosh.c
+++ b/tests/tcosh.c
@@ -1,6 +1,6 @@
/* test file for mpc_cosh.
-Copyright (C) 2008, 2009, 2010, 2011 INRIA
+Copyright (C) 2008, 2009, 2010, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -38,8 +38,8 @@ pure_real_argument (void)
/* cosh(1 +i*0) = cosh(1) +i*0 */
mpc_set_ui_ui (z, 1, 0, MPC_RNDNN);
- mpfr_cosh (mpc_realref (u), mpc_realref (z), GMP_RNDN);
- mpfr_set_ui (mpc_imagref (u), 0, GMP_RNDN);
+ mpfr_cosh (mpc_realref (u), mpc_realref (z), MPFR_RNDN);
+ mpfr_set_ui (mpc_imagref (u), 0, MPFR_RNDN);
mpc_cosh (cosh_z, z, MPC_RNDNN);
if (mpc_cmp (cosh_z, u) != 0 || mpfr_signbit (mpc_imagref (cosh_z)))
TEST_FAILED ("mpc_cosh", z, cosh_z, u, MPC_RNDNN);
@@ -84,8 +84,8 @@ pure_imaginary_argument (void)
/* cosh(+0 +i) = cos(1) + i*0 */
mpc_set_ui_ui (z, 0, 1, MPC_RNDNN);
- mpfr_cos (mpc_realref (u), mpc_imagref (z), GMP_RNDN);
- mpfr_set_ui (mpc_imagref (u), 0, GMP_RNDN);
+ mpfr_cos (mpc_realref (u), mpc_imagref (z), MPFR_RNDN);
+ mpfr_set_ui (mpc_imagref (u), 0, MPFR_RNDN);
mpc_cosh (cosh_z, z, MPC_RNDNN);
if (mpc_cmp (cosh_z, u) != 0 || mpfr_signbit (mpc_imagref (cosh_z)))
TEST_FAILED ("mpc_cosh", z, cosh_z, u, MPC_RNDNN);
diff --git a/tests/tdiv_2exp.c b/tests/tdiv_2si.c
index 91b03af..5046201 100644
--- a/tests/tdiv_2exp.c
+++ b/tests/tdiv_2si.c
@@ -1,6 +1,6 @@
-/* tdiv_2exp -- test file for mpc_div_2exp.
+/* tdiv_2si -- test file for mpc_div_2si.
-Copyright (C) 2008 INRIA
+Copyright (C) 2012 INRIA
This file is part of GNU MPC.
@@ -23,7 +23,7 @@ along with this program. If not, see http://www.gnu.org/licenses/ .
int
main (void)
{
- DECL_FUNC (CCU, f, mpc_div_2exp);
+ DECL_FUNC (CCS, f, mpc_div_2si);
test_start ();
diff --git a/tests/tdiv_2ui.c b/tests/tdiv_2ui.c
new file mode 100644
index 0000000..6cc8f14
--- /dev/null
+++ b/tests/tdiv_2ui.c
@@ -0,0 +1,35 @@
+/* tdiv_2ui -- test file for mpc_div_2ui.
+
+Copyright (C) 2008, 2012 INRIA
+
+This file is part of GNU MPC.
+
+GNU MPC 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 3 of the License, or (at your
+option) any later version.
+
+GNU MPC 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 this program. If not, see http://www.gnu.org/licenses/ .
+*/
+
+#include "mpc-tests.h"
+
+int
+main (void)
+{
+ DECL_FUNC (CCU, f, mpc_div_2ui);
+
+ test_start ();
+
+ tgeneric (f, 2, 1024, 7, -1);
+
+ test_end ();
+
+ return 0;
+}
diff --git a/tests/tfma.c b/tests/tfma.c
index 02eed66..81bc167 100644
--- a/tests/tfma.c
+++ b/tests/tfma.c
@@ -62,7 +62,7 @@ static void
check_random (void)
{
mpfr_prec_t prec;
- mpfr_rnd_t rnd_re, rnd_im;
+ int rnd_re, rnd_im;
mpc_t a, b, c;
mpc_init2 (a, 1000);
@@ -80,7 +80,7 @@ check_random (void)
for (rnd_re = 0; rnd_re < 4; rnd_re ++)
for (rnd_im = 0; rnd_im < 4; rnd_im ++)
- cmpfma (a, b, c, RNDC(rnd_re, rnd_im));
+ cmpfma (a, b, c, MPC_RND (rnd_re, rnd_im));
}
mpc_clear (a);
diff --git a/tests/tgeneric.c b/tests/tgeneric.c
index 1ead958..cf56997 100644
--- a/tests/tgeneric.c
+++ b/tests/tgeneric.c
@@ -1,6 +1,6 @@
/* tgeneric.c -- File for generic tests.
-Copyright (C) 2008, 2009, 2010, 2011 INRIA
+Copyright (C) 2008, 2009, 2010, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -25,7 +25,7 @@ along with this program. If not, see http://www.gnu.org/licenses/ .
#define MPFR_CAN_ROUND(b,err,prec,rnd) \
(mpfr_zero_p (b) || mpfr_inf_p (b) \
|| mpfr_can_round (b, (long)mpfr_get_prec (b) - (err), (rnd), \
- GMP_RNDZ, (prec) + ((rnd)==GMP_RNDN)))
+ MPFR_RNDZ, (prec) + ((rnd)==MPFR_RNDN)))
/* functions with one input, one output */
static void
@@ -563,8 +563,8 @@ static void
reuse_fc (mpc_function* function, mpc_ptr z, mpc_ptr x, mpfr_ptr expected)
{
mpc_set (x, z, MPC_RNDNN); /* exact */
- function->pointer.FC (expected, z, GMP_RNDN);
- function->pointer.FC (mpc_realref (x), x, GMP_RNDN);
+ function->pointer.FC (expected, z, MPFR_RNDN);
+ function->pointer.FC (mpc_realref (x), x, MPFR_RNDN);
if (!same_mpfr_value (mpc_realref (x), expected, 1))
{
mpfr_t got;
@@ -577,7 +577,7 @@ reuse_fc (mpc_function* function, mpc_ptr z, mpc_ptr x, mpfr_ptr expected)
exit (1);
}
mpc_set (x, z, MPC_RNDNN); /* exact */
- function->pointer.FC (mpc_imagref (x), x, GMP_RNDN);
+ function->pointer.FC (mpc_imagref (x), x, MPFR_RNDN);
if (!same_mpfr_value (mpc_imagref (x), expected, 1))
{
mpfr_t got;
@@ -856,7 +856,7 @@ reuse_cuuc (mpc_function* function, unsigned long ul1, unsigned long ul2,
static mpfr_rnd_t
first_rnd_mode (void)
{
- return GMP_RNDN;
+ return MPFR_RNDN;
}
static mpfr_rnd_t
@@ -865,16 +865,16 @@ next_rnd_mode (mpfr_rnd_t curr)
when curr is the last rounding mode */
{
switch (curr) {
- case GMP_RNDN:
- return GMP_RNDZ;
- case GMP_RNDZ:
- return GMP_RNDU;
- case GMP_RNDU:
- return GMP_RNDD;
+ case MPFR_RNDN:
+ return MPFR_RNDZ;
+ case MPFR_RNDZ:
+ return MPFR_RNDU;
+ case MPFR_RNDU:
+ return MPFR_RNDD;
default:
/* return invalid guard value in mpfr_rnd_t */
#if MPFR_VERSION_MAJOR < 3
- return GMP_RNDNA;
+ return MPFR_RNDNA;
#else
return MPFR_RNDA; /* valid rounding type, but not (yet) used in mpc */
#endif
@@ -885,8 +885,8 @@ static int
is_valid_rnd_mode (mpfr_rnd_t curr)
/* returns 1 if curr is a valid rounding mode, and 0otherwise */
{
- if ( curr == GMP_RNDN || curr == GMP_RNDZ
- || curr == GMP_RNDU || curr == GMP_RNDD)
+ if ( curr == MPFR_RNDN || curr == MPFR_RNDZ
+ || curr == MPFR_RNDU || curr == MPFR_RNDD)
return 1;
else
return 0;
@@ -1010,25 +1010,25 @@ tgeneric (mpc_function function, mpfr_prec_t prec_min,
switch (special)
{
case 1:
- mpfr_set_ui (mpc_realref (z1), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (z1), 0, MPFR_RNDN);
break;
case 2:
mpfr_set_inf (mpc_realref (z1), +1);
break;
case 3:
- mpfr_set_ui (mpc_imagref (z1), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_imagref (z1), 0, MPFR_RNDN);
break;
case 4:
mpfr_set_inf (mpc_imagref (z1), -1);
break;
case 5:
- mpfr_set_ui (mpc_realref (z2), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (z2), 0, MPFR_RNDN);
break;
case 6:
mpfr_set_inf (mpc_realref (z2), -1);
break;
case 7:
- mpfr_set_ui (mpc_imagref (z2), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_imagref (z2), 0, MPFR_RNDN);
break;
case 8:
mpfr_set_inf (mpc_imagref (z2), +1);
@@ -1045,25 +1045,25 @@ tgeneric (mpc_function function, mpfr_prec_t prec_min,
switch (special)
{
case 1:
- mpfr_set_ui (mpc_realref (z1), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (z1), 0, MPFR_RNDN);
break;
case 2:
mpfr_set_inf (mpc_realref (z1), +1);
break;
case 3:
- mpfr_set_ui (mpc_imagref (z1), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_imagref (z1), 0, MPFR_RNDN);
break;
case 4:
mpfr_set_inf (mpc_imagref (z1), -1);
break;
case 5:
- mpfr_set_ui (mpc_realref (z2), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (z2), 0, MPFR_RNDN);
break;
case 6:
mpfr_set_inf (mpc_realref (z2), -1);
break;
case 7:
- mpfr_set_ui (mpc_imagref (z2), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_imagref (z2), 0, MPFR_RNDN);
break;
case 8:
mpfr_set_inf (mpc_imagref (z2), +1);
@@ -1078,13 +1078,13 @@ tgeneric (mpc_function function, mpfr_prec_t prec_min,
switch (special)
{
case 1:
- mpfr_set_ui (mpc_realref (z1), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (z1), 0, MPFR_RNDN);
break;
case 2:
mpfr_set_inf (mpc_realref (z1), +1);
break;
case 3:
- mpfr_set_ui (mpc_imagref (z1), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_imagref (z1), 0, MPFR_RNDN);
break;
case 4:
mpfr_set_inf (mpc_imagref (z1), -1);
@@ -1095,21 +1095,21 @@ tgeneric (mpc_function function, mpfr_prec_t prec_min,
mpc_set_prec (z2, 128);
do {
test_default_random (z2, 0, 64, 128, zero_probability);
- } while (!mpfr_fits_ulong_p (mpc_realref (z2), GMP_RNDN));
- ul1 = mpfr_get_ui (mpc_realref(z2), GMP_RNDN);
+ } while (!mpfr_fits_ulong_p (mpc_realref (z2), MPFR_RNDN));
+ ul1 = mpfr_get_ui (mpc_realref(z2), MPFR_RNDN);
mpc_set_prec (z2, prec);
mpc_set_prec (z3, prec);
mpc_set_prec (zzzz, 4*prec);
switch (special)
{
case 1:
- mpfr_set_ui (mpc_realref (z1), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (z1), 0, MPFR_RNDN);
break;
case 2:
mpfr_set_inf (mpc_realref (z1), +1);
break;
case 3:
- mpfr_set_ui (mpc_imagref (z1), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_imagref (z1), 0, MPFR_RNDN);
break;
case 4:
mpfr_set_inf (mpc_imagref (z1), -1);
@@ -1123,23 +1123,23 @@ tgeneric (mpc_function function, mpfr_prec_t prec_min,
mpc_set_prec (z2, 128);
do {
test_default_random (z2, 0, 64, 128, zero_probability);
- } while (!mpfr_fits_ulong_p (mpc_realref (z2), GMP_RNDN)
- ||!mpfr_fits_ulong_p (mpc_imagref (z2), GMP_RNDN));
- ul1 = mpfr_get_ui (mpc_realref(z2), GMP_RNDN);
- ul2 = mpfr_get_ui (mpc_imagref(z2), GMP_RNDN);
+ } while (!mpfr_fits_ulong_p (mpc_realref (z2), MPFR_RNDN)
+ ||!mpfr_fits_ulong_p (mpc_imagref (z2), MPFR_RNDN));
+ ul1 = mpfr_get_ui (mpc_realref(z2), MPFR_RNDN);
+ ul2 = mpfr_get_ui (mpc_imagref(z2), MPFR_RNDN);
mpc_set_prec (z2, prec);
mpc_set_prec (z3, prec);
mpc_set_prec (zzzz, 4*prec);
switch (special)
{
case 1:
- mpfr_set_ui (mpc_realref (z1), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (z1), 0, MPFR_RNDN);
break;
case 2:
mpfr_set_inf (mpc_realref (z1), +1);
break;
case 3:
- mpfr_set_ui (mpc_imagref (z1), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_imagref (z1), 0, MPFR_RNDN);
break;
case 4:
mpfr_set_inf (mpc_imagref (z1), -1);
@@ -1156,21 +1156,21 @@ tgeneric (mpc_function function, mpfr_prec_t prec_min,
mpc_set_prec (z2, 128);
do {
test_default_random (z2, 0, 64, 128, zero_probability);
- } while (!mpfr_fits_slong_p (mpc_realref (z2), GMP_RNDN));
- lo = mpfr_get_si (mpc_realref(z2), GMP_RNDN);
+ } while (!mpfr_fits_slong_p (mpc_realref (z2), MPFR_RNDN));
+ lo = mpfr_get_si (mpc_realref(z2), MPFR_RNDN);
mpc_set_prec (z2, prec);
mpc_set_prec (z3, prec);
mpc_set_prec (zzzz, 4*prec);
switch (special)
{
case 1:
- mpfr_set_ui (mpc_realref (z1), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (z1), 0, MPFR_RNDN);
break;
case 2:
mpfr_set_inf (mpc_realref (z1), +1);
break;
case 3:
- mpfr_set_ui (mpc_imagref (z1), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_imagref (z1), 0, MPFR_RNDN);
break;
case 4:
mpfr_set_inf (mpc_imagref (z1), -1);
@@ -1184,21 +1184,21 @@ tgeneric (mpc_function function, mpfr_prec_t prec_min,
mpc_set_prec (z2, 128);
do {
test_default_random (z2, 0, 64, 128, zero_probability);
- } while (!mpfr_fits_slong_p (mpc_realref (z2), GMP_RNDN));
- i = (int)mpfr_get_si (mpc_realref(z2), GMP_RNDN);
+ } while (!mpfr_fits_slong_p (mpc_realref (z2), MPFR_RNDN));
+ i = (int)mpfr_get_si (mpc_realref(z2), MPFR_RNDN);
mpc_set_prec (z2, prec);
mpc_set_prec (z3, prec);
mpc_set_prec (zzzz, 4*prec);
switch (special)
{
case 1:
- mpfr_set_ui (mpc_realref (z1), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (z1), 0, MPFR_RNDN);
break;
case 2:
mpfr_set_inf (mpc_realref (z1), +1);
break;
case 3:
- mpfr_set_ui (mpc_imagref (z1), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_imagref (z1), 0, MPFR_RNDN);
break;
case 4:
mpfr_set_inf (mpc_imagref (z1), -1);
@@ -1210,7 +1210,7 @@ tgeneric (mpc_function function, mpfr_prec_t prec_min,
break;
case CCF: case CFC:
mpfr_set_prec (x1, prec);
- mpfr_set (x1, mpc_realref (z1), GMP_RNDN);
+ mpfr_set (x1, mpc_realref (z1), MPFR_RNDN);
test_default_random (z1, exp_min, exp_max, 128, zero_probability);
mpc_set_prec (z2, prec);
mpc_set_prec (z3, prec);
@@ -1218,19 +1218,19 @@ tgeneric (mpc_function function, mpfr_prec_t prec_min,
switch (special)
{
case 1:
- mpfr_set_ui (mpc_realref (z1), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (z1), 0, MPFR_RNDN);
break;
case 2:
mpfr_set_inf (mpc_realref (z1), +1);
break;
case 3:
- mpfr_set_ui (mpc_imagref (z1), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_imagref (z1), 0, MPFR_RNDN);
break;
case 4:
mpfr_set_inf (mpc_imagref (z1), -1);
break;
case 5:
- mpfr_set_ui (x1, 0, GMP_RNDN);
+ mpfr_set_ui (x1, 0, MPFR_RNDN);
break;
case 6:
mpfr_set_inf (x1, +1);
@@ -1247,13 +1247,13 @@ tgeneric (mpc_function function, mpfr_prec_t prec_min,
switch (special)
{
case 1:
- mpfr_set_ui (mpc_realref (z1), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (z1), 0, MPFR_RNDN);
break;
case 2:
mpfr_set_inf (mpc_realref (z1), +1);
break;
case 3:
- mpfr_set_ui (mpc_imagref (z1), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_imagref (z1), 0, MPFR_RNDN);
break;
case 4:
mpfr_set_inf (mpc_imagref (z1), -1);
@@ -1268,13 +1268,13 @@ tgeneric (mpc_function function, mpfr_prec_t prec_min,
switch (special)
{
case 1:
- mpfr_set_ui (mpc_realref (z1), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (z1), 0, MPFR_RNDN);
break;
case 2:
mpfr_set_inf (mpc_realref (z1), +1);
break;
case 3:
- mpfr_set_ui (mpc_imagref (z1), 0, GMP_RNDN);
+ mpfr_set_ui (mpc_imagref (z1), 0, MPFR_RNDN);
break;
case 4:
mpfr_set_inf (mpc_imagref (z1), -1);
@@ -1288,13 +1288,13 @@ tgeneric (mpc_function function, mpfr_prec_t prec_min,
case C_CC:
for (rnd_im = first_rnd_mode (); is_valid_rnd_mode (rnd_im); rnd_im = next_rnd_mode (rnd_im))
tgeneric_c_cc (&function, z1, z2, z3, zzzz, z4,
- RNDC (rnd_re, rnd_im));
+ MPC_RND (rnd_re, rnd_im));
reuse_c_cc (&function, z1, z2, z3, z4);
break;
case CCCC:
for (rnd_im = first_rnd_mode (); is_valid_rnd_mode (rnd_im); rnd_im = next_rnd_mode (rnd_im))
tgeneric_cccc (&function, z1, z2, z3, z4, zzzz, z5,
- RNDC (rnd_re, rnd_im));
+ MPC_RND (rnd_re, rnd_im));
reuse_cccc (&function, z1, z2, z3, z4, z5);
break;
case FC:
@@ -1304,7 +1304,7 @@ tgeneric (mpc_function function, mpfr_prec_t prec_min,
case CC:
for (rnd_im = first_rnd_mode (); is_valid_rnd_mode (rnd_im); rnd_im = next_rnd_mode (rnd_im))
tgeneric_cc (&function, z1, z2, zzzz, z3,
- RNDC (rnd_re, rnd_im));
+ MPC_RND (rnd_re, rnd_im));
reuse_cc (&function, z1, z2, z3);
break;
case CC_C:
@@ -1312,49 +1312,49 @@ tgeneric (mpc_function function, mpfr_prec_t prec_min,
for (rnd2_re = first_rnd_mode (); is_valid_rnd_mode (rnd2_re); rnd2_re = next_rnd_mode (rnd2_re))
for (rnd2_im = first_rnd_mode (); is_valid_rnd_mode (rnd2_im); rnd2_im = next_rnd_mode (rnd2_im))
tgeneric_cc_c (&function, z1, z2, z3, zzzz, zzzz2, z4, z5,
- RNDC (rnd_re, rnd_im), RNDC (rnd2_re, rnd2_im));
+ MPC_RND (rnd_re, rnd_im), MPC_RND (rnd2_re, rnd2_im));
reuse_cc_c (&function, z1, z2, z3, z4, z5);
break;
case CFC:
for (rnd_im = first_rnd_mode (); is_valid_rnd_mode (rnd_im); rnd_im = next_rnd_mode (rnd_im))
tgeneric_cfc (&function, x1, z1, z2, zzzz, z3,
- RNDC (rnd_re, rnd_im));
+ MPC_RND (rnd_re, rnd_im));
reuse_cfc (&function, z1, x1, z2, z3);
break;
case CCF:
for (rnd_im = first_rnd_mode (); is_valid_rnd_mode (rnd_im); rnd_im = next_rnd_mode (rnd_im))
tgeneric_ccf (&function, z1, x1, z2, zzzz, z3,
- RNDC (rnd_re, rnd_im));
+ MPC_RND (rnd_re, rnd_im));
reuse_ccf (&function, z1, x1, z2, z3);
break;
case CCU:
for (rnd_im = first_rnd_mode (); is_valid_rnd_mode (rnd_im); rnd_im = next_rnd_mode (rnd_im))
tgeneric_ccu (&function, z1, ul1, z2, zzzz, z3,
- RNDC (rnd_re, rnd_im));
+ MPC_RND (rnd_re, rnd_im));
reuse_ccu (&function, z1, ul1, z2, z3);
break;
case CUC:
for (rnd_im = first_rnd_mode (); is_valid_rnd_mode (rnd_im); rnd_im = next_rnd_mode (rnd_im))
tgeneric_cuc (&function, ul1, z1, z2, zzzz, z3,
- RNDC (rnd_re, rnd_im));
+ MPC_RND (rnd_re, rnd_im));
reuse_cuc (&function, ul1, z1, z2, z3);
break;
case CCS:
for (rnd_im = first_rnd_mode (); is_valid_rnd_mode (rnd_im); rnd_im = next_rnd_mode (rnd_im))
tgeneric_ccs (&function, z1, lo, z2, zzzz, z3,
- RNDC (rnd_re, rnd_im));
+ MPC_RND (rnd_re, rnd_im));
reuse_ccs (&function, z1, lo, z2, z3);
break;
case CCI:
for (rnd_im = first_rnd_mode (); is_valid_rnd_mode (rnd_im); rnd_im = next_rnd_mode (rnd_im))
tgeneric_cci (&function, z1, i, z2, zzzz, z3,
- RNDC (rnd_re, rnd_im));
+ MPC_RND (rnd_re, rnd_im));
reuse_cci (&function, z1, i, z2, z3);
break;
case CUUC:
for (rnd_im = first_rnd_mode (); is_valid_rnd_mode (rnd_im); rnd_im = next_rnd_mode (rnd_im))
tgeneric_cuuc (&function, ul1, ul2, z1, z2, zzzz, z3,
- RNDC (rnd_re, rnd_im));
+ MPC_RND (rnd_re, rnd_im));
reuse_cuuc (&function, ul1, ul2, z1, z2, z3);
break;
default:
diff --git a/tests/tmul.c b/tests/tmul.c
index d83fca0..225cf0e 100644
--- a/tests/tmul.c
+++ b/tests/tmul.c
@@ -1,6 +1,6 @@
/* tmul -- test file for mpc_mul.
-Copyright (C) 2002, 2005, 2008, 2009, 2010, 2011 INRIA
+Copyright (C) 2002, 2005, 2008, 2009, 2010, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -84,7 +84,7 @@ static void
check_regular (void)
{
mpc_t x, y;
- mpc_rnd_t rnd_re, rnd_im;
+ int rnd_re, rnd_im;
mpfr_prec_t prec;
testmul (247, -65, -223, 416, 8, 24);
@@ -102,15 +102,15 @@ check_regular (void)
imaginary part */
mpc_set_prec (x, 7);
mpc_set_prec (y, 7);
- mpfr_set_str (mpc_realref (x), "0xB4p+733", 16, GMP_RNDN);
- mpfr_set_str (mpc_imagref (x), "0x90p+244", 16, GMP_RNDN);
- mpfr_set_str (mpc_realref (y), "0xECp-146", 16, GMP_RNDN);
- mpfr_set_str (mpc_imagref (y), "0xACp-471", 16, GMP_RNDN);
+ mpfr_set_str (mpc_realref (x), "0xB4p+733", 16, MPFR_RNDN);
+ mpfr_set_str (mpc_imagref (x), "0x90p+244", 16, MPFR_RNDN);
+ mpfr_set_str (mpc_realref (y), "0xECp-146", 16, MPFR_RNDN);
+ mpfr_set_str (mpc_imagref (y), "0xACp-471", 16, MPFR_RNDN);
cmpmul (x, y, MPC_RNDNN);
- mpfr_set_str (mpc_realref (x), "0xB4p+733", 16, GMP_RNDN);
- mpfr_set_str (mpc_imagref (x), "0x90p+244", 16, GMP_RNDN);
- mpfr_set_str (mpc_realref (y), "0xACp-471", 16, GMP_RNDN);
- mpfr_set_str (mpc_imagref (y), "-0xECp-146", 16, GMP_RNDN);
+ mpfr_set_str (mpc_realref (x), "0xB4p+733", 16, MPFR_RNDN);
+ mpfr_set_str (mpc_imagref (x), "0x90p+244", 16, MPFR_RNDN);
+ mpfr_set_str (mpc_realref (y), "0xACp-471", 16, MPFR_RNDN);
+ mpfr_set_str (mpc_imagref (y), "-0xECp-146", 16, MPFR_RNDN);
cmpmul (x, y, MPC_RNDNN);
for (prec = 2; prec < 1000; prec = (mpfr_prec_t) (prec * 1.1 + 1))
@@ -123,7 +123,7 @@ check_regular (void)
for (rnd_re = 0; rnd_re < 4; rnd_re ++)
for (rnd_im = 0; rnd_im < 4; rnd_im ++)
- cmpmul (x, y, RNDC(rnd_re, rnd_im));
+ cmpmul (x, y, MPC_RND (rnd_re, rnd_im));
}
mpc_clear (x);
diff --git a/tests/tmul_2exp.c b/tests/tmul_2si.c
index 0653899..bf86f18 100644
--- a/tests/tmul_2exp.c
+++ b/tests/tmul_2si.c
@@ -1,6 +1,6 @@
-/* tmul_2exp -- test file for mpc_mul_2exp.
+/* tmul_2si -- test file for mpc_mul_2si.
-Copyright (C) 2008 INRIA
+Copyright (C) 2012 INRIA
This file is part of GNU MPC.
@@ -23,7 +23,7 @@ along with this program. If not, see http://www.gnu.org/licenses/ .
int
main (void)
{
- DECL_FUNC (CCU, f, mpc_mul_2exp);
+ DECL_FUNC (CCS, f, mpc_mul_2si);
test_start ();
diff --git a/tests/tmul_2ui.c b/tests/tmul_2ui.c
new file mode 100644
index 0000000..97073db
--- /dev/null
+++ b/tests/tmul_2ui.c
@@ -0,0 +1,35 @@
+/* tmul_2ui -- test file for mpc_mul_2ui.
+
+Copyright (C) 2008, 2012 INRIA
+
+This file is part of GNU MPC.
+
+GNU MPC 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 3 of the License, or (at your
+option) any later version.
+
+GNU MPC 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 this program. If not, see http://www.gnu.org/licenses/ .
+*/
+
+#include "mpc-tests.h"
+
+int
+main (void)
+{
+ DECL_FUNC (CCU, f, mpc_mul_2ui);
+
+ test_start ();
+
+ tgeneric (f, 2, 1024, 7, -1);
+
+ test_end ();
+
+ return 0;
+}
diff --git a/tests/tmul_i.c b/tests/tmul_i.c
index 3cde4ac..863ed5f 100644
--- a/tests/tmul_i.c
+++ b/tests/tmul_i.c
@@ -1,6 +1,6 @@
/* tmul_i -- test file for mpc_mul_i.
-Copyright (C) 2008, 2009, 2010, 2011 INRIA
+Copyright (C) 2008, 2009, 2010, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -36,10 +36,10 @@ check_different_precisions(void)
mpfr_set_prec (mpc_imagref (expected), 32);
mpfr_set_prec (mpc_imagref (got), 32);
- mpfr_set_str (mpc_realref (z), "0x100000000fp-32", 16, GMP_RNDN);
- mpfr_set_str (mpc_imagref (z), "-1", 2, GMP_RNDN);
- mpfr_set_str (mpc_realref (expected), "+1", 2, GMP_RNDN);
- mpfr_set_str (mpc_imagref (expected), "0x100000000fp-32", 16, GMP_RNDN);
+ mpfr_set_str (mpc_realref (z), "0x100000000fp-32", 16, MPFR_RNDN);
+ mpfr_set_str (mpc_imagref (z), "-1", 2, MPFR_RNDN);
+ mpfr_set_str (mpc_realref (expected), "+1", 2, MPFR_RNDN);
+ mpfr_set_str (mpc_imagref (expected), "0x100000000fp-32", 16, MPFR_RNDN);
mpc_set (got, z, MPC_RNDNN);
res = mpc_mul_i (got, got, +1, MPC_RNDNN);
diff --git a/tests/tnorm.c b/tests/tnorm.c
index 3f4dccd..1dba939 100644
--- a/tests/tnorm.c
+++ b/tests/tnorm.c
@@ -1,6 +1,6 @@
/* tnorm -- test file for mpc_norm.
-Copyright (C) 2008, 2011 INRIA
+Copyright (C) 2008, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -30,11 +30,11 @@ test_underflow (void)
mpfr_set_emin (-1); /* smallest positive number is 0.5*2^emin = 0.25 */
mpc_init2 (z, 10);
- mpfr_set_ui_2exp (mpc_realref (z), 1023, -11, GMP_RNDN); /* exact */
- mpfr_set_ui_2exp (mpc_imagref (z), 1023, -11, GMP_RNDN); /* exact */
+ mpfr_set_ui_2exp (mpc_realref (z), 1023, -11, MPFR_RNDN); /* exact */
+ mpfr_set_ui_2exp (mpc_imagref (z), 1023, -11, MPFR_RNDN); /* exact */
mpfr_init2 (f, 10);
- inex = mpc_norm (f, z, GMP_RNDZ); /* should give 511/1024 */
+ inex = mpc_norm (f, z, MPFR_RNDZ); /* should give 511/1024 */
if (inex >= 0)
{
printf ("Error in underflow case (1)\n");
@@ -47,12 +47,12 @@ test_underflow (void)
printf ("got ");
mpfr_dump (f);
printf ("expected ");
- mpfr_set_ui_2exp (f, 511, -10, GMP_RNDZ);
+ mpfr_set_ui_2exp (f, 511, -10, MPFR_RNDZ);
mpfr_dump (f);
exit (1);
}
- inex = mpc_norm (f, z, GMP_RNDN); /* should give 511/1024 */
+ inex = mpc_norm (f, z, MPFR_RNDN); /* should give 511/1024 */
if (inex >= 0)
{
printf ("Error in underflow case (2)\n");
@@ -65,12 +65,12 @@ test_underflow (void)
printf ("got ");
mpfr_dump (f);
printf ("expected ");
- mpfr_set_ui_2exp (f, 511, -10, GMP_RNDZ);
+ mpfr_set_ui_2exp (f, 511, -10, MPFR_RNDZ);
mpfr_dump (f);
exit (1);
}
- inex = mpc_norm (f, z, GMP_RNDU); /* should give 1023/2048 */
+ inex = mpc_norm (f, z, MPFR_RNDU); /* should give 1023/2048 */
if (inex <= 0)
{
printf ("Error in underflow case (3)\n");
@@ -83,7 +83,7 @@ test_underflow (void)
printf ("got ");
mpfr_dump (f);
printf ("expected ");
- mpfr_set_ui_2exp (f, 1023, -11, GMP_RNDZ);
+ mpfr_set_ui_2exp (f, 1023, -11, MPFR_RNDZ);
mpfr_dump (f);
exit (1);
}
diff --git a/tests/tpow.c b/tests/tpow.c
index 3592209..31ac1ca 100644
--- a/tests/tpow.c
+++ b/tests/tpow.c
@@ -1,6 +1,6 @@
/* tpow -- test file for mpc_pow.
-Copyright (C) 2009, 2011 INRIA
+Copyright (C) 2009, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -34,8 +34,8 @@ reuse_bug (void)
mpc_init2 (y, prec);
mpc_init2 (z, prec);
- mpfr_set_ui (mpc_realref (x), 0ul, GMP_RNDN);
- mpfr_set_ui_2exp (mpc_imagref (x), 3ul, -2, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (x), 0ul, MPFR_RNDN);
+ mpfr_set_ui_2exp (mpc_imagref (x), 3ul, -2, MPFR_RNDN);
mpc_set_ui (y, 8ul, MPC_RNDNN);
mpc_pow (z, x, y, MPC_RNDNN);
diff --git a/tests/tpow_fr.c b/tests/tpow_fr.c
index 2b0dc29..99274af 100644
--- a/tests/tpow_fr.c
+++ b/tests/tpow_fr.c
@@ -1,6 +1,6 @@
/* tpow_fr -- test file for mpc_pow_fr.
-Copyright (C) 2009, 2011 INRIA
+Copyright (C) 2009, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -30,9 +30,9 @@ test_reuse (void)
mpfr_init2 (y, 2);
mpc_init2 (z, 2);
mpc_set_si_si (z, 0, -1, MPC_RNDNN);
- mpfr_neg (mpc_realref (z), mpc_realref (z), GMP_RNDN);
- mpc_div_2exp (z, z, 4, MPC_RNDNN);
- mpfr_set_ui (y, 512, GMP_RNDN);
+ mpfr_neg (mpc_realref (z), mpc_realref (z), MPFR_RNDN);
+ mpc_div_2ui (z, z, 4, MPC_RNDNN);
+ mpfr_set_ui (y, 512, MPFR_RNDN);
inex = mpc_pow_fr (z, z, y, MPC_RNDNN);
if (MPC_INEX_RE(inex) != 0 || MPC_INEX_IM(inex) != 0 ||
mpfr_cmp_ui_2exp (mpc_realref(z), 1, -2048) != 0 ||
diff --git a/tests/tpow_ui.c b/tests/tpow_ui.c
index 4e8cd31..1c7cc6b 100644
--- a/tests/tpow_ui.c
+++ b/tests/tpow_ui.c
@@ -1,6 +1,6 @@
/* tpow_ui -- test file for mpc_pow_ui.
-Copyright (C) 2009, 2010 INRIA
+Copyright (C) 2009, 2010, 2012 INRIA
This file is part of GNU MPC.
@@ -97,9 +97,9 @@ main (int argc, char *argv[])
MPC_ASSERT (k >= 0);
mpc_init2 (z, p);
mpc_init2 (res, p);
- mpfr_const_pi (mpc_realref (z), GMP_RNDN);
- mpfr_div_2exp (mpc_realref (z), mpc_realref (z), 2, GMP_RNDN);
- mpfr_const_log2 (mpc_imagref (z), GMP_RNDN);
+ mpfr_const_pi (mpc_realref (z), MPFR_RNDN);
+ mpfr_div_2exp (mpc_realref (z), mpc_realref (z), 2, MPFR_RNDN);
+ mpfr_const_log2 (mpc_imagref (z), MPFR_RNDN);
while (k--)
mpc_pow_ui (res, z, (unsigned long int) n, MPC_RNDNN);
mpc_clear (z);
diff --git a/tests/treimref.c b/tests/treimref.c
index 230d34c..9d3c75c 100644
--- a/tests/treimref.c
+++ b/tests/treimref.c
@@ -1,6 +1,6 @@
/* treimref -- test file for mpc_realref and mpc_imagref.
-Copyright (C) 2009 INRIA
+Copyright (C) 2009, 2012 INRIA
This file is part of GNU MPC.
@@ -30,14 +30,14 @@ main (void)
mpc_init2 (z, 6);
mpc_set_ui_ui (z, 17, 42, MPC_RNDNN);
- mpfr_set_ui (mpc_realref (z), 18, GMP_RNDN);
- if (mpfr_get_ui (mpc_realref (z), GMP_RNDN) != 18)
+ mpfr_set_ui (mpc_realref (z), 18, MPFR_RNDN);
+ if (mpfr_get_ui (mpc_realref (z), MPFR_RNDN) != 18)
{
fprintf (stderr, "Error in mpfr_set_ui/mpc_realref\n");
exit (1);
}
- mpfr_set_ui (mpc_imagref (z), 43, GMP_RNDN);
- if (mpfr_get_ui (mpc_imagref (z), GMP_RNDN) != 43)
+ mpfr_set_ui (mpc_imagref (z), 43, MPFR_RNDN);
+ if (mpfr_get_ui (mpc_imagref (z), MPFR_RNDN) != 43)
{
fprintf (stderr, "Error in mpfr_set_ui/mpc_imagref\n");
exit (1);
diff --git a/tests/tset.c b/tests/tset.c
index 0049436..27ea0b3 100644
--- a/tests/tset.c
+++ b/tests/tset.c
@@ -1,6 +1,6 @@
/* tset -- Test file for mpc_set_x and mpc_set_x_x functions.
-Copyright (C) 2009, 2010, 2011 INRIA
+Copyright (C) 2009, 2010, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -92,7 +92,7 @@ check_set (void)
lo = -prec;
- mpfr_set_d (fr, 1.23456789, GMP_RNDN);
+ mpfr_set_d (fr, 1.23456789, MPFR_RNDN);
mpc_set_d (z, 1.23456789, MPC_RNDNN);
if (mpfr_cmp (mpc_realref(z), fr) != 0 || mpfr_cmp_si (mpc_imagref(z), 0) != 0)
@@ -117,7 +117,7 @@ check_set (void)
if (mpfr_cmp_si (mpc_realref(z), lo) != 0 || mpfr_cmp_ui (mpc_imagref(z), 0) != 0)
PRINT_ERROR ("mpc_set_si", prec, z);
- mpfr_set_ld (fr, 1.23456789L, GMP_RNDN);
+ mpfr_set_ld (fr, 1.23456789L, MPFR_RNDN);
mpc_set_ld_ld (z, 1.23456789L, 1.23456789L, MPC_RNDNN);
if (mpfr_cmp (mpc_realref(z), fr) != 0 || mpfr_cmp (mpc_imagref(z), fr) != 0)
@@ -141,10 +141,10 @@ check_set (void)
PRINT_ERROR ("mpc_set_ld", prec, z);
mpc_set_prec (x, prec);
- mpfr_set_ui(fr, 1, GMP_RNDN);
- mpfr_div_ui(fr, fr, 3, GMP_RNDN);
- mpfr_set(mpc_realref(x), fr, GMP_RNDN);
- mpfr_set(mpc_imagref(x), fr, GMP_RNDN);
+ mpfr_set_ui(fr, 1, MPFR_RNDN);
+ mpfr_div_ui(fr, fr, 3, MPFR_RNDN);
+ mpfr_set(mpc_realref(x), fr, MPFR_RNDN);
+ mpfr_set(mpc_imagref(x), fr, MPFR_RNDN);
mpc_set (z, x, MPC_RNDNN);
mpfr_clear_flags (); /* mpc_cmp set erange flag when an operand is a
@@ -170,7 +170,7 @@ check_set (void)
|| mpfr_erangeflag_p())
PRINT_ERROR ("mpc_set_fr", prec, z);
- mpfr_set_z (fr, mpz, GMP_RNDN);
+ mpfr_set_z (fr, mpz, MPFR_RNDN);
mpc_set_z_z (z, mpz, mpz, MPC_RNDNN);
mpfr_clear_flags ();
if (mpfr_cmp (mpc_realref(z), fr) != 0
@@ -192,7 +192,7 @@ check_set (void)
|| mpfr_erangeflag_p())
PRINT_ERROR ("mpc_set_z", prec, z);
- mpfr_set_q (fr, mpq, GMP_RNDN);
+ mpfr_set_q (fr, mpq, MPFR_RNDN);
mpc_set_q_q (z, mpq, mpq, MPC_RNDNN);
mpfr_clear_flags ();
if (mpfr_cmp (mpc_realref(z), fr) != 0
@@ -221,7 +221,7 @@ check_set (void)
|| mpfr_erangeflag_p())
PRINT_ERROR ("mpc_set_q", prec, z);
- mpfr_set_f (fr, mpf, GMP_RNDN);
+ mpfr_set_f (fr, mpf, MPFR_RNDN);
mpc_set_f_f (z, mpf, mpf, MPC_RNDNN);
mpfr_clear_flags ();
if (mpfr_cmp (mpc_realref(z), fr) != 0
@@ -277,13 +277,13 @@ check_set (void)
im = 2 * im * im + 4 * im + 1; /* gives 2^(2n-1)-1 from 2^(n-1)-1 */
mpc_set_sj (z, im, MPC_RNDNN);
- if (mpfr_get_sj (mpc_realref(z), GMP_RNDN) != im ||
+ if (mpfr_get_sj (mpc_realref(z), MPFR_RNDN) != im ||
mpfr_cmp_ui (mpc_imagref(z), 0) != 0)
PRINT_ERROR ("mpc_set_sj (2)", im, z);
mpc_set_sj_sj (z, im, im, MPC_RNDNN);
- if (mpfr_get_sj (mpc_realref(z), GMP_RNDN) != im ||
- mpfr_get_sj (mpc_imagref(z), GMP_RNDN) != im)
+ if (mpfr_get_sj (mpc_realref(z), MPFR_RNDN) != im ||
+ mpfr_get_sj (mpc_imagref(z), MPFR_RNDN) != im)
PRINT_ERROR ("mpc_set_sj_sj (2)", im, z);
}
#endif /* _MPC_H_HAVE_INTMAX_T */
@@ -408,7 +408,7 @@ check_set_str (mpfr_exp_t exp_max)
/* the real part has a zero exponent in base ten (fixed in r439) */
mpc_set_prec (expected, 37);
mpc_set_prec (got, 37);
- mpc_set_str (expected, "921FC04EDp-35 ", 16, GMP_RNDN);
+ mpc_set_str (expected, "921FC04EDp-35 ", 16, MPFR_RNDN);
str = mpc_get_str (10, 0, expected, MPC_RNDNN);
if (mpc_set_str (got, str, 10, MPC_RNDNN) == -1
|| mpc_cmp (got, expected) != 0)
diff --git a/tests/tsqr.c b/tests/tsqr.c
index 02fea7e..2ec2099 100644
--- a/tests/tsqr.c
+++ b/tests/tsqr.c
@@ -1,6 +1,6 @@
/* tsqr -- test file for mpc_sqr.
-Copyright (C) 2002, 2005, 2008, 2010, 2011 INRIA
+Copyright (C) 2002, 2005, 2008, 2010, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -148,9 +148,9 @@ reuse_bug (void)
/* reuse bug found by Paul Zimmermann 20081021 */
mpc_init2 (z1, 2);
/* RE (z1^2) overflows, IM(z^2) = -0 */
- mpfr_set_str (mpc_realref (z1), "0.11", 2, GMP_RNDN);
- mpfr_mul_2si (mpc_realref (z1), mpc_realref (z1), mpfr_get_emax (), GMP_RNDN);
- mpfr_set_ui (mpc_imagref (z1), 0, GMP_RNDN);
+ mpfr_set_str (mpc_realref (z1), "0.11", 2, MPFR_RNDN);
+ mpfr_mul_2si (mpc_realref (z1), mpc_realref (z1), mpfr_get_emax (), MPFR_RNDN);
+ mpfr_set_ui (mpc_imagref (z1), 0, MPFR_RNDN);
mpc_conj (z1, z1, MPC_RNDNN);
mpc_sqr (z1, z1, MPC_RNDNN);
if (!mpfr_inf_p (mpc_realref (z1)) || mpfr_signbit (mpc_realref (z1))
diff --git a/tests/ttan.c b/tests/ttan.c
index f1d826a..c7c672c 100644
--- a/tests/ttan.c
+++ b/tests/ttan.c
@@ -1,6 +1,6 @@
/* ttan -- test file for mpc_tan.
-Copyright (C) 2008, 2011 INRIA
+Copyright (C) 2008, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -38,8 +38,8 @@ pure_real_argument (void)
/* tan(1 +i*0) = tan(1) +i*0 */
mpc_set_ui_ui (z, 1, 0, MPC_RNDNN);
- mpfr_set_ui (x, 1, GMP_RNDN);
- mpfr_tan (tan_x, x, GMP_RNDN);
+ mpfr_set_ui (x, 1, MPFR_RNDN);
+ mpfr_tan (tan_x, x, MPFR_RNDN);
mpc_tan (tan_z, z, MPC_RNDNN);
if (mpfr_cmp (mpc_realref (tan_z), tan_x) != 0
|| !mpfr_zero_p (mpc_imagref (tan_z)) || mpfr_signbit (mpc_imagref (tan_z)))
@@ -59,11 +59,11 @@ pure_real_argument (void)
}
/* tan(Pi/2 +i*0) = +Inf +i*0 */
- mpfr_const_pi (x, GMP_RNDN);
- mpfr_div_2ui (x, x, 1, GMP_RNDN);
- mpfr_set (mpc_realref (z), x, GMP_RNDN);
- mpfr_set_ui (mpc_imagref (z), 0, GMP_RNDN);
- mpfr_tan (tan_x, x, GMP_RNDN);
+ mpfr_const_pi (x, MPFR_RNDN);
+ mpfr_div_2ui (x, x, 1, MPFR_RNDN);
+ mpfr_set (mpc_realref (z), x, MPFR_RNDN);
+ mpfr_set_ui (mpc_imagref (z), 0, MPFR_RNDN);
+ mpfr_tan (tan_x, x, MPFR_RNDN);
mpc_tan (tan_z, z, MPC_RNDNN);
if (mpfr_cmp (mpc_realref (tan_z), tan_x) != 0
|| !mpfr_zero_p (mpc_imagref (tan_z)) || mpfr_signbit (mpc_imagref (tan_z)))
@@ -83,9 +83,9 @@ pure_real_argument (void)
}
/* tan(-Pi/2 +i*0) = -Inf +i*0 */
- mpfr_neg (x, x, GMP_RNDN);
+ mpfr_neg (x, x, MPFR_RNDN);
mpc_neg (z, z, MPC_RNDNN);
- mpfr_tan (tan_x, x, GMP_RNDN);
+ mpfr_tan (tan_x, x, MPFR_RNDN);
mpc_tan (tan_z, z, MPC_RNDNN);
if (mpfr_cmp (mpc_realref (tan_z), tan_x) != 0
|| !mpfr_zero_p (mpc_imagref (tan_z)) || mpfr_signbit (mpc_imagref (tan_z)))
@@ -128,8 +128,8 @@ pure_imaginary_argument (void)
/* tan(0 +i) = +0 +i*tanh(1) */
mpc_set_ui_ui (z, 0, 1, MPC_RNDNN);
- mpfr_set_ui (y, 1, GMP_RNDN);
- mpfr_tanh (tanh_y, y, GMP_RNDN);
+ mpfr_set_ui (y, 1, MPFR_RNDN);
+ mpfr_tanh (tanh_y, y, MPFR_RNDN);
mpc_tan (tan_z, z, MPC_RNDNN);
if (mpfr_cmp (mpc_imagref (tan_z), tanh_y) != 0
|| !mpfr_zero_p (mpc_realref (tan_z)) || mpfr_signbit (mpc_realref (tan_z)))
@@ -137,15 +137,15 @@ pure_imaginary_argument (void)
mpc_t c99;
mpc_init2 (c99, prec);
- mpfr_set_ui (mpc_realref (c99), 0, GMP_RNDN);
- mpfr_set (mpc_imagref (c99), tanh_y, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (c99), 0, MPFR_RNDN);
+ mpfr_set (mpc_imagref (c99), tanh_y, MPFR_RNDN);
TEST_FAILED ("mpc_tan", z, tan_z, c99, MPC_RNDNN);
}
/* tan(0 -i) = +0 +i*tanh(-1) */
mpc_conj (z, z, MPC_RNDNN);
- mpfr_neg (tanh_y, tanh_y, GMP_RNDN);
+ mpfr_neg (tanh_y, tanh_y, MPFR_RNDN);
mpc_tan (tan_z, z, MPC_RNDNN);
if (mpfr_cmp (mpc_imagref (tan_z), tanh_y) != 0
|| !mpfr_zero_p (mpc_realref (tan_z)) || mpfr_signbit (mpc_realref (tan_z)))
@@ -153,15 +153,15 @@ pure_imaginary_argument (void)
mpc_t c99;
mpc_init2 (c99, prec);
- mpfr_set_ui (mpc_realref (c99), 0, GMP_RNDN);
- mpfr_set (mpc_imagref (c99), tanh_y, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (c99), 0, MPFR_RNDN);
+ mpfr_set (mpc_imagref (c99), tanh_y, MPFR_RNDN);
TEST_FAILED ("mpc_tan", z, tan_z, c99, MPC_RNDNN);
}
/* tan(-0 +i) = -0 +i*tanh(1) */
mpc_neg (z, z, MPC_RNDNN);
- mpfr_neg (tanh_y, tanh_y, GMP_RNDN);
+ mpfr_neg (tanh_y, tanh_y, MPFR_RNDN);
mpc_tan (tan_z, z, MPC_RNDNN);
if (mpfr_cmp (mpc_imagref (tan_z), tanh_y) != 0
|| !mpfr_zero_p (mpc_realref (tan_z)) || !mpfr_signbit (mpc_realref (tan_z)))
@@ -169,15 +169,15 @@ pure_imaginary_argument (void)
mpc_t c99;
mpc_init2 (c99, prec);
- mpfr_set_ui (mpc_realref (c99), 0, GMP_RNDN);
- mpfr_set (mpc_imagref (c99), tanh_y, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (c99), 0, MPFR_RNDN);
+ mpfr_set (mpc_imagref (c99), tanh_y, MPFR_RNDN);
TEST_FAILED ("mpc_tan", z, tan_z, c99, MPC_RNDNN);
}
/* tan(-0 -i) = -0 +i*tanh(-1) */
mpc_conj (z, z, MPC_RNDNN);
- mpfr_neg (tanh_y, tanh_y, GMP_RNDN);
+ mpfr_neg (tanh_y, tanh_y, MPFR_RNDN);
mpc_tan (tan_z, z, MPC_RNDNN);
if (mpfr_cmp (mpc_imagref (tan_z), tanh_y) != 0
|| !mpfr_zero_p (mpc_realref (tan_z)) || !mpfr_signbit (mpc_realref (tan_z)))
@@ -185,8 +185,8 @@ pure_imaginary_argument (void)
mpc_t c99;
mpc_init2 (c99, prec);
- mpfr_set_ui (mpc_realref (c99), 0, GMP_RNDN);
- mpfr_set (mpc_imagref (c99), tanh_y, GMP_RNDN);
+ mpfr_set_ui (mpc_realref (c99), 0, MPFR_RNDN);
+ mpfr_set (mpc_imagref (c99), tanh_y, MPFR_RNDN);
TEST_FAILED ("mpc_tan", z, tan_z, c99, MPC_RNDNN);
}
diff --git a/tests/tui_div.c b/tests/tui_div.c
index c109189..40c740a 100644
--- a/tests/tui_div.c
+++ b/tests/tui_div.c
@@ -1,6 +1,6 @@
/* tui_div -- test file for mpc_ui_div.
-Copyright (C) 2008, 2011 INRIA
+Copyright (C) 2008, 2011, 2012 INRIA
This file is part of GNU MPC.
@@ -41,8 +41,8 @@ special (void)
}
/* 0/(-1-0*I) should give (-0, +0) */
- mpfr_set_str (mpc_realref(a), "-1", 10, GMP_RNDN);
- mpfr_set_str (mpc_imagref(a), "-0", 10, GMP_RNDN);
+ mpfr_set_str (mpc_realref(a), "-1", 10, MPFR_RNDN);
+ mpfr_set_str (mpc_imagref(a), "-0", 10, MPFR_RNDN);
mpc_ui_div (b, 0, a, MPC_RNDNN);
if ((mpc_cmp_si_si (b, 0, 0) != 0) || (MPFR_SIGN (mpc_realref(b)) > 0)
|| (MPFR_SIGN (mpc_imagref(b)) < 0))
diff --git a/tools/coverage b/tools/coverage
new file mode 100755
index 0000000..9fd4ca1
--- /dev/null
+++ b/tools/coverage
@@ -0,0 +1,105 @@
+#!/bin/bash
+
+# to compute the coverage of mpc-x.y.z, just copy this script
+# into mpc-x.y.z/tools and run it
+
+# Set up the right directoy
+cd $(dirname $0)/..
+
+# First Build MPC in /tmp/
+echo "Erasing previous /tmp/ompc-gcov"
+rm -rf /tmp/ompc-gcov
+mkdir /tmp/ompc-gcov || exit 1
+
+echo "Copying MPC sources to /tmp/ompc-gcov"
+cp -r . /tmp/ompc-gcov || exit 1
+cd /tmp/ompc-gcov || exit 1
+
+echo "Remove previous coverage information."
+rm -f $(find . -name '*.gc*')
+
+echo "Reconfiguring MPC"
+autoreconf -fi || exit 1
+
+echo "Building MPC"
+./configure --disable-shared --enable-static \
+ CFLAGS="-fprofile-arcs -ftest-coverage -g" || exit 1
+make clean || exit 1
+make all -j4 || exit 1
+
+# Note: we want to compute the coverage even in case of failure of some tests.
+make check
+
+# Check version of gcov:
+# 3.3 outputs like this:
+# 100.00% of 36 lines executed in function mpc_add
+# 100.00% of 36 lines executed in file add.c
+# Creating add.c.gcov.
+# It doesn't support gcov *.c
+#
+# gcov (GCC) 3.4 outputs like this:
+# Function `mpc_add'
+# Lines executed:100.00% of 36
+#
+# File `add.c'
+# Lines executed:100.00% of 36
+# add.c:creating `add.c.gcov'
+# It supports gcov *.c
+
+# Setup the parser depending on gcov
+version=$(gcov --version | head -1 | cut -f2 -d')')
+version=$(( $(echo "$version" | cut -f1 -d'.')*100 + $(echo "$version" | cut -f1 -d'.')*10 ))
+if test "$version" -ge 340 ; then
+ echo "#!/bin/bash
+while true ; do
+ if read x ; then
+ case \$x in
+ Function*)
+ read y
+ case \$y in
+ *100.00*)
+ ;;
+ *)
+ echo \$x \$y
+ ;;
+ esac
+ ;;
+ esac
+ else
+ exit 0
+ fi
+done
+" > coverage.subscript
+else
+ echo "#!/bin/bash
+while true ; do
+ if read x ; then
+ case \$x in
+ 100.00*)
+ ;;
+ *function*)
+ echo \$x
+ ;;
+ esac
+ else
+ exit 0
+ fi
+done
+" > coverage.subscript
+fi
+
+# Do "gcov" for all files and parse the output
+cd src
+for i in $(find . -name '*.c')
+do
+ gcov -f $i -o $(dirname $i) 2> /dev/null || exit 1
+done | bash ../coverage.subscript | grep -v '__gmp' > ../coverage.mpc
+
+rm -f coverage.subscript coverage-tmp || exit 1
+
+cd -
+lcov --capture --directory . --output-file all.info || exit 1
+genhtml -o coverage all.info || exit 1
+
+echo "Coverage summary saved in file /tmp/ompc-gcov/coverage.mpc"
+echo "Detailed coverage is available at /tmp/ompc-gcov/coverage/index.html"