ext/mpfr/ruby_mpfr.c in ruby-mpfr-0.0.7 vs ext/mpfr/ruby_mpfr.c in ruby-mpfr-0.0.8

- old
+ new

@@ -1,12 +1,19 @@ #include "ruby_mpfr.h" +#define MPFR_DUMP_NUMBER 'A' +#define MPFR_DUMP_PZERO 'B' +#define MPFR_DUMP_MZERO 'C' +#define MPFR_DUMP_PINF 'D' +#define MPFR_DUMP_MINF 'E' +#define MPFR_DUMP_NAN 'F' + static ID eqq, to_s, new, class, method_defined, object_id; static VALUE __mpfr_class__, __sym_to_s__, __sym_to_str__; /* ------------------------------ Precision and Rounding Mode Start ------------------------------ */ -#define VALID_RND(rnd) (rnd >= 0 && rnd <= 3) +#define VALID_RND(rnd_mode) (rnd_mode >= MPFR_RNDN && rnd_mode < ((MPFR_RNDA)+1)) #define SPECIAL_FUNC_STATE "@@special_func_state" /* Convert VALUE rnd (rounding mode number) to C integer and */ /* return it if it is valid as rounding mode number. */ mp_rnd_t r_mpfr_rnd_from_value(VALUE rnd) @@ -454,10 +461,25 @@ r_mpfr_make_struct_init2(val_ret, ptr_return, prec); mpfr_set_nan(ptr_return); return val_ret; } +/* Return zero. This method takes one optional argument meaning precision. */ +static VALUE r_mpfr_zero(int argc, VALUE *argv, VALUE self) +{ + mp_prec_t prec = r_mpfr_prec_from_optional_argument(0, 2, argc, argv); + MPFR *ptr_return; + VALUE val_ret; + int sign = 1; + if (argc >= 1) { + sign = NUM2INT(argv[0]); + } + r_mpfr_make_struct_init2(val_ret, ptr_return, prec); + mpfr_set_zero(ptr_return, sign); + return val_ret; +} + /* Return plus infinity. This method takes one optional argument meaning precision. */ static VALUE r_mpfr_pinf(int argc, VALUE *argv, VALUE self) { mp_prec_t prec = r_mpfr_prec_from_optional_argument(0, 1, argc, argv); MPFR *ptr_return; @@ -541,10 +563,25 @@ r_mpfr_get_struct(ptr_self, self); mpfr_set_nan(ptr_self); return self; } +/* Set the value of self to zero. */ +static VALUE r_mpfr_set_zero(int argc, VALUE *argv, VALUE self) +{ + int sign = 1; + MPFR *ptr_self; + r_mpfr_get_struct(ptr_self, self); + if (argc == 1) { + sign = NUM2INT(argv[0]); + } else if (argc > 1) { + rb_raise(rb_eArgError, "Invalid number of arguments."); + } + mpfr_set_zero(ptr_self, sign); + return self; +} + /* Swap the values self and p1 efficiently. p1 must be MPFR object. */ static VALUE r_mpfr_swap(VALUE self, VALUE other) { MPFR *ptr_self, *ptr_other; r_mpfr_get_struct(ptr_self, self); @@ -1195,10 +1232,18 @@ MPFR *ptr_self; r_mpfr_get_struct(ptr_self, self); return (mpfr_zero_p(ptr_self) == 0 ? Qtrue : Qfalse); } +/* Return true if self is regular number, nil otherwise. */ +static VALUE r_mpfr_regular_p(VALUE self) +{ + MPFR *ptr_self; + r_mpfr_get_struct(ptr_self, self); + return (mpfr_regular_p(ptr_self) != 0 ? Qtrue : Qfalse); +} + /* mpfr_sgn(self). */ static VALUE r_mpfr_sgn(VALUE self) { MPFR *ptr_self; r_mpfr_get_struct(ptr_self, self); @@ -1278,11 +1323,11 @@ /* ------------------------------ Comparison Functions End ------------------------------ */ /* ------------------------------ Integer Related Functions Start ------------------------------ */ /* mpfr_rint(ret, self, rnd) */ -static VALUE r_mpfr_m_rint(int argc, VALUE *argv, VALUE self) +static VALUE r_mpfr_fr_rint(int argc, VALUE *argv, VALUE self) { mp_rnd_t rnd; mp_prec_t prec; r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 0, 2, argc, argv); MPFR *ptr_self, *ptr_return; @@ -1292,11 +1337,11 @@ mpfr_rint(ptr_return, ptr_self, rnd); return val_ret; } /* mpfr_ceil(ret, self) */ -static VALUE r_mpfr_m_ceil(int argc, VALUE *argv, VALUE self) +static VALUE r_mpfr_fr_ceil(int argc, VALUE *argv, VALUE self) { mp_prec_t prec = r_mpfr_prec_from_optional_argument(0, 1, argc, argv); MPFR *ptr_self, *ptr_return; VALUE val_ret; r_mpfr_get_struct(ptr_self, self); @@ -1304,11 +1349,11 @@ mpfr_ceil(ptr_return, ptr_self); return val_ret; } /* mpfr_floor(ret, self) */ -static VALUE r_mpfr_m_floor(int argc, VALUE *argv, VALUE self) +static VALUE r_mpfr_fr_floor(int argc, VALUE *argv, VALUE self) { mp_prec_t prec = r_mpfr_prec_from_optional_argument(0, 1, argc, argv); MPFR *ptr_self, *ptr_return; VALUE val_ret; r_mpfr_get_struct(ptr_self, self); @@ -1316,11 +1361,11 @@ mpfr_floor(ptr_return, ptr_self); return val_ret; } /* mpfr_round(ret, self) */ -static VALUE r_mpfr_m_round(int argc, VALUE *argv, VALUE self) +static VALUE r_mpfr_fr_round(int argc, VALUE *argv, VALUE self) { mp_prec_t prec = r_mpfr_prec_from_optional_argument(0, 1, argc, argv); MPFR *ptr_self, *ptr_return; VALUE val_ret; r_mpfr_get_struct(ptr_self, self); @@ -1328,11 +1373,11 @@ mpfr_round(ptr_return, ptr_self); return val_ret; } /* mpfr_trunc(ret, self) */ -static VALUE r_mpfr_m_trunc(int argc, VALUE *argv, VALUE self) +static VALUE r_mpfr_fr_trunc(int argc, VALUE *argv, VALUE self) { mp_prec_t prec = r_mpfr_prec_from_optional_argument(0, 1, argc, argv); MPFR *ptr_self, *ptr_return; VALUE val_ret; r_mpfr_get_struct(ptr_self, self); @@ -1607,11 +1652,11 @@ mpfr_set(ptr_return, ptr_self, mpfr_get_default_prec()); mpfr_prec_round(ptr_return, prec, rnd); return val_ret; } -/* mpfr_prec_round(ret, prec, rnd) */ +/* mpfr_prec_round(self, prec, rnd) */ static VALUE r_mpfr_prec_round2(int argc, VALUE *argv, VALUE self) { mp_rnd_t rnd; mp_prec_t prec; r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 0, 2, argc, argv); @@ -1619,10 +1664,30 @@ r_mpfr_get_struct(ptr_self, self); mpfr_prec_round(ptr_self, prec, rnd); return self; } +/* mpfr_can_round(self, err, rnd1, rnd2, prec) */ +static VALUE r_mpfr_can_round(VALUE self, VALUE err, VALUE rnd1, VALUE rnd2, VALUE prec) +{ + MPFR *ptr_self; + r_mpfr_get_struct(ptr_self, self); + if (mpfr_can_round(ptr_self, NUM2INT(err), NUM2INT(rnd1), NUM2INT(rnd2), NUM2INT(prec))) { + return Qtrue; + } + return Qnil; +} + +/* mpfr_min_prec(self) */ +static VALUE r_mpfr_min_prec(VALUE self) +{ + MPFR *ptr_self; + r_mpfr_get_struct(ptr_self, self); + return INT2NUM(mpfr_min_prec(ptr_self)); +} + + /* ------------------------------ Rounding Mode Related Functions End ------------------------------ */ /* ------------------------------ Special Functions Start ------------------------------ */ /* @@ -1958,10 +2023,55 @@ r_mpfr_make_struct_init2(val_ret2, ptr_return2, prec); r_mpfr_set_special_func_state(mpfr_sinh_cosh(ptr_return1, ptr_return2, ptr_arg1, rnd)); return rb_ary_new3(2, val_ret1, val_ret2); } +/* mpfr_sech(ret, p1, rnd). */ +static VALUE r_mpfr_math_sech(int argc, VALUE *argv, VALUE self) +{ + mp_rnd_t rnd; + mp_prec_t prec; + r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 1, 3, argc, argv); + MPFR *ptr_arg1, *ptr_return; + VALUE val_ret; + volatile VALUE tmp_argv0 = r_mpfr_new_fr_obj(argv[0]); + r_mpfr_get_struct(ptr_arg1, tmp_argv0); + r_mpfr_make_struct_init2(val_ret, ptr_return, prec); + r_mpfr_set_special_func_state(mpfr_sech(ptr_return, ptr_arg1, rnd)); + return val_ret; +} + +/* mpfr_csch(ret, p1, rnd). */ +static VALUE r_mpfr_math_csch(int argc, VALUE *argv, VALUE self) +{ + mp_rnd_t rnd; + mp_prec_t prec; + r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 1, 3, argc, argv); + MPFR *ptr_arg1, *ptr_return; + VALUE val_ret; + volatile VALUE tmp_argv0 = r_mpfr_new_fr_obj(argv[0]); + r_mpfr_get_struct(ptr_arg1, tmp_argv0); + r_mpfr_make_struct_init2(val_ret, ptr_return, prec); + r_mpfr_set_special_func_state(mpfr_csch(ptr_return, ptr_arg1, rnd)); + return val_ret; +} + +/* mpfr_coth(ret, p1, rnd). */ +static VALUE r_mpfr_math_coth(int argc, VALUE *argv, VALUE self) +{ + mp_rnd_t rnd; + mp_prec_t prec; + r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 1, 3, argc, argv); + MPFR *ptr_arg1, *ptr_return; + VALUE val_ret; + volatile VALUE tmp_argv0 = r_mpfr_new_fr_obj(argv[0]); + r_mpfr_get_struct(ptr_arg1, tmp_argv0); + r_mpfr_make_struct_init2(val_ret, ptr_return, prec); + r_mpfr_set_special_func_state(mpfr_coth(ptr_return, ptr_arg1, rnd)); + return val_ret; +} + /* mpfr_acosh(ret, p1, rnd). */ static VALUE r_mpfr_math_acosh(int argc, VALUE *argv, VALUE self) { mp_rnd_t rnd; mp_prec_t prec; @@ -2127,10 +2237,25 @@ r_mpfr_make_struct_init2(val_ret, ptr_return, prec); r_mpfr_set_special_func_state(mpfr_lgamma(ptr_return, &singp, ptr_arg1, rnd)); return rb_ary_new3(2, val_ret, INT2FIX(singp)); } +/* mpfr_digamma(ret, p1, rnd). */ +static VALUE r_mpfr_math_digamma(int argc, VALUE *argv, VALUE self) +{ + mp_rnd_t rnd; + mp_prec_t prec; + r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 1, 3, argc, argv); + MPFR *ptr_arg1, *ptr_return; + VALUE val_ret; + volatile VALUE tmp_argv0 = r_mpfr_new_fr_obj(argv[0]); + r_mpfr_get_struct(ptr_arg1, tmp_argv0); + r_mpfr_make_struct_init2(val_ret, ptr_return, prec); + r_mpfr_set_special_func_state(mpfr_digamma(ptr_return, ptr_arg1, rnd)); + return val_ret; +} + /* mpfr_zeta(ret, p1, rnd). */ static VALUE r_mpfr_math_zeta(int argc, VALUE *argv, VALUE self) { mp_rnd_t rnd; mp_prec_t prec; @@ -2344,10 +2469,25 @@ r_mpfr_make_struct_init2(val_ret, ptr_return, prec); r_mpfr_set_special_func_state(mpfr_hypot(ptr_return, ptr_arg1, ptr_arg2, rnd)); return val_ret; } +/* mpfr_ai(ret, p1, rnd). */ +static VALUE r_mpfr_math_ai(int argc, VALUE *argv, VALUE self) +{ + mp_rnd_t rnd; + mp_prec_t prec; + r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 1, 3, argc, argv); + MPFR *ptr_arg1, *ptr_return; + VALUE val_ret; + volatile VALUE tmp_argv0 = r_mpfr_new_fr_obj(argv[0]); + r_mpfr_get_struct(ptr_arg1, tmp_argv0); + r_mpfr_make_struct_init2(val_ret, ptr_return, prec); + r_mpfr_set_special_func_state(mpfr_ai(ptr_return, ptr_arg1, rnd)); + return val_ret; +} + /* mpfr_const_log2(ret, rnd). */ static VALUE r_mpfr_math_const_log2(int argc, VALUE *argv, VALUE self) { mp_rnd_t rnd; mp_prec_t prec; @@ -2463,12 +2603,115 @@ r_mpfr_make_struct_init2(val_ret, ptr_return, prec); mpfr_max(ptr_return, ptr_arg1, ptr_arg2, rnd); return val_ret; } +/* Version string which mpfr_get_version() returns. */ +static VALUE r_mpfr_get_version(VALUE self) +{ + return rb_str_new2(mpfr_get_version()); +} +/* String which mpfr_get_patches() returns. */ +static VALUE r_mpfr_get_patches(VALUE self) +{ + return rb_str_new2(mpfr_get_patches()); +} +/* Return true if MPFR was compiled as thread safe using compiler-level Thread Local Storage. Otherwise, nil. */ +static VALUE r_mpfr_buildopt_tls_p(VALUE self) +{ + return mpfr_buildopt_tls_p() == 0 ? Qnil : Qtrue; +} + +/* Return true if MPFR was compiled with decimal float support. Otherwise, nil. */ +static VALUE r_mpfr_buildopt_decimal_p(VALUE self) +{ + return mpfr_buildopt_decimal_p() == 0 ? Qnil : Qtrue; +} + +static VALUE r_mpfr_marshal_dump(VALUE self) +{ + MPFR *ptr_s; + r_mpfr_get_struct(ptr_s, self); + char *ret_str; + if (mpfr_regular_p(ptr_s)) { + mpz_t m; + mp_exp_t e; + mpz_init(m); + e = mpfr_get_z_2exp(m, ptr_s); + mpfr_asprintf(&ret_str, "%c%ld\t%ld\t%Zd", MPFR_DUMP_NUMBER, mpfr_get_prec(ptr_s), (long int)e, m); + mpz_clear(m); + } else { + char type; + if (mpfr_zero_p(ptr_s)) { + if (mpfr_sgn(ptr_s) >= 0) { + type = MPFR_DUMP_PZERO; + } else { + type = MPFR_DUMP_MZERO; + } + } else if (mpfr_nan_p(ptr_s)) { + type = MPFR_DUMP_NAN; + } else if (mpfr_sgn(ptr_s) >= 0) { + type = MPFR_DUMP_PINF; + } else { + type = MPFR_DUMP_MINF; + } + mpfr_asprintf(&ret_str, "%c%ld", type, mpfr_get_prec(ptr_s)); + } + VALUE ret_val = rb_str_new2(ret_str); + mpfr_free_str(ret_str); + return ret_val; +} + +static VALUE r_mpfr_marshal_load(VALUE self, VALUE dump_string) +{ + long int prec; + MPFR *ptr_s; + r_mpfr_get_struct(ptr_s, self); + Check_Type(dump_string, T_STRING); + char *dump, type; + dump = RSTRING_PTR(dump_string); + type = dump[0]; + dump++; + if (type == MPFR_DUMP_NUMBER) { + mpz_t m; + long int e; + mpz_init(m); + sscanf(dump, "%ld\t%ld\t", &prec, &e); + int i; + i = 0; + while (i < 2) { + if (dump[0] == '\t') { + i++; + } + dump++; + } + mpz_set_str(m, dump, 10); + mpfr_init2(ptr_s, prec); + mpfr_set_z_2exp(ptr_s, m, e, MPFR_RNDN); + mpz_clear(m); + } else { + sscanf(dump, "%ld", &prec); + mpfr_init2(ptr_s, prec); + if (type == MPFR_DUMP_PZERO) { + mpfr_set_zero(ptr_s, +1); + } else if (type == MPFR_DUMP_MZERO){ + mpfr_set_zero(ptr_s, -1); + } else if (type == MPFR_DUMP_NAN) { + mpfr_set_nan(ptr_s); + } else if (type == MPFR_DUMP_PINF) { + mpfr_set_inf(ptr_s, +1); + } else if (type == MPFR_DUMP_MINF) { + mpfr_set_inf(ptr_s, -1); + } else { + rb_raise(rb_eArgError, "Invalid dumped data for marshal_load."); + } + } + return self; +} + void Init_mpfr() { /* ------------------------------ Class MPFR Start ------------------------------ */ /* @@ -2492,11 +2735,11 @@ == Name of methods and constants Except for some methods, the names of methods inherit that of MPFR functions in C language and each name of method is removed 'mpfr_' from that of correspnding MPFR function in C language. - The methods m_rint, m_ceil, m_floor, m_round and m_trunc are exceptions and + The methods fr_rint, fr_ceil, fr_floor, fr_round and fr_trunc are exceptions and respectively corresponts to mpfr_rint, mpfr_ceil, mpfr_floor, mpfr_round and mpfr_trunc. Note that there are also methods rint, ceil, floor, round and trunc which have respectively defferent actions from mpfr_rint, mpfr_ceil, mpfr_floor, mpfr_round and mpfr_trunc. @@ -2533,45 +2776,48 @@ /* ------------------------------ Class MPFR End ------------------------------ */ /* ------------------------------ Constants Start ------------------------------ */ - /* Version string which mpfr_get_version() returns. */ - rb_define_const(r_mpfr_class, "MPFR_VERSION", rb_str_new2(mpfr_get_version())); - /* String which mpfr_get_patches() returns. */ - rb_define_const(r_mpfr_class, "MPFR_PATCHES", rb_str_new2(mpfr_get_patches())); - /* Integer which is macro MPFR_VERSION. */ - rb_define_const(r_mpfr_class, "MPFR_VERSION2", INT2NUM(MPFR_VERSION)); - /* Integer which is macro MPFR_VERSION_MAJOR. */ + /* Integer that is macro MPFR_VERSION. */ + rb_define_const(r_mpfr_class, "MPFR_VERSION", INT2NUM(MPFR_VERSION)); + /* Integer that is macro MPFR_VERSION_MAJOR. */ rb_define_const(r_mpfr_class, "MPFR_VERSION_MAJOR", INT2NUM(MPFR_VERSION_MAJOR)); - /* Integer which is macro MPFR_VERSION_MINOR. */ + /* Integer that is macro MPFR_VERSION_MINOR. */ rb_define_const(r_mpfr_class, "MPFR_VERSION_MINOR", INT2NUM(MPFR_VERSION_MINOR)); - /* Integer which is macro MPFR_VERSION_PATCHLEVEL. */ + /* Integer that is macro MPFR_VERSION_PATCHLEVEL. */ rb_define_const(r_mpfr_class, "MPFR_VERSION_PATCHLEVEL", INT2NUM(MPFR_VERSION_PATCHLEVEL)); - /* String whichi is macro MPFR_VERSION_STRING. */ + /* String that is macro MPFR_VERSION_STRING. */ rb_define_const(r_mpfr_class, "MPFR_VERSION_STRING", rb_str_new2(MPFR_VERSION_STRING)); - /* Integer which is macro MPFR_PREC_MAX. */ + /* Integer that is macro MPFR_PREC_MAX. */ rb_define_const(r_mpfr_class, "PREC_MAX", INT2NUM(MPFR_PREC_MAX)); - /* Integer which is macro MPFR_PREC_MIN. */ + /* Integer that is macro MPFR_PREC_MIN. */ rb_define_const(r_mpfr_class, "PREC_MIN", INT2NUM(MPFR_PREC_MIN)); - /* Integer which is macro MPFR_EMAX_DEFAULT. */ + /* Integer that is macro MPFR_EMAX_DEFAULT. */ rb_define_const(r_mpfr_class, "EMAX_DEFAULT", INT2NUM(MPFR_EMAX_DEFAULT)); /* Integer whichi is MPFR_EMIN_DEFAULT. */ rb_define_const(r_mpfr_class, "EMIN_DEFAULT", INT2NUM(MPFR_EMIN_DEFAULT)); - /* Integer which is macro GMP_RNDN. */ - rb_define_const(r_mpfr_class, "RNDN", INT2NUM(GMP_RNDN)); - /* Integer which is macro GMP_RNDZ. */ - rb_define_const(r_mpfr_class, "RNDZ", INT2NUM(GMP_RNDZ)); - /* Integer which is macro GMP_RNDU. */ - rb_define_const(r_mpfr_class, "RNDU", INT2NUM(GMP_RNDU)); - /* Integer which is macro GMP_RNDD. */ - rb_define_const(r_mpfr_class, "RNDD", INT2NUM(GMP_RNDD)); + /* Integer that is macro MPFR_RNDN. */ + rb_define_const(r_mpfr_class, "RNDN", INT2NUM(MPFR_RNDN)); + /* Integer that is macro MPFR_RNDZ. */ + rb_define_const(r_mpfr_class, "RNDZ", INT2NUM(MPFR_RNDZ)); + /* Integer that is macro MPFR_RNDU. */ + rb_define_const(r_mpfr_class, "RNDU", INT2NUM(MPFR_RNDU)); + /* Integer that is macro MPFR_RNDD. */ + rb_define_const(r_mpfr_class, "RNDD", INT2NUM(MPFR_RNDD)); + /* Integer that is macro MPFR_RNDD. */ + rb_define_const(r_mpfr_class, "RNDA", INT2NUM(MPFR_RNDA)); /* ------------------------------ Constants End ------------------------------ */ + rb_define_singleton_method(r_mpfr_class, "get_version", r_mpfr_get_version, 0); + rb_define_singleton_method(r_mpfr_class, "get_patches", r_mpfr_get_patches, 0); + rb_define_singleton_method(r_mpfr_class, "buildopt_tls?", r_mpfr_buildopt_tls_p, 0); + rb_define_singleton_method(r_mpfr_class, "buildopt_decimal?", r_mpfr_buildopt_decimal_p, 0); + /* ------------------------------ Precision and Rounding Mode Start ------------------------------ */ rb_define_singleton_method(r_mpfr_class, "set_default_prec", r_mpfr_set_default_prec, 1); rb_define_singleton_method(r_mpfr_class, "get_default_prec", r_mpfr_get_default_prec, 0); rb_define_singleton_method(r_mpfr_class, "set_default_rounding_mode", r_mpfr_set_default_rounding_mode, 1); @@ -2618,10 +2864,11 @@ rb_define_private_method(r_mpfr_class, "initialize", r_mpfr_initialize, -1); rb_define_private_method(r_mpfr_class, "initialize_copy", r_mpfr_initialize_copy, 1); rb_define_method(r_mpfr_class, "coerce", r_mpfr_coerce, 1); rb_define_singleton_method(r_mpfr_class, "nan", r_mpfr_nan, -1); + rb_define_singleton_method(r_mpfr_class, "zero", r_mpfr_zero, -1); rb_define_singleton_method(r_mpfr_class, "pinf", r_mpfr_pinf, -1); rb_define_singleton_method(r_mpfr_class, "minf", r_mpfr_minf, -1); /* ------------------------------ MPFR allocation End ------------------------------ */ @@ -2631,19 +2878,23 @@ rb_define_method(r_mpfr_class, "get_prec", r_mpfr_get_prec, 0); rb_define_method(r_mpfr_class, "set", r_mpfr_set, -1); rb_define_method(r_mpfr_class, "set_fixnum_2exp", r_mpfr_set_fixnum_2exp, -1); rb_define_method(r_mpfr_class, "set_inf", r_mpfr_set_inf, 1); rb_define_method(r_mpfr_class, "set_nan", r_mpfr_set_nan, 0); + rb_define_method(r_mpfr_class, "set_zero", r_mpfr_set_zero, -1); rb_define_method(r_mpfr_class, "swap", r_mpfr_swap, 1); /* ------------------------------ Assignment Functions End ------------------------------ */ /* ------------------------------ Methods related to string Start ------------------------------ */ rb_define_method(r_mpfr_class, "to_strf", r_mpfr_to_strf, 1); rb_define_method(r_mpfr_class, "to_s", r_mpfr_to_s, 0); rb_define_method(r_mpfr_class, "inspect", r_mpfr_inspect, 0); + + rb_define_method(r_mpfr_class, "marshal_dump", r_mpfr_marshal_dump, 0); + rb_define_method(r_mpfr_class, "marshal_load", r_mpfr_marshal_load, 1); /* ------------------------------ Methods related to string End ------------------------------ */ /* ------------------------------ Conversion functions Start ------------------------------ */ rb_define_method(r_mpfr_class, "get_d", r_mpfr_get_d, -1); @@ -2697,20 +2948,21 @@ rb_define_alias(r_mpfr_class, "<=>", "cmp"); rb_define_alias(r_mpfr_class, "nan?", "nan_p"); rb_define_alias(r_mpfr_class, "finite?", "number_p"); rb_define_alias(r_mpfr_class, "zero?", "zero_p"); rb_define_method(r_mpfr_class, "nonzero?", r_mpfr_nonzero_p, 1); + rb_define_method(r_mpfr_class, "regular?", r_mpfr_regular_p, 1); /* ------------------------------ Comparison Functions Start ------------------------------ */ /* ------------------------------ Integer Related Functions Start ------------------------------ */ - rb_define_method(r_mpfr_class, "m_rint", r_mpfr_m_rint, -1); - rb_define_method(r_mpfr_class, "m_ceil", r_mpfr_m_ceil, -1); - rb_define_method(r_mpfr_class, "m_floor", r_mpfr_m_floor, -1); - rb_define_method(r_mpfr_class, "m_round", r_mpfr_m_round, -1); - rb_define_method(r_mpfr_class, "m_trunc", r_mpfr_m_trunc, -1); + rb_define_method(r_mpfr_class, "fr_rint", r_mpfr_fr_rint, -1); + rb_define_method(r_mpfr_class, "fr_ceil", r_mpfr_fr_ceil, -1); + rb_define_method(r_mpfr_class, "fr_floor", r_mpfr_fr_floor, -1); + rb_define_method(r_mpfr_class, "fr_round", r_mpfr_fr_round, -1); + rb_define_method(r_mpfr_class, "fr_trunc", r_mpfr_fr_trunc, -1); rb_define_method(r_mpfr_class, "rint_ceil", r_mpfr_rint_ceil, -1); rb_define_method(r_mpfr_class, "rint_floor", r_mpfr_rint_floor, -1); rb_define_method(r_mpfr_class, "rint_round", r_mpfr_rint_round, -1); rb_define_method(r_mpfr_class, "rint_trunc", r_mpfr_rint_trunc, -1); rb_define_method(r_mpfr_class, "frac", r_mpfr_frac, -1); @@ -2741,10 +2993,12 @@ /* ------------------------------ Rounding Mode Related Functions Start ------------------------------ */ rb_define_method(r_mpfr_class, "prec_round", r_mpfr_prec_round, -1); rb_define_method(r_mpfr_class, "prec_round!", r_mpfr_prec_round2, -1); + rb_define_method(r_mpfr_class, "can_round", r_mpfr_can_round, 4); + rb_define_method(r_mpfr_class, "min_prec", r_mpfr_min_prec, 0); /* ------------------------------ Rounding Mode Related Functions End ------------------------------ */ /* ------------------------------ Module MPFR::Math Start ------------------------------ */ @@ -2811,10 +3065,13 @@ rb_define_module_function(r_mpfr_math, "atan2", r_mpfr_math_atan2, -1); rb_define_module_function(r_mpfr_math, "cosh", r_mpfr_math_cosh, -1); rb_define_module_function(r_mpfr_math, "sinh", r_mpfr_math_sinh, -1); rb_define_module_function(r_mpfr_math, "tanh", r_mpfr_math_tanh, -1); rb_define_module_function(r_mpfr_math, "sinh_cosh", r_mpfr_math_sinh_cosh, -1); + rb_define_module_function(r_mpfr_math, "sech", r_mpfr_math_sech, -1); + rb_define_module_function(r_mpfr_math, "csch", r_mpfr_math_csch, -1); + rb_define_module_function(r_mpfr_math, "coth", r_mpfr_math_coth, -1); rb_define_module_function(r_mpfr_math, "acosh", r_mpfr_math_acosh, -1); rb_define_module_function(r_mpfr_math, "asinh", r_mpfr_math_asinh, -1); rb_define_module_function(r_mpfr_math, "atanh", r_mpfr_math_atanh, -1); rb_define_module_function(r_mpfr_math, "fac_ui", r_mpfr_math_fac_ui, -1); rb_define_module_function(r_mpfr_math, "log1p", r_mpfr_math_log1p, -1); @@ -2822,10 +3079,11 @@ rb_define_module_function(r_mpfr_math, "eint", r_mpfr_math_eint, -1); rb_define_module_function(r_mpfr_math, "li2", r_mpfr_math_li2, -1); rb_define_module_function(r_mpfr_math, "gamma", r_mpfr_math_gamma, -1); rb_define_module_function(r_mpfr_math, "lngamma", r_mpfr_math_lngamma, -1); rb_define_module_function(r_mpfr_math, "lgamma", r_mpfr_math_lgamma, -1); + rb_define_module_function(r_mpfr_math, "digamma", r_mpfr_math_digamma, -1); rb_define_module_function(r_mpfr_math, "zeta", r_mpfr_math_zeta, -1); rb_define_module_function(r_mpfr_math, "erf", r_mpfr_math_erf, -1); rb_define_module_function(r_mpfr_math, "erfc", r_mpfr_math_erfc, -1); rb_define_module_function(r_mpfr_math, "j0", r_mpfr_math_j0, -1); rb_define_module_function(r_mpfr_math, "j1", r_mpfr_math_j1, -1); @@ -2835,10 +3093,11 @@ rb_define_module_function(r_mpfr_math, "yn", r_mpfr_math_yn, -1); rb_define_module_function(r_mpfr_math, "fma", r_mpfr_math_fma, -1); rb_define_module_function(r_mpfr_math, "fms", r_mpfr_math_fms, -1); rb_define_module_function(r_mpfr_math, "agm", r_mpfr_math_agm, -1); rb_define_module_function(r_mpfr_math, "hypot", r_mpfr_math_hypot, -1); + rb_define_module_function(r_mpfr_math, "ai", r_mpfr_math_ai, -1); rb_define_module_function(r_mpfr_math, "const_log2", r_mpfr_math_const_log2, -1); rb_define_module_function(r_mpfr_math, "const_pi", r_mpfr_math_const_pi, -1); rb_define_module_function(r_mpfr_math, "const_euler", r_mpfr_math_const_euler, -1); rb_define_module_function(r_mpfr_math, "const_catalan", r_mpfr_math_const_catalan, -1); rb_define_module_function(r_mpfr_math, "free_cache", r_mpfr_math_free_cache, 0); @@ -2865,5 +3124,6 @@ __mpfr_class__ = rb_eval_string("MPFR"); __sym_to_s__ = rb_eval_string(":to_s"); __sym_to_str__ = rb_eval_string(":to_str"); } +