diff options
author | hanrot <hanrot@280ebfd0-de03-0410-8827-d642c229c3f4> | 2000-11-21 15:21:33 +0000 |
---|---|---|
committer | hanrot <hanrot@280ebfd0-de03-0410-8827-d642c229c3f4> | 2000-11-21 15:21:33 +0000 |
commit | ebb0a24940eb551ce03eb361910c423fee7d6499 (patch) | |
tree | 46fccc5920d05d93d00ecd30aff4a012adba3d13 | |
parent | 1cc85c4f5a5658c530891f7348c153155b6dddbb (diff) | |
download | mpfr-ebb0a24940eb551ce03eb361910c423fee7d6499.tar.gz |
Infinis, premiere tentative.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@793 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | add.c | 25 | ||||
-rw-r--r-- | add_ulp.c | 2 | ||||
-rw-r--r-- | agm.c | 3 | ||||
-rw-r--r-- | cmp.c | 5 | ||||
-rw-r--r-- | cmp_ui.c | 4 | ||||
-rwxr-xr-x | configure | 107 | ||||
-rw-r--r-- | div.c | 44 | ||||
-rw-r--r-- | div_ui.c | 20 | ||||
-rw-r--r-- | dump.c | 11 | ||||
-rw-r--r-- | eq.c | 13 | ||||
-rw-r--r-- | exp.c | 9 | ||||
-rw-r--r-- | exp2.c | 8 | ||||
-rw-r--r-- | exp3.c | 8 | ||||
-rw-r--r-- | extract.c | 2 | ||||
-rw-r--r-- | generic.c | 2 | ||||
-rw-r--r-- | get_str.c | 10 | ||||
-rw-r--r-- | log.c | 14 | ||||
-rw-r--r-- | mpfr.h | 10 | ||||
-rw-r--r-- | mpz_set_fr.c | 2 | ||||
-rw-r--r-- | mul.c | 16 | ||||
-rw-r--r-- | mul_ui.c | 11 | ||||
-rw-r--r-- | out_str.c | 6 | ||||
-rw-r--r-- | pow.c | 15 | ||||
-rw-r--r-- | print_raw.c | 5 | ||||
-rw-r--r-- | reldiff.c | 14 | ||||
-rw-r--r-- | round.c | 1 | ||||
-rw-r--r-- | set.c | 6 | ||||
-rw-r--r-- | set_d.c | 14 | ||||
-rw-r--r-- | set_str_raw.c | 13 | ||||
-rw-r--r-- | sin_cos.c | 2 | ||||
-rw-r--r-- | sqrt.c | 7 | ||||
-rw-r--r-- | sub.c | 25 | ||||
-rw-r--r-- | zeta.c | 138 |
33 files changed, 416 insertions, 156 deletions
@@ -396,6 +396,31 @@ mpfr_add(a, b, c, rnd_mode) MPFR_SET_NAN(a); return; } + if (MPFR_IS_INF(b)) + { + if (MPFR_IS_INF(c)) + { + if (MPFR_SIGN(b) == MPFR_SIGN(c)) + { + MPFR_SET_INF(a); + if (MPFR_SIGN(a) != MPFR_SIGN(b)) { MPFR_CHANGE_SIGN(a); } + } + else + MPFR_SET_NAN(a); + } + else + { + MPFR_SET_INF(a); + if (MPFR_SIGN(b) != MPFR_SIGN(a)) { MPFR_CHANGE_SIGN(a); } + } + } + else + if (MPFR_IS_INF(c)) + { + MPFR_SET_INF(a); + if (MPFR_SIGN(c) != MPFR_SIGN(a)) { MPFR_CHANGE_SIGN(a); } + } + if (!MPFR_NOTZERO(b)) { mpfr_set(a, c, rnd_mode); return; } if (!MPFR_NOTZERO(c)) { mpfr_set(a, b, rnd_mode); return; } @@ -34,6 +34,7 @@ mpfr_add_one_ulp(x) { int xn, sh; mp_limb_t *xp; + if (MPFR_IS_INF(x)) { return; } xn = 1 + (MPFR_PREC(x)-1)/BITS_PER_MP_LIMB; sh = xn*BITS_PER_MP_LIMB - MPFR_PREC(x); xp = MPFR_MANT(x); @@ -50,6 +51,7 @@ int mpfr_sub_one_ulp(mpfr_ptr x) { int xn, sh; mp_limb_t *xp; + if (MPFR_IS_INF(x)) { return; } xn = 1 + (MPFR_PREC(x)-1)/BITS_PER_MP_LIMB; sh = xn*BITS_PER_MP_LIMB-MPFR_PREC(x); xp = MPFR_MANT(x); @@ -51,6 +51,7 @@ mpfr_agm(r, a, b, rnd_mode) TMP_DECL(marker1); TMP_DECL(marker2); + /* TODO : CHECK FOR INFINITY. */ /* If a or b is NaN, the result is NaN */ if (MPFR_IS_NAN(op1) || MPFR_IS_NAN(op2)) @@ -60,8 +61,6 @@ mpfr_agm(r, a, b, rnd_mode) /* If a or b is negative, the result is NaN */ if ((MPFR_SIGN(op1) < 0) || (MPFR_SIGN(op2) < 0)) { MPFR_SET_NAN(r); return; } - - /* If a or b is 0, the result is 0 */ if ((MPFR_NOTZERO(op1) && MPFR_NOTZERO(op2)) == 0) @@ -55,6 +55,7 @@ mpfr_cmp3(b, c, s) if (!MPFR_NOTZERO(b)) { if (!MPFR_NOTZERO(c)) return 0; else return -(MPFR_SIGN(c)); + /*TODO: bug ou feature ? s pas pris en compte... */ } else if (!MPFR_NOTZERO(c)) return MPFR_SIGN(b); @@ -62,6 +63,8 @@ mpfr_cmp3(b, c, s) if (s<0) return(MPFR_SIGN(b)); /* now signs are equal */ + if (MPFR_IS_INF(b)) + return MPFR_SIGN(b) * !MPFR_IS_INF(c); diff_exp = MPFR_EXP(b)-MPFR_EXP(c); s = (MPFR_SIGN(b) > 0) ? 1 : -1; @@ -89,6 +92,8 @@ mpfr_cmp3(b, c, s) Assumes b>=c, which implies MPFR_EXP(b)>=MPFR_EXP(c). if b=c, returns prec(b). */ +/* TODO: semantique ? */ + int #if __STDC__ mpfr_cmp2 ( mpfr_srcptr b, mpfr_srcptr c ) @@ -44,6 +44,7 @@ mpfr_cmp_ui_2exp (b, i, f) if (MPFR_SIGN(b) < 0) return -1; /* now b>=0 */ + else if (MPFR_IS_INF(b)) return 1; else if (!MPFR_NOTZERO(b)) return((i) ? -1 : 0); /* now b>0 */ else if (i==0) return 1; @@ -88,7 +89,8 @@ mpfr_cmp_si_2exp(b, i, f) int e, k, bn, si; mp_limb_t c, *bp; si = (i<0) ? -1 : 1; /* sign of i */ - if (MPFR_SIGN(b) * i < 0) return MPFR_SIGN(b); /* both signs differ */ + if (MPFR_SIGN(b) * i < 0 || MPFR_IS_INF(b)) return MPFR_SIGN(b); + /* both signs differ */ else if (!MPFR_NOTZERO(b) || (i==0)) { /* one is zero */ if (i==0) return ((MPFR_NOTZERO(b)) ? MPFR_SIGN(b) : 0); else return si; /* b is zero */ @@ -697,7 +697,6 @@ else fi - PACKAGE=mpfr VERSION=1.0 @@ -710,7 +709,7 @@ fi missing_dir=`cd $ac_aux_dir && pwd` echo $ac_n "checking for working aclocal""... $ac_c" 1>&6 -echo "configure:714: checking for working aclocal" >&5 +echo "configure:713: checking for working aclocal" >&5 # Run test in a subshell; some versions of sh will print an error if # an executable is not found, even if stderr is redirected. # Redirect stdin to placate older versions of autoconf. Sigh. @@ -723,7 +722,7 @@ else fi echo $ac_n "checking for working autoconf""... $ac_c" 1>&6 -echo "configure:727: checking for working autoconf" >&5 +echo "configure:726: checking for working autoconf" >&5 # Run test in a subshell; some versions of sh will print an error if # an executable is not found, even if stderr is redirected. # Redirect stdin to placate older versions of autoconf. Sigh. @@ -736,7 +735,7 @@ else fi echo $ac_n "checking for working automake""... $ac_c" 1>&6 -echo "configure:740: checking for working automake" >&5 +echo "configure:739: checking for working automake" >&5 # Run test in a subshell; some versions of sh will print an error if # an executable is not found, even if stderr is redirected. # Redirect stdin to placate older versions of autoconf. Sigh. @@ -749,7 +748,7 @@ else fi echo $ac_n "checking for working autoheader""... $ac_c" 1>&6 -echo "configure:753: checking for working autoheader" >&5 +echo "configure:752: checking for working autoheader" >&5 # Run test in a subshell; some versions of sh will print an error if # an executable is not found, even if stderr is redirected. # Redirect stdin to placate older versions of autoconf. Sigh. @@ -762,7 +761,7 @@ else fi echo $ac_n "checking for working makeinfo""... $ac_c" 1>&6 -echo "configure:766: checking for working makeinfo" >&5 +echo "configure:765: checking for working makeinfo" >&5 # Run test in a subshell; some versions of sh will print an error if # an executable is not found, even if stderr is redirected. # Redirect stdin to placate older versions of autoconf. Sigh. @@ -807,7 +806,7 @@ fi # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:811: checking for $ac_word" >&5 +echo "configure:810: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -837,7 +836,7 @@ if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:841: checking for $ac_word" >&5 +echo "configure:840: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -888,7 +887,7 @@ fi # Extract the first word of "cl", so it can be a program name with args. set dummy cl; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:892: checking for $ac_word" >&5 +echo "configure:891: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -920,7 +919,7 @@ fi fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6 -echo "configure:924: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 +echo "configure:923: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 ac_ext=c # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. @@ -931,12 +930,12 @@ cross_compiling=$ac_cv_prog_cc_cross cat > conftest.$ac_ext << EOF -#line 935 "configure" +#line 934 "configure" #include "confdefs.h" main(){return(0);} EOF -if { (eval echo configure:940: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:939: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then ac_cv_prog_cc_works=yes # If we can't run a trivial program, we are probably using a cross compiler. if (./conftest; exit) 2>/dev/null; then @@ -962,12 +961,12 @@ if test $ac_cv_prog_cc_works = no; then { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; } fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6 -echo "configure:966: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 +echo "configure:965: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6 cross_compiling=$ac_cv_prog_cc_cross echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6 -echo "configure:971: checking whether we are using GNU C" >&5 +echo "configure:970: checking whether we are using GNU C" >&5 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -976,7 +975,7 @@ else yes; #endif EOF -if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:980: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then +if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:979: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then ac_cv_prog_gcc=yes else ac_cv_prog_gcc=no @@ -995,7 +994,7 @@ ac_test_CFLAGS="${CFLAGS+set}" ac_save_CFLAGS="$CFLAGS" CFLAGS= echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6 -echo "configure:999: checking whether ${CC-cc} accepts -g" >&5 +echo "configure:998: checking whether ${CC-cc} accepts -g" >&5 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1029,7 +1028,7 @@ fi # Extract the first word of "ranlib", so it can be a program name with args. set dummy ranlib; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:1033: checking for $ac_word" >&5 +echo "configure:1032: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1058,13 +1057,13 @@ fi echo $ac_n "checking OS type""... $ac_c" 1>&6 -echo "configure:1062: checking OS type" >&5 +echo "configure:1061: checking OS type" >&5 OS_TYPE=`uname -a | awk '{print $ 1}' ` echo "$ac_t""$OS_TYPE" 1>&6 echo $ac_n "checking Mach type""... $ac_c" 1>&6 -echo "configure:1068: checking Mach type" >&5 +echo "configure:1067: checking Mach type" >&5 MACHTYPE=`uname -m` echo "$ac_t""$MACHTYPE" 1>&6 @@ -1073,7 +1072,7 @@ MISCFLAGS='$<' case $OS_TYPE in HP-UX*) echo $ac_n "checking for main in -lM""... $ac_c" 1>&6 -echo "configure:1077: checking for main in -lM" >&5 +echo "configure:1076: checking for main in -lM" >&5 ac_lib_var=`echo M'_'main | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1081,14 +1080,14 @@ else ac_save_LIBS="$LIBS" LIBS="-lM $LIBS" cat > conftest.$ac_ext <<EOF -#line 1085 "configure" +#line 1084 "configure" #include "confdefs.h" int main() { main() ; return 0; } EOF -if { (eval echo configure:1092: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1091: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -1118,7 +1117,7 @@ fi SunOS*) MISCFLAGS="trunc.c" echo $ac_n "checking for main in -lm""... $ac_c" 1>&6 -echo "configure:1122: checking for main in -lm" >&5 +echo "configure:1121: checking for main in -lm" >&5 ac_lib_var=`echo m'_'main | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1126,14 +1125,14 @@ else ac_save_LIBS="$LIBS" LIBS="-lm $LIBS" cat > conftest.$ac_ext <<EOF -#line 1130 "configure" +#line 1129 "configure" #include "confdefs.h" int main() { main() ; return 0; } EOF -if { (eval echo configure:1137: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1136: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -1163,7 +1162,7 @@ fi ;; Linux*) echo $ac_n "checking for main in -lm""... $ac_c" 1>&6 -echo "configure:1167: checking for main in -lm" >&5 +echo "configure:1166: checking for main in -lm" >&5 ac_lib_var=`echo m'_'main | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1171,14 +1170,14 @@ else ac_save_LIBS="$LIBS" LIBS="-lm $LIBS" cat > conftest.$ac_ext <<EOF -#line 1175 "configure" +#line 1174 "configure" #include "confdefs.h" int main() { main() ; return 0; } EOF -if { (eval echo configure:1182: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1181: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -1217,7 +1216,7 @@ EOF fi;; IRIX64) echo $ac_n "checking for main in -lm""... $ac_c" 1>&6 -echo "configure:1221: checking for main in -lm" >&5 +echo "configure:1220: checking for main in -lm" >&5 ac_lib_var=`echo m'_'main | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1225,14 +1224,14 @@ else ac_save_LIBS="$LIBS" LIBS="-lm $LIBS" cat > conftest.$ac_ext <<EOF -#line 1229 "configure" +#line 1228 "configure" #include "confdefs.h" int main() { main() ; return 0; } EOF -if { (eval echo configure:1236: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1235: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -1267,7 +1266,7 @@ fi fi;; OSF*) echo $ac_n "checking for main in -lm""... $ac_c" 1>&6 -echo "configure:1271: checking for main in -lm" >&5 +echo "configure:1270: checking for main in -lm" >&5 ac_lib_var=`echo m'_'main | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1275,14 +1274,14 @@ else ac_save_LIBS="$LIBS" LIBS="-lm $LIBS" cat > conftest.$ac_ext <<EOF -#line 1279 "configure" +#line 1278 "configure" #include "confdefs.h" int main() { main() ; return 0; } EOF -if { (eval echo configure:1286: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1285: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -1324,7 +1323,7 @@ EOF ;; *) echo $ac_n "checking for main in -lm""... $ac_c" 1>&6 -echo "configure:1328: checking for main in -lm" >&5 +echo "configure:1327: checking for main in -lm" >&5 ac_lib_var=`echo m'_'main | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1332,14 +1331,14 @@ else ac_save_LIBS="$LIBS" LIBS="-lm $LIBS" cat > conftest.$ac_ext <<EOF -#line 1336 "configure" +#line 1335 "configure" #include "confdefs.h" int main() { main() ; return 0; } EOF -if { (eval echo configure:1343: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1342: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -1371,7 +1370,7 @@ esac echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6 -echo "configure:1375: checking how to run the C preprocessor" >&5 +echo "configure:1374: checking how to run the C preprocessor" >&5 # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= @@ -1386,13 +1385,13 @@ else # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. cat > conftest.$ac_ext <<EOF -#line 1390 "configure" +#line 1389 "configure" #include "confdefs.h" #include <assert.h> Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1396: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1395: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -1403,13 +1402,13 @@ else rm -rf conftest* CPP="${CC-cc} -E -traditional-cpp" cat > conftest.$ac_ext <<EOF -#line 1407 "configure" +#line 1406 "configure" #include "confdefs.h" #include <assert.h> Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1413: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1412: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -1420,13 +1419,13 @@ else rm -rf conftest* CPP="${CC-cc} -nologo -E" cat > conftest.$ac_ext <<EOF -#line 1424 "configure" +#line 1423 "configure" #include "confdefs.h" #include <assert.h> Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1430: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1429: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -1455,17 +1454,17 @@ if test "$with_gmp_include" then ac_safe=`echo "$with_gmp_include/gmp-impl.h" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $with_gmp_include/gmp-impl.h""... $ac_c" 1>&6 -echo "configure:1459: checking for $with_gmp_include/gmp-impl.h" >&5 +echo "configure:1458: checking for $with_gmp_include/gmp-impl.h" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1464 "configure" +#line 1463 "configure" #include "confdefs.h" #include <$with_gmp_include/gmp-impl.h> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1469: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1468: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -1490,17 +1489,17 @@ fi else ac_safe=`echo "gmp-impl.h" | sed 'y%./+-%__p_%'` echo $ac_n "checking for gmp-impl.h""... $ac_c" 1>&6 -echo "configure:1494: checking for gmp-impl.h" >&5 +echo "configure:1493: checking for gmp-impl.h" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1499 "configure" +#line 1498 "configure" #include "confdefs.h" #include <gmp-impl.h> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1504: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1503: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -1531,7 +1530,7 @@ fi if ` test "$with_gmp_lib" ` then echo $ac_n "checking gmp library""... $ac_c" 1>&6 -echo "configure:1535: checking gmp library" >&5 +echo "configure:1534: checking gmp library" >&5 if test -r "$with_gmp_lib/libgmp.a" then LDADD="$LDADD $with_gmp_lib/libgmp.a" @@ -1541,7 +1540,7 @@ echo "configure:1535: checking gmp library" >&5 echo "$ac_t""yes" 1>&6 else echo $ac_n "checking for main in -lgmp""... $ac_c" 1>&6 -echo "configure:1545: checking for main in -lgmp" >&5 +echo "configure:1544: checking for main in -lgmp" >&5 ac_lib_var=`echo gmp'_'main | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1549,14 +1548,14 @@ else ac_save_LIBS="$LIBS" LIBS="-lgmp $LIBS" cat > conftest.$ac_ext <<EOF -#line 1553 "configure" +#line 1552 "configure" #include "confdefs.h" int main() { main() ; return 0; } EOF -if { (eval echo configure:1560: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1559: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -54,23 +54,51 @@ mpfr_div (r, u, v, rnd_mode) TMP_DECL (marker); if (MPFR_IS_NAN(u) || MPFR_IS_NAN(v)) { MPFR_SET_NAN(r); return; } - + if (MPFR_IS_INF(u)) + { + if (MPFR_IS_INF(v)) + { + MPFR_SET_NAN(r); return; + } + else + { + MPFR_SET_INF(r); + if (MPFR_SIGN(r) != MPFR_SIGN(u) * MPFR_SIGN(v)) + { MPFR_CHANGE_SIGN(r); } + return; + } + } + else + { + if (MPFR_IS_INF(v)) + { + MPFR_SET_ZERO(r); + if (MPFR_SIGN(r) != MPFR_SIGN(u) * MPFR_SIGN(v)) + { MPFR_CHANGE_SIGN(r); } + return; + } + } + usize = (MPFR_PREC(u) - 1)/BITS_PER_MP_LIMB + 1; vsize = (MPFR_PREC(v) - 1)/BITS_PER_MP_LIMB + 1; sign_quotient = ((MPFR_SIGN(u) * MPFR_SIGN(v) > 0) ? 1 : -1); prec = MPFR_PREC(r); - if (!MPFR_NOTZERO(u)) { MPFR_SET_ZERO(r); return; } if (!MPFR_NOTZERO(v)) - vsize = 1 / v->_mp_d[vsize - 1]; /* Gestion des infinis ? */ - - if (!MPFR_NOTZERO(v)) { - r->_mp_exp = 0; - MPN_ZERO(r->_mp_d, r->_mp_size); - return; + if (!MPFR_NOTZERO(u)) + { MPFR_SET_NAN(r); return; } + else + { + MPFR_SET_INF(r); + if (MPFR_SIGN(r) != MPFR_SIGN(v) * MPFR_SIGN(u)) + MPFR_CHANGE_SIGN(r); + return; + } } + + if (!MPFR_NOTZERO(u)) { MPFR_SET_ZERO(r); return; } up = u->_mp_d; vp = v->_mp_d; @@ -50,7 +50,25 @@ mpfr_div_ui(y, x, u, rnd_mode) TMP_DECL(marker); if (MPFR_IS_NAN(x)) { MPFR_SET_NAN(y); return 1; } - if (u==0) { fprintf(stderr, "division by zero\n"); exit(1); } + + if (MPFR_IS_INF(x)) + { + MPFR_SET_INF(y); + if (MPFR_SIGN(y) * MPFR_SIGN(x) * u < 0) + MPFR_CHANGE_SIGN(y); + return 0; + /* TODO: semantique de la division par un zero entier ? signe ? */ + } + + if (u==0) + { + if (MPFR_IS_ZERO(x)) { MPFR_SET_NAN(y) ; return 1; } + else + { + MPFR_SET_INF(y); MPFR_SET_SAME_SIGN(y, x); return 0; + /* TODO: semantique de la division dans ce cas-la aussi ? */ + } + } TMP_MARK(marker); xn = (MPFR_PREC(x)-1)/BITS_PER_MP_LIMB + 1; @@ -42,6 +42,17 @@ mpfr_dump (u, rnd_mode) mp_exp_t exp; char *str; + if (MPFR_IS_INF(u)) + { + if (MPFR_SIGN(u) == 1) printf("Inf\n"); else printf("-Inf\n"); + return; + } + if (MPFR_IS_NAN(u)) + { + printf("NaN\n"); + return; + } + str = mpfr_get_str (NULL, &exp, 10, 0, u, rnd_mode); if (str[0] == '-') printf ("-0.%se%ld\n", str + 1, exp); @@ -47,8 +47,10 @@ mpfr_eq (u, v, n_bits) usize = (MPFR_PREC(u)-1)/BITS_PER_MP_LIMB + 1; vsize = (MPFR_PREC(v)-1)/BITS_PER_MP_LIMB + 1; + usign = MPFR_SIGN(u); + /* 1. Are the signs different? */ - if (MPFR_SIGN(u) == MPFR_SIGN(v)) + if (usign == MPFR_SIGN(v)) { /* U and V are both non-negative or both negative. */ if (!MPFR_NOTZERO(u)) @@ -61,12 +63,15 @@ mpfr_eq (u, v, n_bits) else { /* Either U or V is negative, but not both. */ - return 0; + if (MPFR_NOTZERO(u) || MPFR_NOTZERO(v)) + return 0; + else return 1; /* particular case -0 = +0 */ } /* U and V have the same sign and are both non-zero. */ - - usign = MPFR_SIGN(u); + if (MPFR_IS_INF(u)) + return (MPFR_IS_INF(v) && (usign == MPFR_SIGN(v))); + else if (MPFR_IS_INF(v)) return 0; /* 2. Are the exponents different? */ if (uexp > vexp) @@ -47,6 +47,15 @@ mpfr_exp(y, x, rnd_mode) mpfr_t r, s, t; if (MPFR_IS_NAN(x)) { MPFR_SET_NAN(y); return 1; } + if (MPFR_IS_INF(x)) + { + if (MPFR_SIGN(x) > 0) + { MPFR_SET_INF(y); if (MPFR_SIGN(y) == -1) { MPFR_CHANGE_SIGN(y); } } + else + { MPFR_SET_ZERO(y); if (MPFR_SIGN(y) == -1) { MPFR_CHANGE_SIGN(y); } } + /* TODO: conflits entre infinis et zeros ? */ + } + if (!MPFR_NOTZERO(x)) { mpfr_set_ui(y, 1, GMP_RNDN); return 0; } expx = MPFR_EXP(x); @@ -106,6 +106,14 @@ mpfr_exp2(y, x, rnd_mode) TMP_DECL(marker); if (MPFR_IS_NAN(x)) { MPFR_SET_NAN(y); return 1; } + if (MPFR_IS_INF(x)) + { + if (MPFR_SIGN(x) > 0) + { MPFR_SET_INF(y); if (MPFR_SIGN(y) == -1) { MPFR_CHANGE_SIGN(y); } } + else + { MPFR_SET_ZERO(y); if (MPFR_SIGN(y) == -1) { MPFR_CHANGE_SIGN(y); } } + /* TODO: conflits entre infinis et zeros ? */ + } if (!MPFR_NOTZERO(x)) { mpfr_set_ui(y, 1, GMP_RNDN); return 0; } expx = MPFR_EXP(x); @@ -174,6 +174,14 @@ mp_rnd_t rnd_mode; int logn; /* commencons par 0 */ if (MPFR_IS_NAN(x)) { MPFR_SET_NAN(y); return 1; } + if (MPFR_IS_INF(x)) + { + if (MPFR_SIGN(x) > 0) + { MPFR_SET_INF(y); if (MPFR_SIGN(y) == -1) { MPFR_CHANGE_SIGN(y); } } + else + { MPFR_SET_ZERO(y); if (MPFR_SIGN(y) == -1) { MPFR_CHANGE_SIGN(y); } } + /* TODO: conflits entre infinis et zeros ? */ + } if (!MPFR_NOTZERO(x)) { mpfr_set_ui(y, 1, GMP_RNDN); return 0; @@ -23,6 +23,8 @@ int i; int size; int j; + /* TODO: gestion de l'infini. */ + if (MPFR_ABSSIZE(p) < two_i){ int j; y->_mp_alloc=two_i_2 ; @@ -23,6 +23,8 @@ MA 02111-1307, USA. */ # error You should specify a name #endif +/* TODO: Reflechir a un traitement generique des infinis ? */ + #ifdef B # ifndef A # error B cannot be used without A @@ -58,9 +58,17 @@ char *mpfr_get_str(str, expptr, base, n, op, rnd_mode) base); exit(1); } - + neg = (MPFR_SIGN(op)<0) ? 1 : 0; + if (MPFR_IS_INF(op)) { + if (str==NULL) str = (*_mp_allocate_func)(neg + 4); + str0 = str; + if (neg) { *str++ = '-'; } + *str++ = 'I'; *str++ = 'n'; *str++ = 'f'; *str='\0'; + return str0; + } + if (!MPFR_NOTZERO(op)) { if (str==NULL) str = (*_mp_allocate_func)(neg + n + 1); str0 = str; @@ -62,9 +62,19 @@ mpfr_log(r, a, rnd_mode) double ref; TMP_DECL(marker); - /* If a is NaN or a is negative or null, the result is NaN */ - if (MPFR_IS_NAN(a) || (MPFR_NOTZERO(a)==0) || (MPFR_SIGN(a)<0)) + /* If a is NaN, the result is NaN */ + if (MPFR_IS_NAN(a)) { MPFR_SET_NAN(r); return 1; } + + if (MPFR_IS_ZERO(a)) + { + MPFR_SET_INF(r); if (MPFR_SIGN(r) != -1) { MPFR_CHANGE_SIGN(r); } + } + + if (MPFR_IS_INF(a)) + { + MPFR_SET_INF(r); if (MPFR_SIGN(r) != 1) { MPFR_CHANGE_SIGN(r); } + } /* If a is 1, the result is 0 */ if (mpfr_cmp_ui_2exp(a,1,0)==0){ @@ -88,17 +88,23 @@ typedef __gmp_const __mpfr_struct *mpfr_srcptr; /* bit 31 of _mp_size is used for sign, bit 30 of _mp_size is used for Nan flag, + bit 29 of _mp_size is used for Inf flag, remaining bits are used to store the number of allocated limbs */ #define MPFR_IS_NAN(x) (((x)->_mp_size >> 30)&1) #define MPFR_SET_NAN(x) ((x)->_mp_size |= (1<<30)) +#define MPFR_IS_INF(x) (((x)->_mp_size >> 29)&1) +#define MPFR_SET_INF(x) ((x)->_mp_size |= (1<<29)) +#define MPFR_IS_FP(x) ((((x) -> _mp_size >> 29) & 3) == 0) +#define MPFR_SET_IS_FP(x) ((x) -> _mp_size &= 2684354559UL); /* 1001111...1 */ #define MPFR_ABSSIZE(x) ((x)->_mp_size & ((1<<30)-1)) #define MPFR_SIZE(x) ((x)->_mp_size) #define MPFR_EXP(x) ((x)->_mp_exp) #define MPFR_MANT(x) ((x)->_mp_d) #define MPFR_SIGN(x) (((x)->_mp_size >> 31) ? -1 : 1) -#define MPFR_ISNONNEG(x) (MPFR_SIGN(x)>=0) -#define MPFR_ISNEG(x) (MPFR_SIGN(x)==-1) +#define MPFR_ISNONNEG(x) (MPFR_NOTZERO((x)) && MPFR_SIGN(x)>=0) +#define MPFR_ISNEG(x) (MPFR_NOTZERO((x)) && MPFR_SIGN(x)==-1) #define MPFR_CHANGE_SIGN(x) (MPFR_SIZE(x) = MPFR_SIZE(x) ^ (((mp_size_t)1)<<31)) +#define MPFR_SET_SAME_SIGN(x, y) if (MPFR_SIGN((x)) != MPFR_SIGN((y))) { MPFR_CHANGE_SIGN((x)); } #define MPFR_PREC(x) ((x)->_mp_prec) #define MPFR_NOTZERO(x) (MPFR_MANT(x)[(MPFR_PREC(x)-1)/BITS_PER_MP_LIMB]) #define MPFR_SET_ZERO(x) (MPFR_MANT(x)[(MPFR_PREC(x)-1)/BITS_PER_MP_LIMB] = 0) diff --git a/mpz_set_fr.c b/mpz_set_fr.c index 7c01399af..34b03a6fd 100644 --- a/mpz_set_fr.c +++ b/mpz_set_fr.c @@ -37,6 +37,8 @@ mpz_set_fr (z, f) { int fn, sh; + /* TODO: semantique de INF, NAN dans ce contexte ; lever une FPE ? */ + fn = 1 + (MPFR_PREC(f)-1)/BITS_PER_MP_LIMB; /* check whether allocated space for z is enough */ @@ -47,6 +47,22 @@ mpfr_mul(a, b, c, rnd_mode) /* deal with NaN and zero */ if (MPFR_IS_NAN(b) || MPFR_IS_NAN(c)) { MPFR_SET_NAN(a); return; } + if (MPFR_IS_INF(b)) + { + if (!MPFR_NOTZERO(c)) { MPFR_SET_NAN(a); return; } + else + { + if (MPFR_SIGN(a) != MPFR_SIGN(b) * MPFR_SIGN(c)) MPFR_CHANGE_SIGN(a); + } + } + else if (MPFR_IS_INF(c)) + { + if (!MPFR_NOTZERO(b)) { MPFR_SET_NAN(a); return; } + else + { + if (MPFR_SIGN(a) != MPFR_SIGN(b) * MPFR_SIGN(c)) MPFR_CHANGE_SIGN(a); + } + } if (!MPFR_NOTZERO(b) || !MPFR_NOTZERO(c)) { MPFR_SET_ZERO(a); return; } sign_product = MPFR_SIGN(b) * MPFR_SIGN(c); @@ -40,6 +40,17 @@ mpfr_mul_ui(y, x, u, rnd_mode) unsigned long xsize, ysize, cnt, dif, ex, sh; TMP_DECL(marker); + if (MPFR_IS_INF(x)) + { + if (u) + { + MPFR_SET_INF(y); + if (MPFR_SIGN(y) != MPFR_SIGN(x) * u) { MPFR_CHANGE_SIGN(y); } + return; + } + else { MPFR_SET_NAN(y); return; } + } + TMP_MARK(marker); my = MPFR_MANT(y); ex = MPFR_EXP(x); ysize = (MPFR_PREC(y)-1)/BITS_PER_MP_LIMB + 1; @@ -42,8 +42,14 @@ mpfr_out_str (stream, base, n_digits, op, rnd_mode) if (MPFR_IS_NAN(op)) { fprintf(stream, "NaN"); return 3; } if (!MPFR_NOTZERO(op)) { fprintf(stream, "0"); return 1; } + if (MPFR_IS_INF(op)) + { + if (MPFR_SIGN(op) == 1) { fprintf(stream, "Inf"); return 3; } + else { fprintf(stream, "-Inf"); return 4; } + } s = mpfr_get_str(NULL, &e, base, n_digits, op, rnd_mode); + /* TODO: maintenir le code pour les infinis dans get_str ? */ s0 = s; /* for op=3.1416 we have s = "31416" and e = 1 */ @@ -38,7 +38,16 @@ mpfr_pow_ui (x, y, n, rnd) #endif { long int i; double err; - + + if (MPFR_IS_INF(y)) + { + if (n == 0) { MPFR_SET_NAN(x); return; } + else if ((MPFR_SIGN(y) < 0 && (MPFR_SIGN(x) > 0 || n % 2 == 0)) || + MPFR_SIGN(y) > 0 && (MPFR_SIGN(x) < 0 && n % 2 == 1)) + MPFR_CHANGE_SIGN(x); + MPFR_SET_INF(x); return; + } + if (n==0) { mpfr_set_ui(x, 1, rnd); return 0; } mpfr_set(x, y, rnd); err = 1.0; for (i=0;(1<<i)<=n;i++); @@ -51,6 +60,10 @@ mpfr_pow_ui (x, y, n, rnd) } /* sets x to y^n, and returns ceil(log2(max ulp error)) */ + +/* TODO: gerer l'infini en cas de debordement ? Fait mecaniquement si fait + dans mul ? */ + int #if __STDC__ mpfr_ui_pow_ui (mpfr_ptr x, unsigned long int y, unsigned long int n, diff --git a/print_raw.c b/print_raw.c index 77821a61c..cfb596244 100644 --- a/print_raw.c +++ b/print_raw.c @@ -40,6 +40,8 @@ mpfr_get_str_raw(digit_ptr, x) ex = MPFR_EXP(x); p = MPFR_PREC(x); + /* TODO: utilite de gerer l'infini a ce niveau ? */ + if (MPFR_SIGN(x) < 0) { *digit_ptr = '-'; digit_ptr++; } sprintf(digit_ptr, "0."); digit_ptr += 2; @@ -72,6 +74,9 @@ mpfr_print_raw(x) char *str; if (MPFR_IS_NAN(x)) printf("NaN"); + else if (MPFR_IS_INF(x)) { + if (MPFR_SIGN(x) == 1) { printf("Inf"); } else printf("-Inf"); + } else if (!MPFR_NOTZERO(x)) printf("0"); else { /* 3 char for sign + 0 + binary point @@ -37,10 +37,22 @@ mpfr_reldiff(a, b, c, rnd_mode) #endif { if (MPFR_IS_NAN(b) || MPFR_IS_NAN(c)) { MPFR_SET_NAN(a); return; } + if (MPFR_IS_INF(b)) + { + if (MPFR_IS_INF(c) && (MPFR_SIGN(c) == MPFR_SIGN(b))) + { MPFR_SET_ZERO(a); return; } + else { MPFR_SET_NAN(a); return; } + } + + if (MPFR_IS_INF(c)) + { + MPFR_SET_INF(a); + if (MPFR_SIGN(a) == MPFR_SIGN(c)) { MPFR_CHANGE_SIGN(a); } + } if (!MPFR_NOTZERO(b)) /* reldiff = abs(c)/c = sign(c) */ + /* TODO: faire preciser la SEMANTIQUE DE CE FOUTOIR. */ mpfr_set_ui(a, MPFR_SIGN(c), rnd_mode); - else { mpfr_sub(a, b, c, rnd_mode); mpfr_abs(a, a, rnd_mode); /* for compatibility with MPF */ @@ -184,6 +184,7 @@ mpfr_round(x, rnd_mode, prec) mp_limb_t *tmp; int carry, signx; mp_prec_t nw; TMP_DECL(marker); + if (MPFR_IS_INF(x) || MPFR_IS_NAN(x)) return; nw = prec / BITS_PER_MP_LIMB; if (prec & (BITS_PER_MP_LIMB - 1)) nw++; signx = MPFR_SIGN(x); @@ -38,6 +38,12 @@ mpfr_set4(a, b, rnd_mode, signb) int carry, an, preca = MPFR_PREC(a), sh; mp_limb_t *ap = MPFR_MANT(a); if (MPFR_IS_NAN(b)) { MPFR_SET_NAN(a); return; } + if (MPFR_IS_INF(b)) + { + MPFR_SET_INF(a); + if (MPFR_SIGN(a) * signb < 0) MPFR_CHANGE_SIGN(a); + return; + } carry = mpfr_round_raw(ap, MPFR_MANT(b), MPFR_PREC(b), (signb<0), preca, rnd_mode); MPFR_EXP(a) = MPFR_EXP(b); @@ -31,6 +31,8 @@ extern int isnan(double); #include "mpfr.h" #define NaN sqrt(-1) /* ensures a machine-independent NaN */ +#define Infp 1/0. +#define Infm -1/0. /* Included from gmp-2.0.2, patched to support denorms */ @@ -247,6 +249,12 @@ mpfr_set_d(r, d, rnd_mode) if (d == 0) { MPFR_SET_ZERO(r); return; } else if (isnan(d)) { MPFR_SET_NAN(r); return; } + else if (isinf(d)) + { + MPFR_SET_INF(r); + if ((d > 0 && (MPFR_SIGN(r) == -1)) || (d < 0 && (MPFR_SIGN(r) == 1))) + MPFR_CHANGE_SIGN(r); + } signd = (d < 0) ? -1 : 1; d = ABS (d); @@ -290,6 +298,12 @@ mpfr_get_d2(src, e) printf("recognized NaN\n"); #endif return NaN; } + if (MPFR_IS_INF(src)) { +#ifdef DEBUG + printf("Found Inf.\n"); +#endif + return (MPFR_SIGN(src) == 1 ? Infp : Infm); + } if (MPFR_NOTZERO(src)==0) return 0.0; size = 1+(MPFR_PREC(src)-1)/BITS_PER_MP_LIMB; qp = MPFR_MANT(src); diff --git a/set_str_raw.c b/set_str_raw.c index eb2d2ed1f..caf09192f 100644 --- a/set_str_raw.c +++ b/set_str_raw.c @@ -55,7 +55,18 @@ mpfr_set_str_raw(x, str) if (*str == '-') { negative = 1; str++; } else if (*str == '+') str++; - + + if (*str == 'I') + { + MPFR_SET_INF(x); if (MPFR_ISNEG(x) != negative) { MPFR_CHANGE_SIGN(x); } + return; + } + + if (*str == 'N') + { + MPFR_SET_NAN(x); return; + } + while (*str == '0') { str++; } while (*str == '0' || *str == '1') @@ -66,7 +66,7 @@ mp_rnd_t rnd_mode; int logn; int tmp_factor; int tmpi; - if (MPFR_IS_NAN(x)) { MPFR_SET_NAN(sinus); MPFR_SET_NAN(cosinus); return 1; } + if (MPFR_IS_NAN(x) || MPFR_IS_INF(x)) { MPFR_SET_NAN(sinus); MPFR_SET_NAN(cosinus); return 1; } if (!MPFR_NOTZERO(x)) { mpfr_set_ui(sinus, 0, GMP_RNDN); mpfr_set_ui(cosinus, 1, GMP_RNDN); @@ -50,7 +50,12 @@ mpfr_sqrt (r, u, rnd_mode) TMP_DECL (marker); TMP_DECL(marker0); if (MPFR_IS_NAN(u) || MPFR_SIGN(u) == -1) { MPFR_SET_NAN(r); return 0; } - + if (MPFR_IS_INF(u)) + { + MPFR_SET_INF(r); + if (MPFR_SIGN(r) != 1) { MPFR_CHANGE_SIGN(r); } + } + prec = MPFR_PREC(r); if (!MPFR_NOTZERO(u)) @@ -515,6 +515,31 @@ mpfr_sub(a, b, c, rnd_mode) if (MPFR_IS_NAN(b) || MPFR_IS_NAN(c)) { MPFR_SET_NAN(a); return; } + if (MPFR_IS_INF(b)) + { + if (MPFR_IS_INF(c)) + { + if (MPFR_SIGN(b) != MPFR_SIGN(c)) + { + MPFR_SET_INF(a); + if (MPFR_SIGN(a) != MPFR_SIGN(b)) { MPFR_CHANGE_SIGN(a); } + } + else + MPFR_SET_NAN(a); + } + else + { + MPFR_SET_INF(a); + if (MPFR_SIGN(b) != MPFR_SIGN(a)) { MPFR_CHANGE_SIGN(a); } + } + } + else + if (MPFR_IS_INF(c)) + { + MPFR_SET_INF(a); + if (MPFR_SIGN(c) == MPFR_SIGN(a)) { MPFR_CHANGE_SIGN(a); } + } + if (!MPFR_NOTZERO(b)) { mpfr_neg(a, c, rnd_mode); return; } if (!MPFR_NOTZERO(c)) { mpfr_set(a, b, rnd_mode); return; } @@ -36,81 +36,67 @@ mpfr_zeta(result, op, rnd_mode) mp_rnd_t rnd_mode; #endif { - mpfr_t s,s2,x,y,u,b,v,nn,z,z2; - int i,n,succes; - - /* first version */ - if (mpfr_get_d(op) != 2.0 || rnd_mode != GMP_RNDN - || MPFR_PREC(result) != 53) { - fprintf(stderr, "not yet implemented\n"); exit(1); - } - -mpfr_set_default_prec(67); -mpfr_init(x); -mpfr_init(y); -mpfr_init(s); -mpfr_init(s2); -mpfr_init(u); -mpfr_init(b); -mpfr_init(v); -mpfr_init(nn); -mpfr_init(z); -mpfr_init(z2); -mpfr_set_ui(u,1,GMP_RNDN); -mpfr_set_ui(s,0,GMP_RNDN); -/*s=Somme des 1/i^2 (i=100...2)*/ -n=100; -for (i=n; i>1; i--) -{ -mpfr_set_ui(x,i*i,GMP_RNDN); -mpfr_div(y,u,x,GMP_RNDN); -mpfr_add(s,s,y,GMP_RNDN); -}; -/*mpfr_print_raw(s);printf("\n"); -t=mpfr_out_str(stdout,10,0,s,GMP_RNDN);printf("\n");*/ -/*Application d'Euler-Maclaurin, jusqu'au terme 1/n^7 - n=100)*/ -mpfr_set_ui(nn,n,GMP_RNDN); -mpfr_div(z,u,nn,GMP_RNDN); -mpfr_set(s2,z,GMP_RNDN); -mpfr_mul(z2,z,z,GMP_RNDN); -mpfr_div_2exp(v,z2,1,GMP_RNDN); -mpfr_sub(s2,s2,v,GMP_RNDN); -mpfr_set_ui(b,6,GMP_RNDN); -mpfr_mul(z,z,z2,GMP_RNDN); -mpfr_div(v,z,b,GMP_RNDN); -mpfr_add(s2,s2,v,GMP_RNDN); -mpfr_set_si(b,-30,GMP_RNDN); -mpfr_mul(z,z,z2,GMP_RNDN); -mpfr_div(v,z,b,GMP_RNDN); -mpfr_add(s2,s2,v,GMP_RNDN); -mpfr_set_si(b,42,GMP_RNDN); -mpfr_mul(z,z,z2,GMP_RNDN); -mpfr_div(v,z,b,GMP_RNDN); -mpfr_add(s2,s2,v,GMP_RNDN); -/*mpfr_print_raw(s2);printf("\n"); -t=mpfr_out_str(stdout,10,0,s2,GMP_RNDN);printf("\n");*/ -mpfr_add(s,s,s2,GMP_RNDN); -/*mpfr_print_raw(s);printf("\n"); -t=mpfr_out_str(stdout,10,0,s,GMP_RNDN);printf("\n");*/ -mpfr_add(s,s,u,GMP_RNDN); -/*mpfr_print_raw(s);printf("\n"); -t=mpfr_out_str(stdout,10,0,s,GMP_RNDN);printf("\n");*/ -/*Peut-on arrondir ? La reponse est oui*/ -succes=mpfr_can_round(s,57,GMP_RNDN,GMP_RNDN,53); -if (succes) mpfr_set(result,s,GMP_RNDN); -else { - fprintf(stderr, "can't round in mpfr_zeta\n"); exit(1); -} + mpfr_t s,s2,x,y,u,b,v,nn,z,z2; + int i,n,succes; + + /* first version */ + if (mpfr_get_d(op) != 2.0 || rnd_mode != GMP_RNDN + || MPFR_PREC(result) != 53) { + fprintf(stderr, "not yet implemented\n"); exit(1); + } + + mpfr_set_default_prec(67); + + mpfr_init(x); mpfr_init(y); mpfr_init(s); mpfr_init(s2); + mpfr_init(u); mpfr_init(b); mpfr_init(v); mpfr_init(nn); + mpfr_init(z); mpfr_init(z2); + + mpfr_set_ui(u,1,GMP_RNDN); + mpfr_set_ui(s,0,GMP_RNDN); + + /* s=Somme des 1/i^2 (i=100...2) */ + n=100; + for (i=n; i>1; i--) + { + mpfr_div_ui(y,u,i*i,GMP_RNDN); + mpfr_add(s,s,y,GMP_RNDN); + } + + /* Application d'Euler-Maclaurin, jusqu'au terme 1/n^7 - n=100) */ + /* mpfr_set_ui(nn,n,GMP_RNDN); */ + mpfr_div_ui(z,u,n,GMP_RNDN); + mpfr_mul(z2,z,z,GMP_RNDN); + mpfr_div_2exp(v,z2,1,GMP_RNDN); + + mpfr_set(s2,z,GMP_RNDN); + mpfr_sub(s2,s2,v,GMP_RNDN); + + mpfr_mul(z,z,z2,GMP_RNDN); + mpfr_div_ui(v,z,6,GMP_RNDN); + mpfr_add(s2,s2,v,GMP_RNDN); + + mpfr_mul(z,z,z2,GMP_RNDN); + mpfr_div_ui(v,z,30,GMP_RNDN); + mpfr_sub(s2,s2,v,GMP_RNDN); + + mpfr_mul(z,z,z2,GMP_RNDN); + mpfr_div_ui(v,z,42,GMP_RNDN); + mpfr_add(s2,s2,v,GMP_RNDN); + + mpfr_add(s,s,s2,GMP_RNDN); + mpfr_add(s,s,u,GMP_RNDN); + + /*Peut-on arrondir ? La reponse est oui*/ + succes=mpfr_can_round(s, 57, GMP_RNDN,GMP_RNDN, 53); + + if (succes) mpfr_set(result,s,GMP_RNDN); + else { + fprintf(stderr, "can't round in mpfr_zeta\n"); exit(1); + } + + mpfr_clear(x); mpfr_clear(y); mpfr_clear(s); mpfr_clear(s2); + mpfr_clear(u); mpfr_clear(b); mpfr_clear(v); mpfr_clear(nn); + mpfr_clear(z); mpfr_clear(z2); -mpfr_clear(x); -mpfr_clear(y); -mpfr_clear(s); -mpfr_clear(s2); -mpfr_clear(u); -mpfr_clear(b); -mpfr_clear(v); -mpfr_clear(nn); -mpfr_clear(z); -mpfr_clear(z2); -return 1; /* result is inexact */ + return 1; /* result is inexact */ } |