summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--add.c2
-rw-r--r--agm.c9
-rw-r--r--exp2.c16
-rw-r--r--exp3.c4
-rw-r--r--generic.c4
-rw-r--r--log2.c4
-rw-r--r--pi.c4
-rw-r--r--print_raw.c2
-rw-r--r--set_d.c4
-rw-r--r--sin_cos.c41
-rw-r--r--sub.c4
11 files changed, 61 insertions, 33 deletions
diff --git a/add.c b/add.c
index 63cbb9109..6aaf88ad7 100644
--- a/add.c
+++ b/add.c
@@ -29,7 +29,7 @@ MA 02111-1307, USA. */
extern void mpfr_sub1 _PROTO((mpfr_ptr, mpfr_srcptr, mpfr_srcptr,
mp_rnd_t, int));
-void mpfr_add1 (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mp_rnd_t, int);
+void mpfr_add1 _PROTO((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mp_rnd_t, int));
#define ONE ((mp_limb_t) 1)
diff --git a/agm.c b/agm.c
index b9a3b435f..27a992769 100644
--- a/agm.c
+++ b/agm.c
@@ -26,7 +26,8 @@ MA 02111-1307, USA. */
#include "mpfr-impl.h"
/* returns ceil(log(d)/log(2)) */
-long _mpfr_ceil_log2 (double d)
+long
+_mpfr_ceil_log2 (double d)
{
long exp;
union ieee_double_extract x;
@@ -39,7 +40,8 @@ long _mpfr_ceil_log2 (double d)
}
/* returns floor(log(d)/log(2)) */
-long _mpfr_floor_log2 (double d)
+long
+_mpfr_floor_log2 (double d)
{
union ieee_double_extract x;
@@ -48,7 +50,8 @@ long _mpfr_floor_log2 (double d)
}
/* returns y >= 2^d */
-double _mpfr_ceil_exp2 (double d)
+double
+_mpfr_ceil_exp2 (double d)
{
long exp;
union ieee_double_extract x;
diff --git a/exp2.c b/exp2.c
index d18926dc4..7756e4321 100644
--- a/exp2.c
+++ b/exp2.c
@@ -26,14 +26,15 @@ MA 02111-1307, USA. */
#include "mpfr.h"
#include "mpfr-impl.h"
-int mpfr_exp2_aux (mpz_t, mpfr_srcptr, int, int*);
-int mpfr_exp2_aux2 (mpz_t, mpfr_srcptr, int, int*);
-mp_exp_t mpz_normalize (mpz_t, mpz_t, int);
-int mpz_normalize2 (mpz_t, mpz_t, int, int);
-int mpfr_exp2 (mpfr_ptr, mpfr_srcptr, mp_rnd_t);
+int mpfr_exp2_aux _PROTO ((mpz_t, mpfr_srcptr, int, int*));
+int mpfr_exp2_aux2 _PROTO ((mpz_t, mpfr_srcptr, int, int*));
+mp_exp_t mpz_normalize _PROTO ((mpz_t, mpz_t, int));
+int mpz_normalize2 _PROTO ((mpz_t, mpz_t, int, int));
+int mpfr_exp2 _PROTO ((mpfr_ptr, mpfr_srcptr, mp_rnd_t));
/* returns floor(sqrt(n)) */
-unsigned long _mpfr_isqrt (unsigned long n)
+unsigned long
+_mpfr_isqrt (unsigned long n)
{
unsigned long s;
@@ -45,7 +46,8 @@ unsigned long _mpfr_isqrt (unsigned long n)
}
/* returns floor(n^(1/3)) */
-unsigned long _mpfr_cuberoot (unsigned long n)
+unsigned long
+_mpfr_cuberoot (unsigned long n)
{
double s, is;
diff --git a/exp3.c b/exp3.c
index 42819d5d8..175ef143d 100644
--- a/exp3.c
+++ b/exp3.c
@@ -27,8 +27,8 @@ MA 02111-1307, USA. */
/* #define DEBUG */
-int mpfr_exp_rational (mpfr_ptr, mpz_srcptr, int, int);
-int mpfr_exp3 (mpfr_ptr, mpfr_srcptr, mp_rnd_t);
+int mpfr_exp_rational _PROTO ((mpfr_ptr, mpz_srcptr, int, int));
+int mpfr_exp3 _PROTO ((mpfr_ptr, mpfr_srcptr, mp_rnd_t));
int
#if __STDC__
diff --git a/generic.c b/generic.c
index da37773b0..88e509367 100644
--- a/generic.c
+++ b/generic.c
@@ -20,14 +20,14 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#ifndef GENERIC
-# error You should specify a name
+ # 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
+ # error B cannot be used without A
# endif
#endif
diff --git a/log2.c b/log2.c
index 0c8688eac..70f4aabd0 100644
--- a/log2.c
+++ b/log2.c
@@ -30,8 +30,8 @@ mpfr_t __mpfr_const_log2; /* stored value of log(2) */
int __mpfr_const_log2_prec=0; /* precision of stored value */
mp_rnd_t __mpfr_const_log2_rnd; /* rounding mode of stored value */
-int mpfr_aux_log2 (mpfr_ptr, mpz_srcptr, int, int);
-int mpfr_const_aux_log2 (mpfr_ptr, mp_rnd_t);
+int mpfr_aux_log2 _PROTO ((mpfr_ptr, mpz_srcptr, int, int));
+int mpfr_const_aux_log2 _PROTO ((mpfr_ptr, mp_rnd_t));
#define A
#define A1 1
diff --git a/pi.c b/pi.c
index 54b0d3f84..fa72a5f8c 100644
--- a/pi.c
+++ b/pi.c
@@ -26,8 +26,8 @@ MA 02111-1307, USA. */
#include "mpfr.h"
#include "mpfr-impl.h"
-int mpfr_aux_pi (mpfr_ptr, mpz_srcptr, int, int);
-int mpfr_pi_machin3 (mpfr_ptr, mp_rnd_t);
+int mpfr_aux_pi _PROTO ((mpfr_ptr, mpz_srcptr, int, int));
+int mpfr_pi_machin3 _PROTO ((mpfr_ptr, mp_rnd_t));
#define A
#define A1 1
diff --git a/print_raw.c b/print_raw.c
index a8bb468be..3b75e8eb3 100644
--- a/print_raw.c
+++ b/print_raw.c
@@ -26,7 +26,7 @@ MA 02111-1307, USA. */
#include "mpfr.h"
#include "mpfr-impl.h"
-void mpfr_get_str_raw (char *, mpfr_srcptr);
+void mpfr_get_str_raw _PROTO ((char *, mpfr_srcptr));
void
#if __STDC__
diff --git a/set_d.c b/set_d.c
index 7d77f5bfd..113066ce4 100644
--- a/set_d.c
+++ b/set_d.c
@@ -32,8 +32,8 @@ MA 02111-1307, USA. */
#define MPFR_LIMBS_PER_DOUBLE 1
#endif
-int __mpfr_extract_double (mp_ptr, double, int);
-double __mpfr_scale2 (double, int);
+int __mpfr_extract_double _PROTO ((mp_ptr, double, int));
+double __mpfr_scale2 _PROTO ((double, int));
#define NaN (0./0.) /* ensures a machine-independent NaN */
#define Infp (1/0.)
diff --git a/sin_cos.c b/sin_cos.c
index 2d1cda102..ff1300f09 100644
--- a/sin_cos.c
+++ b/sin_cos.c
@@ -26,8 +26,8 @@ MA 02111-1307, USA. */
#include "mpfr.h"
#include "mpfr-impl.h"
-int mpfr_sin_aux (mpfr_ptr, mpz_srcptr, int, int);
-int mpfr_cos_aux (mpfr_ptr, mpz_srcptr, int, int);
+int mpfr_sin_aux _PROTO ((mpfr_ptr, mpz_srcptr, int, int));
+int mpfr_cos_aux _PROTO ((mpfr_ptr, mpz_srcptr, int, int));
#undef A
#undef B
@@ -83,6 +83,7 @@ mpfr_sin_cos (sinus, cosinus, x, rnd_mode)
int logn;
int tmp_factor;
int tmpi;
+ TMP_DECL (marker);
if (sinus == cosinus) {
fprintf (stderr, "Error in mpfr_sin_cos: 1st and 2nd operands must be different\n");
@@ -90,17 +91,40 @@ mpfr_sin_cos (sinus, cosinus, x, rnd_mode)
}
if (MPFR_IS_NAN(x) || MPFR_IS_INF(x)) {
- MPFR_SET_NAN(sinus);
- MPFR_SET_NAN(cosinus);
+ if (sinus != NULL) MPFR_SET_NAN(sinus);
+ if (cosinus != NULL) MPFR_SET_NAN(cosinus);
return 1; /* inexact */
}
if (!MPFR_NOTZERO(x)) {
- mpfr_set_ui(sinus, 0, GMP_RNDN);
- mpfr_set_ui(cosinus, 1, GMP_RNDN);
+ if (sinus != NULL) mpfr_set_ui (sinus, 0, GMP_RNDN);
+ if (cosinus != NULL) mpfr_set_ui (cosinus, 1, GMP_RNDN);
return 0; /* exact results */
}
+ TMP_MARK (marker);
+ /* allow sinus or cosinus to be NULL */
+ if (sinus == NULL) { mp_size_t s;
+ if (cosinus == NULL) {
+ fprintf (stderr, "Error in mpfr_sin_cos: 1st and 2nd operands cannot be NULL simultaneously\n");
+ exit (1);
+ }
+ s = 1 + (MPFR_PREC(cosinus) - 1) / BITS_PER_MP_LIMB;
+ sinus = TMP_ALLOC (sizeof(mpfr_t));
+ MPFR_MANT(sinus) = (mp_ptr) TMP_ALLOC(s*BYTES_PER_MP_LIMB);
+ MPFR_PREC(sinus) = MPFR_PREC(cosinus);
+ MPFR_SIZE(sinus) = s;
+ MPFR_EXP(sinus) = 0;
+ }
+ else if (cosinus == NULL) { mp_size_t s;
+ s = 1 + (MPFR_PREC(sinus) - 1) / BITS_PER_MP_LIMB;
+ cosinus = TMP_ALLOC (sizeof(mpfr_t));
+ MPFR_MANT(cosinus) = (mp_ptr) TMP_ALLOC(s*BYTES_PER_MP_LIMB);
+ MPFR_PREC(cosinus) = MPFR_PREC(sinus);
+ MPFR_SIZE(cosinus) = s;
+ MPFR_EXP(cosinus) = 0;
+ }
+
prec_x = _mpfr_ceil_log2 ((double) MPFR_PREC(x) / BITS_PER_MP_LIMB);
ttt = MPFR_EXP(x);
mpfr_init2(x_copy, MPFR_PREC(x));
@@ -245,8 +269,7 @@ mpfr_sin_cos (sinus, cosinus, x, rnd_mode)
mpz_clear (uk);
mpz_clear (square);
mpfr_clear (x_copy);
+ TMP_FREE (marker);
+
return 1; /* inexact result */
}
-
-
-
diff --git a/sub.c b/sub.c
index 4971472de..9fda68d49 100644
--- a/sub.c
+++ b/sub.c
@@ -31,8 +31,8 @@ MA 02111-1307, USA. */
extern void mpfr_add1 _PROTO((mpfr_ptr, mpfr_srcptr, mpfr_srcptr,
mp_rnd_t, int));
-mp_limb_t mpn_sub_lshift_n (mp_limb_t *, mp_limb_t *, int, int, int);
-void mpfr_sub1 (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mp_rnd_t, int);
+mp_limb_t mpn_sub_lshift_n _PROTO ((mp_limb_t *, mp_limb_t *, int, int, int));
+void mpfr_sub1 _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mp_rnd_t, int));
/* put in ap[0]..ap[an-1] the value of bp[0]..bp[n-1] shifted by sh bits
to the left minus ap[0]..ap[n-1], with 0 <= sh < BITS_PER_MP_LIMB, and