Permalink
Browse files

Added MPFR support for Windows

  • Loading branch information...
1 parent dfb0e52 commit 9bd3ce0c155df4d269201d816581903d945eadcf @srawlins committed Mar 5, 2010
Showing with 195 additions and 166 deletions.
  1. +6 −0 CHANGELOG
  2. +6 −28 ext/gmp.c
  3. BIN ext/gmp.so
  4. +171 −0 ext/gmpf.c
  5. +0 −132 ext/gmpf.h
  6. BIN ext/libmpfr-1.dll
  7. +6 −0 ext/ruby_gmp.h
  8. +3 −3 gmp-x86-mswin32.gemspec
  9. +3 −3 manual.tex
View
@@ -1,3 +1,9 @@
+0.4.3:
+ * Support for MPFR on Windows introduced. gmp-x86-mswin32 gem should be used.
+ * Removed compilation warnings when using MPFR
+ * Added constants GMP::GMP_CC, GMP::GMP_CFLAGS, and GMP::GMP_BITS_PER_LIMB
+ * Added constant GMP::MPFR_VERSION
+
0.4.1:
* Fixed some gem dates
* Fixed gmp.so in x86-mswin32 gem
View
@@ -135,6 +135,12 @@ static VALUE r_gmpfsg_set_default_prec(VALUE klass, VALUE arg)
void Init_gmp() {
mGMP = rb_define_module("GMP");
rb_define_const(mGMP, "GMP_VERSION", rb_str_new2(gmp_version));
+ rb_define_const(mGMP, "GMP_CC", rb_str_new2(__GMP_CC));
+ rb_define_const(mGMP, "GMP_CFLAGS", rb_str_new2(__GMP_CFLAGS));
+ rb_define_const(mGMP, "GMP_BITS_PER_LIMB", INT2FIX(mp_bits_per_limb));
+#ifdef MPFR
+ rb_define_const(mGMP, "MPFR_VERSION", rb_str_new2(MPFR_VERSION_STRING));
+#endif /* MPFR */
cGMP_Z = rb_define_class_under(mGMP, "Z", rb_cInteger);
init_gmpz();
@@ -160,34 +166,6 @@ void Init_gmp() {
init_gmpbench_timing();
-#ifdef MPFR
- rb_define_method(cGMP_F, "exp", r_gmpfr_exp, 0);
- rb_define_method(cGMP_F, "log", r_gmpfr_log, 0);
- rb_define_method(cGMP_F, "sqrt", r_gmpfr_sqrt, 0);
- rb_define_method(cGMP_F, "cos", r_gmpfr_cos, 0);
- rb_define_method(cGMP_F, "sin", r_gmpfr_sin, 0);
- rb_define_method(cGMP_F, "tan", r_gmpfr_tan, 0);
- rb_define_method(cGMP_F, "acos", r_gmpfr_acos, 0);
- rb_define_method(cGMP_F, "asin", r_gmpfr_asin, 0);
- rb_define_method(cGMP_F, "atan", r_gmpfr_atan, 0);
- rb_define_method(cGMP_F, "cosh", r_gmpfr_cosh, 0);
- rb_define_method(cGMP_F, "sinh", r_gmpfr_sinh, 0);
- rb_define_method(cGMP_F, "tanh", r_gmpfr_tanh, 0);
- rb_define_method(cGMP_F, "acosh", r_gmpfr_acosh, 0);
- rb_define_method(cGMP_F, "asinh", r_gmpfr_asinh, 0);
- rb_define_method(cGMP_F, "atanh", r_gmpfr_atanh, 0);
- rb_define_method(cGMP_F, "log1p", r_gmpfr_log1p, 0);
- rb_define_method(cGMP_F, "expm1", r_gmpfr_expm1, 0);
- rb_define_method(cGMP_F, "log2", r_gmpfr_log2, 0);
- rb_define_method(cGMP_F, "log10", r_gmpfr_log10, 0);
-
- rb_define_method(cGMP_F, "nan?", r_gmpfr_nan_p, 0);
- rb_define_method(cGMP_F, "infinite?", r_gmpfr_inf_p, 0);
- rb_define_method(cGMP_F, "finite?", r_gmpfr_fin_p, 0);
- rb_define_method(cGMP_F, "number?", r_gmpfr_number_p, 0);
-
- rb_define_method(cGMP_F, "**", r_gmpfr_pow, 1);
-#endif /* MPFR */
// more
REGISTER_TAKEOVER(and, "&", "old_and")
View
Binary file not shown.
View
@@ -515,6 +515,138 @@ DEFUN_FLOAT_CMP(gt,>)
DEFUN_FLOAT_CMP(ge,>=)
+#ifdef MPFR
+#define MPFR_SINGLE_FUNCTION(name) \
+VALUE r_gmpfr_##name(VALUE self) \
+{ \
+ MP_FLOAT *self_val, *res_val; \
+ unsigned long prec; \
+ VALUE res; \
+ \
+ mpf_get_struct_prec(self, self_val, prec); \
+ mpf_make_struct_init(res, res_val, prec); \
+ mpfr_##name(res_val, self_val, __gmp_default_rounding_mode); \
+ \
+ return res; \
+}
+
+MPFR_SINGLE_FUNCTION(log)
+MPFR_SINGLE_FUNCTION(exp)
+MPFR_SINGLE_FUNCTION(sqrt)
+MPFR_SINGLE_FUNCTION(cos)
+MPFR_SINGLE_FUNCTION(sin)
+MPFR_SINGLE_FUNCTION(tan)
+MPFR_SINGLE_FUNCTION(acos)
+MPFR_SINGLE_FUNCTION(asin)
+MPFR_SINGLE_FUNCTION(atan)
+MPFR_SINGLE_FUNCTION(cosh)
+MPFR_SINGLE_FUNCTION(sinh)
+MPFR_SINGLE_FUNCTION(tanh)
+MPFR_SINGLE_FUNCTION(acosh)
+MPFR_SINGLE_FUNCTION(asinh)
+MPFR_SINGLE_FUNCTION(atanh)
+MPFR_SINGLE_FUNCTION(log1p)
+MPFR_SINGLE_FUNCTION(expm1)
+MPFR_SINGLE_FUNCTION(log2)
+MPFR_SINGLE_FUNCTION(log10)
+
+static VALUE r_gmpfr_nan_p(VALUE self)
+{
+ MP_FLOAT *self_val;
+
+ mpf_get_struct(self, self_val);
+ if (mpfr_nan_p(self_val)) {
+ return Qtrue;
+ }
+ else {
+ return Qfalse;
+ }
+}
+
+static VALUE r_gmpfr_inf_p(VALUE self)
+{
+ MP_FLOAT *self_val;
+
+ mpf_get_struct(self, self_val);
+ if (mpfr_inf_p(self_val)) {
+ return Qtrue;
+ }
+ else {
+ return Qfalse;
+ }
+}
+
+static VALUE r_gmpfr_fin_p(VALUE self)
+{
+ if (r_gmpfr_inf_p(self)) {
+ return Qfalse;
+ }
+ else {
+ return Qtrue;
+ }
+}
+
+static VALUE r_gmpfr_number_p(VALUE self)
+{
+ MP_FLOAT *self_val;
+
+ mpf_get_struct(self, self_val);
+ if (mpfr_number_p(self_val)) {
+ return Qtrue;
+ }
+ else {
+ return Qfalse;
+ }
+}
+
+static VALUE r_gmpfr_pow(VALUE self, VALUE arg)
+{
+ MP_FLOAT *self_val, *res_val, *arg_val_f;
+ MP_RAT *arg_val_q;
+ MP_INT *arg_val_z;
+ unsigned long prec;
+ VALUE res;
+
+ mpf_get_struct_prec(self, self_val, prec);
+
+ if (GMPF_P(arg)) {
+ mpf_get_struct(arg, arg_val_f);
+ prec_max(prec, arg_val_f);
+ mpf_make_struct_init(res, res_val, prec);
+ mpfr_pow(res_val, self_val, arg_val_f, __gmp_default_rounding_mode);
+ } else {
+ mpf_make_struct_init(res, res_val, prec);
+
+ if (GMPZ_P(arg)) {
+ mpz_get_struct(arg, arg_val_z);
+ mpf_set_z(res_val, arg_val_z);
+ mpfr_pow(res_val, self_val, res_val, __gmp_default_rounding_mode);
+ } else if (GMPQ_P(arg)) {
+ mpq_get_struct(arg, arg_val_q);
+ mpf_set_q(res_val, arg_val_q);
+ mpfr_pow(res_val, self_val, res_val, __gmp_default_rounding_mode);
+ } else if (FLOAT_P(arg)) {
+ mpf_set_d(res_val, NUM2DBL(arg));
+ mpfr_pow(res_val, self_val, res_val, __gmp_default_rounding_mode);
+ } else if (FIXNUM_P(arg)) {
+ mpfr_pow_si(res_val, self_val, FIX2INT(arg), __gmp_default_rounding_mode);
+ } else if (BIGNUM_P(arg)) {
+ mpz_temp_from_bignum(arg_val_z, arg);
+ mpf_set_z(res_val, arg_val_z);
+ mpz_temp_free(arg_val_z);
+ mpfr_pow(res_val, self_val, res_val, __gmp_default_rounding_mode);
+ } else {
+ typeerror(ZQFXBD);
+ }
+
+ }
+
+ return res;
+}
+
+#endif
+
+
/**********************************************************************
* _unsorted_ *
**********************************************************************/
@@ -583,6 +715,45 @@ void init_gmpf()
rb_define_method(cGMP_F, "<=", r_gmpf_cmp_le, 1);
rb_define_method(cGMP_F, "==", r_gmpf_eq, 1);
+#ifdef MPFR
+ // Basic Arithmetic Functions
+ rb_define_method(cGMP_F, "sqrt", r_gmpfr_sqrt, 0);
+
+ rb_define_method(cGMP_F, "**", r_gmpfr_pow, 1);
+
+ // Comparison Functions
+ rb_define_method(cGMP_F, "nan?", r_gmpfr_nan_p, 0);
+ rb_define_method(cGMP_F, "infinite?", r_gmpfr_inf_p, 0);
+ rb_define_method(cGMP_F, "finite?", r_gmpfr_fin_p, 0);
+ rb_define_method(cGMP_F, "number?", r_gmpfr_number_p, 0);
+
+ // Special Functions
+ rb_define_method(cGMP_F, "log", r_gmpfr_log, 0);
+ rb_define_method(cGMP_F, "log2", r_gmpfr_log2, 0);
+ rb_define_method(cGMP_F, "log10", r_gmpfr_log10, 0);
+ rb_define_method(cGMP_F, "exp", r_gmpfr_exp, 0);
+
+ rb_define_method(cGMP_F, "cos", r_gmpfr_cos, 0);
+ rb_define_method(cGMP_F, "sin", r_gmpfr_sin, 0);
+ rb_define_method(cGMP_F, "tan", r_gmpfr_tan, 0);
+
+ rb_define_method(cGMP_F, "acos", r_gmpfr_acos, 0);
+ rb_define_method(cGMP_F, "asin", r_gmpfr_asin, 0);
+ rb_define_method(cGMP_F, "atan", r_gmpfr_atan, 0);
+
+ rb_define_method(cGMP_F, "cosh", r_gmpfr_cosh, 0);
+ rb_define_method(cGMP_F, "sinh", r_gmpfr_sinh, 0);
+ rb_define_method(cGMP_F, "tanh", r_gmpfr_tanh, 0);
+
+ rb_define_method(cGMP_F, "acosh", r_gmpfr_acosh, 0);
+ rb_define_method(cGMP_F, "asinh", r_gmpfr_asinh, 0);
+ rb_define_method(cGMP_F, "atanh", r_gmpfr_atanh, 0);
+
+ rb_define_method(cGMP_F, "log1p", r_gmpfr_log1p, 0);
+ rb_define_method(cGMP_F, "expm1", r_gmpfr_expm1, 0);
+
+#endif /* MPFR */
+
// _unsorted_
rb_define_method(cGMP_F, "floor", r_gmpf_floor, 0);
rb_define_method(cGMP_F, "floor!", r_gmpf_floor_self, 0);
View
@@ -9,136 +9,4 @@
#include <ruby_gmp.h>
-#ifdef MPFR
-#define MPFR_SINGLE_FUNCTION(name) \
-static VALUE r_gmpfr_##name(VALUE self) \
-{ \
- MP_FLOAT *self_val, *res_val; \
- unsigned long prec; \
- VALUE res; \
- \
- mpf_get_struct_prec(self, self_val, prec); \
- mpf_make_struct_init(res, res_val, prec); \
- mpfr_##name(res_val, self_val, __gmp_default_rounding_mode); \
- \
- return res; \
-}
-
-MPFR_SINGLE_FUNCTION(log)
-MPFR_SINGLE_FUNCTION(exp)
-MPFR_SINGLE_FUNCTION(sqrt)
-MPFR_SINGLE_FUNCTION(cos)
-MPFR_SINGLE_FUNCTION(sin)
-MPFR_SINGLE_FUNCTION(tan)
-MPFR_SINGLE_FUNCTION(acos)
-MPFR_SINGLE_FUNCTION(asin)
-MPFR_SINGLE_FUNCTION(atan)
-MPFR_SINGLE_FUNCTION(cosh)
-MPFR_SINGLE_FUNCTION(sinh)
-MPFR_SINGLE_FUNCTION(tanh)
-MPFR_SINGLE_FUNCTION(acosh)
-MPFR_SINGLE_FUNCTION(asinh)
-MPFR_SINGLE_FUNCTION(atanh)
-MPFR_SINGLE_FUNCTION(log1p)
-MPFR_SINGLE_FUNCTION(expm1)
-MPFR_SINGLE_FUNCTION(log2)
-MPFR_SINGLE_FUNCTION(log10)
-
-static VALUE r_gmpfr_nan_p(VALUE self)
-{
- MP_FLOAT *self_val;
-
- mpf_get_struct(self, self_val);
- if (mpfr_nan_p(self_val)) {
- return Qtrue;
- }
- else {
- return Qfalse;
- }
-}
-
-static VALUE r_gmpfr_inf_p(VALUE self)
-{
- MP_FLOAT *self_val;
-
- mpf_get_struct(self, self_val);
- if (mpfr_inf_p(self_val)) {
- return Qtrue;
- }
- else {
- return Qfalse;
- }
-}
-
-static VALUE r_gmpfr_fin_p(VALUE self)
-{
- if (r_gmpfr_inf_p(self)) {
- return Qfalse;
- }
- else {
- return Qtrue;
- }
-}
-
-static VALUE r_gmpfr_number_p(VALUE self)
-{
- MP_FLOAT *self_val;
-
- mpf_get_struct(self, self_val);
- if (mpfr_number_p(self_val)) {
- return Qtrue;
- }
- else {
- return Qfalse;
- }
-}
-
-static VALUE r_gmpfr_pow(VALUE self, VALUE arg)
-{
- MP_FLOAT *self_val, *res_val, *arg_val_f;
- MP_RAT *arg_val_q;
- MP_INT *arg_val_z;
- unsigned long prec;
- VALUE res;
-
- mpf_get_struct_prec(self, self_val, prec);
-
- if (GMPF_P(arg)) {
- mpf_get_struct(arg, arg_val_f);
- prec_max(prec, arg_val_f);
- mpf_make_struct_init(res, res_val, prec);
- mpfr_pow(res_val, self_val, arg_val_f, __gmp_default_rounding_mode);
- } else {
- mpf_make_struct_init(res, res_val, prec);
-
- if (GMPZ_P(arg)) {
- mpz_get_struct(arg, arg_val_z);
- mpf_set_z(res_val, arg_val_z);
- mpfr_pow(res_val, self_val, res_val, __gmp_default_rounding_mode);
- } else if (GMPQ_P(arg)) {
- mpq_get_struct(arg, arg_val_q);
- mpf_set_q(res_val, arg_val_q);
- mpfr_pow(res_val, self_val, res_val, __gmp_default_rounding_mode);
- } else if (FLOAT_P(arg)) {
- mpf_set_d(res_val, FLT2DBL(arg));
- mpfr_pow(res_val, self_val, res_val, __gmp_default_rounding_mode);
- } else if (FIXNUM_P(arg)) {
- mpfr_pow_si(res_val, self_val, FIX2INT(arg), __gmp_default_rounding_mode);
- } else if (BIGNUM_P(arg)) {
- mpz_temp_from_bignum(arg_val_z, arg);
- mpf_set_z(res_val, arg_val_z);
- mpz_temp_free(arg_val_z);
- mpfr_pow(res_val, self_val, res_val, __gmp_default_rounding_mode);
- } else {
- typeerror(ZQFXBD);
- }
-
- }
-
- return res;
-}
-
-#endif
-
-
#endif
View
Binary file not shown.
View
@@ -207,6 +207,12 @@ extern VALUE r_gmpf_eq(VALUE self, VALUE arg);
extern VALUE r_gmpf_cmp(VALUE self, VALUE arg);
extern int mpf_cmp_value(MP_FLOAT *OP, VALUE arg);
+// MPFR
+#ifdef MPFR
+ extern VALUE r_gmpfr_log(VALUE self);
+ extern VALUE r_gmpfr_exp(VALUE self);
+#endif /* MPFR */
+
// _unsorted_
extern VALUE r_gmpf_sgn(VALUE self);
extern VALUE r_gmpf_get_prec(VALUE self);
Oops, something went wrong.

0 comments on commit 9bd3ce0

Please sign in to comment.