Class: MPFR
- Inherits:
-
Numeric
- Object
- Numeric
- MPFR
- Includes:
- Comparable
- Defined in:
- lib/mpfr/rspec.rb,
lib/mpfr/matrix.rb,
lib/mpfr/version.rb,
ext/mpfr/ruby_mpfr.c,
ext/mpfr_matrix/mpfr/ruby_mpfr_matrix.c
Defined Under Namespace
Modules: Math, Vector Classes: ColumnVector, Matrix, RowVector, SquareMatrix
Constant Summary collapse
- VERSION =
'0.0.17'
- MPFR_VERSION =
Integer that is macro MPFR_VERSION.
INT2NUM(MPFR_VERSION)
- MPFR_VERSION_MAJOR =
Integer that is macro MPFR_VERSION_MAJOR.
INT2NUM(MPFR_VERSION_MAJOR)
- MPFR_VERSION_MINOR =
Integer that is macro MPFR_VERSION_MINOR.
INT2NUM(MPFR_VERSION_MINOR)
- MPFR_VERSION_PATCHLEVEL =
Integer that is macro MPFR_VERSION_PATCHLEVEL.
INT2NUM(MPFR_VERSION_PATCHLEVEL)
- MPFR_VERSION_STRING =
String that is macro MPFR_VERSION_STRING.
rb_str_new2(MPFR_VERSION_STRING)
- PREC_MAX =
Integer that is macro MPFR_PREC_MAX.
INT2NUM(MPFR_PREC_MAX)
- PREC_MIN =
Integer that is macro MPFR_PREC_MIN.
INT2NUM(MPFR_PREC_MIN)
- EMAX_DEFAULT =
Integer that is macro MPFR_EMAX_DEFAULT.
INT2NUM(MPFR_EMAX_DEFAULT)
- EMIN_DEFAULT =
Integer whichi is MPFR_EMIN_DEFAULT.
INT2NUM(MPFR_EMIN_DEFAULT)
- RNDN =
Integer that is macro MPFR_RNDN.
ID2SYM(id_rndn)
- RNDZ =
Integer that is macro MPFR_RNDZ.
ID2SYM(id_rndz)
- RNDU =
Integer that is macro MPFR_RNDU.
ID2SYM(id_rndu)
- RNDD =
Integer that is macro MPFR_RNDD.
ID2SYM(id_rndd)
- RNDA =
Integer that is macro MPFR_RNDD.
ID2SYM(id_rnda)
- @@error =
MPFR('1e-12')
Class Method Summary collapse
-
.buildopt_decimal? ⇒ Boolean
Return true if MPFR was compiled with decimal float support.
-
.buildopt_tls? ⇒ Boolean
Return true if MPFR was compiled as thread safe using compiler-level Thread Local Storage.
-
.clear_erangeflag ⇒ Object
Execute mpfr_clear_erangeflag() and return nil.
-
.clear_flags ⇒ Object
Execute mpfr_clear_flags() and return nil.
-
.clear_inexflag ⇒ Object
Execute mpfr_clear_inexflag() and return nil.
-
.clear_nanflag ⇒ Object
Execute mpfr_clear_nanflag() and return nil.
-
.clear_overflow ⇒ Object
Execute mpfr_clear_overflow() and return nil.
-
.clear_underflow ⇒ Object
Execute mpfr_clear_underflow() and return nil.
-
.ColumnVector(arg) ⇒ Object
Return new MPFR::ColumnVector instance.
-
.erangeflag_p ⇒ Object
If erange flag is set, this method returns true.
-
.get_default_prec ⇒ Object
Return the default MPFR precision in bits.
-
.get_default_rounding_mode ⇒ Object
Get the default rounding mode.
-
.get_emax ⇒ Object
Return integer which is mpfr_get_emax().
-
.get_emax_max ⇒ Object
Return integer which is mpfr_get_emax_max().
-
.get_emax_min ⇒ Object
Return integer which is mpfr_get_emax_min().
-
.get_emin ⇒ Object
Return integer which is mpfr_get_emin().
-
.get_emin_max ⇒ Object
Return integer which is mpfr_get_emin_max().
-
.get_emin_min ⇒ Object
Return integer which is mpfr_get_emin_min().
- .get_error_of_test ⇒ Object
-
.get_patches ⇒ Object
String which mpfr_get_patches() returns.
-
.get_version ⇒ Object
Version string which mpfr_get_version() returns.
-
.inexflag_p ⇒ Object
If inexact flag is set, this method returns true.
-
.Matrix(*args) ⇒ Object
Return new MPFR::Matrix instance.
-
.minf(*args) ⇒ Object
Return minus infinity.
-
.nan(*args) ⇒ Object
Return NaN.
-
.nanflag_p ⇒ Object
If invalid flag is set, this method returns true.
-
.overflow_p ⇒ Object
If owerflow flag is set, this method returns true.
-
.pinf(*args) ⇒ Object
Return plus infinity.
-
.RowVector(arg) ⇒ Object
Return new MPFR::RowVector instance.
-
.set_default_prec(prec) ⇒ Object
Set the default MPFR precision in bits.
-
.set_default_rounding_mode(rnd) ⇒ Object
Set the default rounding mode.
-
.set_emax(exp) ⇒ Object
Return integer which is mpfr_set_emax( p1 ).
-
.set_emin(exp) ⇒ Object
Return integer which is mpfr_set_emin( p1 ).
-
.set_erangeflag ⇒ Object
Execute mpfr_set_erangeflag() and return nil.
- .set_error_of_test(err) ⇒ Object
-
.set_inexflag ⇒ Object
Execute mpfr_set_inexflag() and return nil.
-
.set_nanflag ⇒ Object
Execute mpfr_set_nanflag() and return nil.
-
.set_overflow ⇒ Object
Execute mpfr_set_overflow() and return nil.
-
.set_underflow ⇒ Object
Execute mpfr_set_underflow() and return nil.
-
.SquareMatrix(arg) ⇒ Object
Return new MPFR::SquareMatrix instance.
-
.underflow_p ⇒ Object
If underflow flag is set, this method returns true.
-
.zero(*args) ⇒ Object
Return zero.
Instance Method Summary collapse
-
#%(other) ⇒ Object
(also: #modulo)
mpfr_remainder(ret, self, p1, mpfr_getdefault_rounding_mode()).
-
#*(other) ⇒ Object
Return self * p1.
-
#**(other) ⇒ Object
Return p1-th power of self.
-
#+(other) ⇒ Object
Return self + p1.
-
#-(other) ⇒ Object
Return self - p1.
-
#/(other) ⇒ Object
Return self / p1.
-
#abs(*args) ⇒ Object
Return absolute value of self.
-
#can_round(err, rnd1, rnd2, prec) ⇒ Object
mpfr_can_round(self, err, rnd1, rnd2, prec).
-
#ceil ⇒ Object
Return Fixnum object which is the minimum integer over self.
- #check_error(other, error = nil) ⇒ Object
-
#check_range(*args) ⇒ Object
Execute mpfr_check_range( self, p1, rnd ) and return self.
-
#cmp(other) ⇒ Object
(also: #<=>)
Return negative integer if self < other, negative integer if self > other, or 0 if self == other.
-
#cmp_si_2exp(other, exp) ⇒ Object
mpfr_cmp_si_2exp(self, p1, p2).
-
#cmp_ui_2exp(other, exp) ⇒ Object
mpfr_cmp_ui_2exp(self, p1, p2).
-
#cmpabs(other) ⇒ Object
mpfr_cmpabs(self, p1).
-
#coerce(other) ⇒ Object
Return array which have MPFR instance converted to from p1 and self.
-
#copysign(*args) ⇒ Object
mpfr_copysign(ret, self, p1, rnd).
-
#equal_p(other) ⇒ Object
Return true if self == other, nil otherwise.
-
#floor ⇒ Object
Return Fixnum object which is the maximum integer not over self.
-
#fmod(*args) ⇒ Object
mpfr_fmod(ret, self, p1, rnd).
-
#fr_ceil(*args) ⇒ Object
mpfr_ceil(ret, self).
-
#fr_floor(*args) ⇒ Object
mpfr_floor(ret, self).
-
#fr_rint(*args) ⇒ Object
mpfr_rint(ret, self, rnd).
-
#fr_round(*args) ⇒ Object
mpfr_round(ret, self).
-
#fr_trunc(*args) ⇒ Object
mpfr_trunc(ret, self).
-
#frac(*args) ⇒ Object
mpfr_frac(ret, self, rnd).
-
#get_d(*args) ⇒ Object
(also: #to_f)
Return Float object by converting self.
-
#get_d_2exp(*args) ⇒ Object
d times 2 raised to exp equals self rounded to double precision.
-
#get_exp ⇒ Object
If self is not number, return nil.
-
#get_prec ⇒ Object
Return precision actually used for assignments of self.
-
#get_str ⇒ Object
Return array having String object meaning mantissa and Fixnum object meaning exponent.
- #get_z_2exp ⇒ Object
-
#greater_p(other) ⇒ Object
Return true if self > other, nil otherwise.
-
#greaterequal_p(other) ⇒ Object
Return true if self >= other, nil otherwise.
-
#inf_p ⇒ Object
Return true if self is infinity, nil otherwise.
-
#infinite? ⇒ Boolean
Return 1 if self is plus infinity, -1 if minus infinity.
-
#inspect ⇒ Object
Output for debugging.
-
#integer_p ⇒ Object
(also: #integer?)
If value of self is integer, return true.
-
#less_p(other) ⇒ Object
Return true if self < other, nil otherwise.
-
#lessequal_p(other) ⇒ Object
Return true if self <= other, nil otherwise.
-
#lessgreater_p(other) ⇒ Object
Return true if self < other or self > other, nil otherwise.
- #marshal_dump ⇒ Object
- #marshal_load(dump_string) ⇒ Object
-
#min_prec ⇒ Object
mpfr_min_prec(self).
-
#modf(*args) ⇒ Object
Return [ret1, ret2] such that mpfr_modf(ret1, ret2, self, rnd).
-
#nan_p ⇒ Object
(also: #nan?)
Return true if self is NaN, nil otherwise.
-
#neg(*args) ⇒ Object
Return negative value of self.
-
#nextabove ⇒ Object
mpfr_nextabove(self).
-
#nextbelow ⇒ Object
mpfr_nextbelow(self).
-
#nexttoward(other) ⇒ Object
mpfr_nexttoward(self, p1).
-
#nonzero? ⇒ Boolean
Return true if self is non zero, nil otherwise.
-
#number_p ⇒ Object
(also: #finite?)
Return true if self is number, nil otherwise.
-
#prec_round(*args) ⇒ Object
mpfr_prec_round(ret, prec, rnd).
-
#prec_round!(*args) ⇒ Object
mpfr_prec_round(self, prec, rnd).
-
#regular? ⇒ Boolean
Return true if self is regular number, nil otherwise.
-
#remainder(*args) ⇒ Object
mpfr_remainder(ret, self, p1, rnd).
-
#remquo(*args) ⇒ Object
mpfr_remquo(ret1, ret2, self, p1, rnd).
-
#rint_ceil(*args) ⇒ Object
mpfr_rint_ceil(ret, self, rnd).
-
#rint_floor(*args) ⇒ Object
mpfr_rint_floor(ret, self, rnd).
-
#rint_round(*args) ⇒ Object
mpfr_rint_round(ret, self, rnd).
-
#rint_trunc(*args) ⇒ Object
mpfr_rint_trunc(ret, self, rnd).
-
#round ⇒ Object
Return Fixnum object which is nearest integer to self.
-
#set(*args) ⇒ Object
Arguments are val, rnd, and prec.
-
#set_exp(arg_exp) ⇒ Object
arg_exp is integer and we execute mpfr_set_exp(self, arg_exp).
-
#set_fixnum_2exp(*args) ⇒ Object
Arguments are num, exp, rnd, and prec.
-
#set_inf(sign) ⇒ Object
If p1 is nonnegative Fixnum, set the value of self to plus Inf.
-
#set_nan ⇒ Object
Set the value of self to NaN.
-
#set_prec(prec) ⇒ Object
Reset the precision of self to be exactly p1 bits and set its value to NaN.
-
#set_zero(*args) ⇒ Object
Set the value of self to zero.
-
#setsign(*args) ⇒ Object
mpfr_setsign(ret, self, p1, rnd).
-
#sgn ⇒ Object
mpfr_sgn(self).
-
#signbit ⇒ Object
Return integer which is mpfr_signbit(self).
-
#subnormalize(*args) ⇒ Object
Execute mpfr_subnormalize( self, p1, rnd ) and return self.
-
#swap(other) ⇒ Object
Swap the values self and p1 efficiently.
- #to_mpf(*args) ⇒ Object
- #to_mpz(*args) ⇒ Object
-
#to_s ⇒ Object
Convert to string.
-
#to_strf(format_str) ⇒ Object
Output self by mpfr_asprintf( some_val, p1, self ).
-
#truncate ⇒ Object
(also: #to_i, #to_int)
Return Fixnum object by truncating self.
-
#unordered_p(other) ⇒ Object
Return true if self or other is a NaN, nil otherwise.
-
#zero_p ⇒ Object
(also: #zero?)
Return true if self is 0, nil otherwise.
Class Method Details
.buildopt_decimal? ⇒ Boolean
Return true if MPFR was compiled with decimal float support. Otherwise, nil.
2912 2913 2914 2915 |
# File 'ext/mpfr/ruby_mpfr.c', line 2912
static VALUE r_mpfr_buildopt_decimal_p(VALUE self)
{
return mpfr_buildopt_decimal_p() == 0 ? Qnil : Qtrue;
}
|
.buildopt_tls? ⇒ Boolean
Return true if MPFR was compiled as thread safe using compiler-level Thread Local Storage. Otherwise, nil.
2906 2907 2908 2909 |
# File 'ext/mpfr/ruby_mpfr.c', line 2906
static VALUE r_mpfr_buildopt_tls_p(VALUE self)
{
return mpfr_buildopt_tls_p() == 0 ? Qnil : Qtrue;
}
|
.clear_erangeflag ⇒ Object
Execute mpfr_clear_erangeflag() and return nil.
244 245 246 247 248 |
# File 'ext/mpfr/ruby_mpfr.c', line 244
static VALUE r_mpfr_clear_erangeflag(VALUE self)
{
mpfr_clear_erangeflag();
return Qnil;
}
|
.clear_flags ⇒ Object
Execute mpfr_clear_flags() and return nil.
286 287 288 289 290 |
# File 'ext/mpfr/ruby_mpfr.c', line 286
static VALUE r_mpfr_clear_flags(VALUE self)
{
mpfr_clear_flags();
return Qnil;
}
|
.clear_inexflag ⇒ Object
Execute mpfr_clear_inexflag() and return nil.
237 238 239 240 241 |
# File 'ext/mpfr/ruby_mpfr.c', line 237
static VALUE r_mpfr_clear_inexflag(VALUE self)
{
mpfr_clear_inexflag();
return Qnil;
}
|
.clear_nanflag ⇒ Object
Execute mpfr_clear_nanflag() and return nil.
230 231 232 233 234 |
# File 'ext/mpfr/ruby_mpfr.c', line 230
static VALUE r_mpfr_clear_nanflag(VALUE self)
{
mpfr_clear_nanflag();
return Qnil;
}
|
.clear_overflow ⇒ Object
Execute mpfr_clear_overflow() and return nil.
223 224 225 226 227 |
# File 'ext/mpfr/ruby_mpfr.c', line 223
static VALUE r_mpfr_clear_overflow(VALUE self)
{
mpfr_clear_overflow();
return Qnil;
}
|
.clear_underflow ⇒ Object
Execute mpfr_clear_underflow() and return nil.
216 217 218 219 220 |
# File 'ext/mpfr/ruby_mpfr.c', line 216
static VALUE r_mpfr_clear_underflow(VALUE self)
{
mpfr_clear_underflow();
return Qnil;
}
|
.ColumnVector(arg) ⇒ Object
Return new MPFR::ColumnVector instance. The same arguments as MPFR::ColumnVector.new is acceptable.
270 271 272 273 274 275 276 277 |
# File 'ext/mpfr_matrix/mpfr/ruby_mpfr_matrix.c', line 270
static VALUE r_mpfr_col_vector_global_new(VALUE self, VALUE arg)
{
MPFRMatrix *ptr;
VALUE val;
r_mpfr_make_col_vector_struct(val, ptr);
r_mpfr_col_vector_set_initial_value(ptr, arg);
return val;
}
|
.erangeflag_p ⇒ Object
If erange flag is set, this method returns true. Otherwise nil.
317 318 319 320 |
# File 'ext/mpfr/ruby_mpfr.c', line 317
static VALUE r_mpfr_erangeflag_p(VALUE self)
{
return (mpfr_erangeflag_p() != 0 ? Qtrue : Qfalse);
}
|
.get_default_prec ⇒ Object
Return the default MPFR precision in bits.
119 120 121 122 |
# File 'ext/mpfr/ruby_mpfr.c', line 119
static VALUE r_mpfr_get_default_prec(VALUE self)
{
return INT2NUM((int)mpfr_get_default_prec());
}
|
.get_default_rounding_mode ⇒ Object
Get the default rounding mode.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'ext/mpfr/ruby_mpfr.c', line 143
static VALUE r_mpfr_get_default_rounding_mode(VALUE self)
{
switch (mpfr_get_default_rounding_mode()) {
case MPFR_RNDN:
return ID2SYM(id_rndn);
case MPFR_RNDZ:
return ID2SYM(id_rndz);
case MPFR_RNDU:
return ID2SYM(id_rndu);
case MPFR_RNDD:
return ID2SYM(id_rndd);
case MPFR_RNDA:
return ID2SYM(id_rnda);
case MPFR_RNDF:
case MPFR_RNDNA:
rb_raise(rb_eStandardError, "Unsupported rounding mode.");
}
rb_raise(rb_eStandardError, "Invalid rounding mode.");
}
|
.get_emax ⇒ Object
Return integer which is mpfr_get_emax().
174 175 176 177 |
# File 'ext/mpfr/ruby_mpfr.c', line 174
static VALUE r_mpfr_get_emax(VALUE self)
{
return INT2NUM(mpfr_get_emax());
}
|
.get_emax_max ⇒ Object
Return integer which is mpfr_get_emax_max().
210 211 212 213 |
# File 'ext/mpfr/ruby_mpfr.c', line 210
static VALUE r_mpfr_get_emax_max(VALUE self)
{
return INT2NUM(mpfr_get_emax_max());
}
|
.get_emax_min ⇒ Object
Return integer which is mpfr_get_emax_min().
204 205 206 207 |
# File 'ext/mpfr/ruby_mpfr.c', line 204
static VALUE r_mpfr_get_emax_min(VALUE self)
{
return INT2NUM(mpfr_get_emax_min());
}
|
.get_emin ⇒ Object
Return integer which is mpfr_get_emin().
168 169 170 171 |
# File 'ext/mpfr/ruby_mpfr.c', line 168
static VALUE r_mpfr_get_emin(VALUE self)
{
return INT2NUM(mpfr_get_emin());
}
|
.get_emin_max ⇒ Object
Return integer which is mpfr_get_emin_max().
198 199 200 201 |
# File 'ext/mpfr/ruby_mpfr.c', line 198
static VALUE r_mpfr_get_emin_max(VALUE self)
{
return INT2NUM(mpfr_get_emin_max());
}
|
.get_emin_min ⇒ Object
Return integer which is mpfr_get_emin_min().
192 193 194 195 |
# File 'ext/mpfr/ruby_mpfr.c', line 192
static VALUE r_mpfr_get_emin_min(VALUE self)
{
return INT2NUM(mpfr_get_emin_min());
}
|
.get_error_of_test ⇒ Object
8 9 10 |
# File 'lib/mpfr/rspec.rb', line 8 def self.get_error_of_test @error end |
.get_patches ⇒ Object
String which mpfr_get_patches() returns.
2900 2901 2902 2903 |
# File 'ext/mpfr/ruby_mpfr.c', line 2900
static VALUE r_mpfr_get_patches(VALUE self)
{
return rb_str_new2(mpfr_get_patches());
}
|
.get_version ⇒ Object
Version string which mpfr_get_version() returns.
2894 2895 2896 2897 |
# File 'ext/mpfr/ruby_mpfr.c', line 2894
static VALUE r_mpfr_get_version(VALUE self)
{
return rb_str_new2(mpfr_get_version());
}
|
.inexflag_p ⇒ Object
If inexact flag is set, this method returns true. Otherwise nil.
311 312 313 314 |
# File 'ext/mpfr/ruby_mpfr.c', line 311
static VALUE r_mpfr_inexflag_p(VALUE self)
{
return (mpfr_inexflag_p() != 0 ? Qtrue : Qfalse);
}
|
.Matrix(*args) ⇒ Object
Return new MPFR::Matrix instance. The same arguments as MPFR::Matrix.new is acceptable.
99 100 101 102 103 104 105 106 |
# File 'ext/mpfr_matrix/mpfr/ruby_mpfr_matrix.c', line 99
static VALUE r_mpfr_matrix_global_new(int argc, VALUE *argv, VALUE self)
{
MPFRMatrix *ptr;
VALUE val;
r_mpfr_make_matrix_struct(val, ptr);
r_mpfr_matrix_set_initial_value(ptr, argc, argv);
return val;
}
|
.minf(*args) ⇒ Object
Return minus infinity. This method takes one optional argument meaning precision.
608 609 610 611 612 613 614 615 616 |
# File 'ext/mpfr/ruby_mpfr.c', line 608
static VALUE r_mpfr_minf(int argc, VALUE *argv, VALUE self)
{
mp_prec_t prec = r_mpfr_prec_from_optional_argument(0, 1, argc, argv);
MPFR *ptr_return;
VALUE val_ret;
r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
mpfr_set_inf(ptr_return, -1);
return val_ret;
}
|
.nan(*args) ⇒ Object
Return NaN. This method takes one optional argument meaning precision.
571 572 573 574 575 576 577 578 579 |
# File 'ext/mpfr/ruby_mpfr.c', line 571
static VALUE r_mpfr_nan(int argc, VALUE *argv, VALUE self)
{
mp_prec_t prec = r_mpfr_prec_from_optional_argument(0, 1, argc, argv);
MPFR *ptr_return;
VALUE val_ret;
r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
mpfr_set_nan(ptr_return);
return val_ret;
}
|
.nanflag_p ⇒ Object
If invalid flag is set, this method returns true. Otherwise nil.
305 306 307 308 |
# File 'ext/mpfr/ruby_mpfr.c', line 305
static VALUE r_mpfr_nanflag_p(VALUE self)
{
return (mpfr_nanflag_p() != 0 ? Qtrue : Qfalse);
}
|
.overflow_p ⇒ Object
If owerflow flag is set, this method returns true. Otherwise nil.
299 300 301 302 |
# File 'ext/mpfr/ruby_mpfr.c', line 299
static VALUE r_mpfr_overflow_p(VALUE self)
{
return (mpfr_overflow_p() != 0 ? Qtrue : Qfalse);
}
|
.pinf(*args) ⇒ Object
Return plus infinity. This method takes one optional argument meaning precision.
597 598 599 600 601 602 603 604 605 |
# File 'ext/mpfr/ruby_mpfr.c', line 597
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;
VALUE val_ret;
r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
mpfr_set_inf(ptr_return, 1);
return val_ret;
}
|
.RowVector(arg) ⇒ Object
Return new MPFR::RowVector instance. The same arguments as MPFR::RowVector.new is acceptable.
321 322 323 324 325 326 327 328 |
# File 'ext/mpfr_matrix/mpfr/ruby_mpfr_matrix.c', line 321
static VALUE r_mpfr_row_vector_global_new(int argc, VALUE arg)
{
MPFRMatrix *ptr;
VALUE val;
r_mpfr_make_row_vector_struct(val, ptr);
r_mpfr_row_vector_set_initial_value(ptr, arg);
return val;
}
|
.set_default_prec(prec) ⇒ Object
Set the default MPFR precision in bits.
108 109 110 111 112 113 114 115 116 |
# File 'ext/mpfr/ruby_mpfr.c', line 108
static VALUE r_mpfr_set_default_prec(VALUE self, VALUE prec)
{
int set_prec = NUM2INT(prec);
if(set_prec <= 0){
rb_raise(rb_eRangeError, "Argument must be positive.");
}
mpfr_set_default_prec(set_prec);
return INT2FIX(mpfr_get_default_prec());
}
|
.set_default_rounding_mode(rnd) ⇒ Object
Set the default rounding mode. The default rounding mode is MPFR::RNDN.
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'ext/mpfr/ruby_mpfr.c', line 125
static VALUE r_mpfr_set_default_rounding_mode(VALUE self, VALUE rnd)
{
ID rnd_id = SYM2ID(rnd);
if (rnd_id == id_rndn) {
mpfr_set_default_rounding_mode(MPFR_RNDN);
} else if (rnd_id == id_rndz) {
mpfr_set_default_rounding_mode(MPFR_RNDZ);
} else if (rnd_id == id_rndu) {
mpfr_set_default_rounding_mode(MPFR_RNDU);
} else if (rnd_id == id_rndd) {
mpfr_set_default_rounding_mode(MPFR_RNDD);
} else if (rnd_id == id_rnda) {
mpfr_set_default_rounding_mode(MPFR_RNDA);
}
return rnd;
}
|
.set_emax(exp) ⇒ Object
Return integer which is mpfr_set_emax( p1 ).
186 187 188 189 |
# File 'ext/mpfr/ruby_mpfr.c', line 186
static VALUE r_mpfr_set_emax(VALUE self, VALUE exp)
{
return INT2NUM(mpfr_set_emax(NUM2INT(exp)));
}
|
.set_emin(exp) ⇒ Object
Return integer which is mpfr_set_emin( p1 ).
180 181 182 183 |
# File 'ext/mpfr/ruby_mpfr.c', line 180
static VALUE r_mpfr_set_emin(VALUE self, VALUE exp)
{
return INT2NUM(mpfr_set_emin(NUM2INT(exp)));
}
|
.set_erangeflag ⇒ Object
Execute mpfr_set_erangeflag() and return nil.
279 280 281 282 283 |
# File 'ext/mpfr/ruby_mpfr.c', line 279
static VALUE r_mpfr_set_erangeflag(VALUE self)
{
mpfr_set_erangeflag();
return Qnil;
}
|
.set_error_of_test(err) ⇒ Object
4 5 6 |
# File 'lib/mpfr/rspec.rb', line 4 def self.set_error_of_test(err) @error = err end |
.set_inexflag ⇒ Object
Execute mpfr_set_inexflag() and return nil.
272 273 274 275 276 |
# File 'ext/mpfr/ruby_mpfr.c', line 272
static VALUE r_mpfr_set_inexflag(VALUE self)
{
mpfr_set_inexflag();
return Qnil;
}
|
.set_nanflag ⇒ Object
Execute mpfr_set_nanflag() and return nil.
265 266 267 268 269 |
# File 'ext/mpfr/ruby_mpfr.c', line 265
static VALUE r_mpfr_set_nanflag(VALUE self)
{
mpfr_set_nanflag();
return Qnil;
}
|
.set_overflow ⇒ Object
Execute mpfr_set_overflow() and return nil.
258 259 260 261 262 |
# File 'ext/mpfr/ruby_mpfr.c', line 258
static VALUE r_mpfr_set_overflow(VALUE self)
{
mpfr_set_overflow();
return Qnil;
}
|
.set_underflow ⇒ Object
Execute mpfr_set_underflow() and return nil.
251 252 253 254 255 |
# File 'ext/mpfr/ruby_mpfr.c', line 251
static VALUE r_mpfr_set_underflow(VALUE self)
{
mpfr_set_underflow();
return Qnil;
}
|
.SquareMatrix(arg) ⇒ Object
Return new MPFR::SquareMatrix instance. The same arguments as MPFR::SquareMatrix.new is acceptable.
166 167 168 169 170 171 172 173 |
# File 'ext/mpfr_matrix/mpfr/ruby_mpfr_matrix.c', line 166
static VALUE r_mpfr_square_matrix_global_new(int argc, VALUE arg)
{
MPFRMatrix *ptr;
VALUE val;
r_mpfr_make_square_matrix_struct(val, ptr);
r_mpfr_square_matrix_set_initial_value(ptr, arg);
return val;
}
|
.underflow_p ⇒ Object
If underflow flag is set, this method returns true. Otherwise nil.
293 294 295 296 |
# File 'ext/mpfr/ruby_mpfr.c', line 293
static VALUE r_mpfr_underflow_p(VALUE self)
{
return (mpfr_underflow_p() != 0 ? Qtrue : Qfalse);
}
|
.zero(*args) ⇒ Object
Return zero. This method takes one optional argument meaning precision.
582 583 584 585 586 587 588 589 590 591 592 593 594 |
# File 'ext/mpfr/ruby_mpfr.c', line 582
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;
}
|
Instance Method Details
#%(other) ⇒ Object Also known as: modulo
mpfr_remainder(ret, self, p1, mpfr_getdefault_rounding_mode())
1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 |
# File 'ext/mpfr/ruby_mpfr.c', line 1733
static VALUE r_mpfr_remainder2(VALUE self, VALUE other)
{
MPFR *ptr_self, *ptr_other, *ptr_return;
volatile VALUE tmp_other;
VALUE val_ret;
r_mpfr_get_struct(ptr_self, self);
r_mpfr_make_struct_init(val_ret, ptr_return);
tmp_other = r_mpfr_new_fr_obj(other);
r_mpfr_get_struct(ptr_other, tmp_other);
mpfr_remainder(ptr_return, ptr_self, ptr_other, mpfr_get_default_rounding_mode());
return val_ret;
}
|
#*(other) ⇒ Object
Return self * p1.
962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 |
# File 'ext/mpfr/ruby_mpfr.c', line 962
static VALUE r_mpfr_mul(VALUE self, VALUE other)
{
MPFR *ptr_self, *ptr_other, *ptr_return;
VALUE val_ret;
r_mpfr_get_struct(ptr_self, self);
r_mpfr_make_struct_init(val_ret, ptr_return);
if(MPFR_P(other)){
r_mpfr_get_struct(ptr_other, other);
mpfr_mul(ptr_return, ptr_self, ptr_other, mpfr_get_default_rounding_mode());
}else if(TYPE(other) == T_FIXNUM){
mpfr_mul_si(ptr_return, ptr_self, FIX2LONG(other), mpfr_get_default_rounding_mode());
}else if(TYPE(other) == T_FLOAT){
mpfr_mul_d(ptr_return, ptr_self, NUM2DBL(other), mpfr_get_default_rounding_mode());
}else if(TYPE(other) == T_BIGNUM){
volatile VALUE tmp = rb_funcall(__mpfr_class__, new, 1, other);
r_mpfr_get_struct(ptr_other, tmp);
mpfr_mul(ptr_return, ptr_self, ptr_other, mpfr_get_default_rounding_mode());
}else if(rb_respond_to(other, to_fr)){
volatile VALUE tmp = rb_funcall(other, to_fr, 0);
r_mpfr_get_struct(ptr_other, tmp);
mpfr_mul(ptr_return, ptr_self, ptr_other, mpfr_get_default_rounding_mode());
}else{
rb_raise(rb_eArgError, "Argument must be MPFR, Fixnum, Float, or Bignum.");
}
return val_ret;
}
|
#**(other) ⇒ Object
Return p1-th power of self.
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 |
# File 'ext/mpfr/ruby_mpfr.c', line 1020
static VALUE r_mpfr_pow(VALUE self, VALUE other)
{
MPFR *ptr_self, *ptr_other, *ptr_return;
VALUE val_ret;
r_mpfr_get_struct(ptr_self, self);
r_mpfr_make_struct_init(val_ret, ptr_return);
if(TYPE(other) == T_FIXNUM){
mpfr_pow_si(ptr_return, ptr_self, FIX2LONG(other), mpfr_get_default_rounding_mode());
}else{
volatile VALUE tmp_other = r_mpfr_new_fr_obj(other);
r_mpfr_get_struct(ptr_other, tmp_other);
mpfr_pow(ptr_return, ptr_self, ptr_other, mpfr_get_default_rounding_mode());
}
return val_ret;
}
|
#+(other) ⇒ Object
Return self + p1.
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 |
# File 'ext/mpfr/ruby_mpfr.c', line 904
static VALUE r_mpfr_add(VALUE self, VALUE other)
{
MPFR *ptr_self, *ptr_other, *ptr_return;
VALUE val_ret;
r_mpfr_get_struct(ptr_self, self);
r_mpfr_make_struct_init(val_ret, ptr_return);
if(MPFR_P(other)){
r_mpfr_get_struct(ptr_other, other);
mpfr_add(ptr_return, ptr_self, ptr_other, mpfr_get_default_rounding_mode());
}else if(TYPE(other) == T_FIXNUM){
mpfr_add_si(ptr_return, ptr_self, FIX2LONG(other), mpfr_get_default_rounding_mode());
}else if(TYPE(other) == T_FLOAT){
mpfr_add_d(ptr_return, ptr_self, NUM2DBL(other), mpfr_get_default_rounding_mode());
}else if(TYPE(other) == T_BIGNUM){
volatile VALUE tmp = rb_funcall(__mpfr_class__, new, 1, other);
r_mpfr_get_struct(ptr_other, tmp);
mpfr_add(ptr_return, ptr_self, ptr_other, mpfr_get_default_rounding_mode());
}else if(rb_respond_to(other, to_fr)){
volatile VALUE tmp = rb_funcall(other, to_fr, 0);
r_mpfr_get_struct(ptr_other, tmp);
mpfr_add(ptr_return, ptr_self, ptr_other, mpfr_get_default_rounding_mode());
}else{
rb_raise(rb_eArgError, "Argument must be MPFR, Fixnum, Float, or Bignum.");
}
return val_ret;
}
|
#-(other) ⇒ Object
Return self - p1.
933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 |
# File 'ext/mpfr/ruby_mpfr.c', line 933
static VALUE r_mpfr_sub(VALUE self, VALUE other)
{
MPFR *ptr_self, *ptr_other, *ptr_return;
VALUE val_ret;
r_mpfr_get_struct(ptr_self, self);
r_mpfr_make_struct_init(val_ret, ptr_return);
if(MPFR_P(other)){
r_mpfr_get_struct(ptr_other, other);
mpfr_sub(ptr_return, ptr_self, ptr_other, mpfr_get_default_rounding_mode());
}else if(TYPE(other) == T_FIXNUM){
mpfr_sub_si(ptr_return, ptr_self, FIX2LONG(other), mpfr_get_default_rounding_mode());
}else if(TYPE(other) == T_FLOAT){
mpfr_sub_d(ptr_return, ptr_self, NUM2DBL(other), mpfr_get_default_rounding_mode());
}else if(TYPE(other) == T_BIGNUM){
volatile VALUE tmp = rb_funcall(__mpfr_class__, new, 1, other);
r_mpfr_get_struct(ptr_other, tmp);
mpfr_sub(ptr_return, ptr_self, ptr_other, mpfr_get_default_rounding_mode());
}else if(rb_respond_to(other, to_fr)){
volatile VALUE tmp = rb_funcall(other, to_fr, 0);
r_mpfr_get_struct(ptr_other, tmp);
mpfr_sub(ptr_return, ptr_self, ptr_other, mpfr_get_default_rounding_mode());
}else{
rb_raise(rb_eArgError, "Argument must be MPFR, Fixnum, Float, or Bignum.");
}
return val_ret;
}
|
#/(other) ⇒ Object
Return self / p1.
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 |
# File 'ext/mpfr/ruby_mpfr.c', line 991
static VALUE r_mpfr_div(VALUE self, VALUE other)
{
MPFR *ptr_self, *ptr_other, *ptr_return;
VALUE val_ret;
r_mpfr_get_struct(ptr_self, self);
r_mpfr_make_struct_init(val_ret, ptr_return);
if(MPFR_P(other)){
r_mpfr_get_struct(ptr_other, other);
mpfr_div(ptr_return, ptr_self, ptr_other, mpfr_get_default_rounding_mode());
}else if(TYPE(other) == T_FIXNUM){
mpfr_div_si(ptr_return, ptr_self, FIX2LONG(other), mpfr_get_default_rounding_mode());
}else if(TYPE(other) == T_FLOAT){
mpfr_div_d(ptr_return, ptr_self, NUM2DBL(other), mpfr_get_default_rounding_mode());
}else if(TYPE(other) == T_BIGNUM){
volatile VALUE tmp = rb_funcall(__mpfr_class__, new, 1, other);
r_mpfr_get_struct(ptr_other, tmp);
mpfr_div(ptr_return, ptr_self, ptr_other, mpfr_get_default_rounding_mode());
}else if(rb_respond_to(other, to_fr)){
volatile VALUE tmp = rb_funcall(other, to_fr, 0);
r_mpfr_get_struct(ptr_other, tmp);
mpfr_div(ptr_return, ptr_self, ptr_other, mpfr_get_default_rounding_mode());
}else{
rb_raise(rb_eArgError, "Argument must be MPFR, Fixnum, Float, or Bignum.");
}
return val_ret;
}
|
#abs(*args) ⇒ Object
Return absolute value of self.
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 |
# File 'ext/mpfr/ruby_mpfr.c', line 1051
static VALUE r_mpfr_abs(int argc, VALUE *argv, VALUE self)
{
mp_rnd_t rnd;
mp_prec_t prec;
MPFR *ptr_self, *ptr_return;
VALUE val_ret;
r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 0, 2, argc, argv);
r_mpfr_get_struct(ptr_self, self);
r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
mpfr_abs(ptr_return, ptr_self, rnd);
return val_ret;
}
|
#can_round(err, rnd1, rnd2, prec) ⇒ Object
mpfr_can_round(self, err, rnd1, rnd2, prec)
1902 1903 1904 1905 1906 1907 1908 1909 1910 |
# File 'ext/mpfr/ruby_mpfr.c', line 1902
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;
}
|
#ceil ⇒ Object
Return Fixnum object which is the minimum integer over self.
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 |
# File 'ext/mpfr/ruby_mpfr.c', line 814
static VALUE r_mpfr_ceil_to_i(VALUE self)
{
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
if (mpfr_fits_slong_p(ptr_self, GMP_RNDU)) {
return LONG2NUM(mpfr_get_si(ptr_self, GMP_RNDU));
} else if (mpfr_nan_p(ptr_self)) {
rb_raise(__mpfr_domain_error__, "Can not convert NaN to an integer");
} else {
MPFR *tmp_int;
char *tmp_str;
VALUE bignum;
r_mpfr_temp_alloc_init2(tmp_int, mpfr_get_prec(ptr_self));
mpfr_ceil(tmp_int, ptr_self);
if (!mpfr_asprintf(&tmp_str, "%Rf", tmp_int)) {
rb_raise(rb_eFatal, "Can not allocate a string by mpfr_asprintf.");
}
bignum = rb_cstr_to_inum(tmp_str, 10, false);
r_mpfr_temp_free(tmp_int);
return bignum;
}
}
|
#check_error(other, error = nil) ⇒ Object
12 13 14 |
# File 'lib/mpfr/rspec.rb', line 12 def check_error(other, error = nil) (self - other).abs < (error || @@error) end |
#check_range(*args) ⇒ Object
Execute mpfr_check_range( self, p1, rnd ) and return self.
323 324 325 326 327 328 329 330 |
# File 'ext/mpfr/ruby_mpfr.c', line 323
static VALUE r_mpfr_check_range(int argc, VALUE *argv, VALUE self)
{
mp_rnd_t rnd = r_mpfr_rnd_from_optional_argument(1, 2, argc, argv);
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
mpfr_check_range(ptr_self, NUM2INT(argv[0]), rnd);
return self;
}
|
#cmp(other) ⇒ Object Also known as: <=>
Return negative integer if self < other, negative integer if self > other, or 0 if self == other.
1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 |
# File 'ext/mpfr/ruby_mpfr.c', line 1340
static VALUE r_mpfr_cmp(VALUE self, VALUE other)
{
MPFR *ptr_self, *ptr_other;
int val_ret;
r_mpfr_get_struct(ptr_self, self);
if(MPFR_P(other)){
r_mpfr_get_struct(ptr_other, other);
val_ret = mpfr_cmp(ptr_self, ptr_other);
}else if(TYPE(other) == T_FIXNUM){
val_ret = mpfr_cmp_si(ptr_self, FIX2LONG(other));
}else if(TYPE(other) == T_FLOAT){
val_ret = mpfr_cmp_d(ptr_self, NUM2DBL(other));
}else if(TYPE(other) == T_BIGNUM){
volatile VALUE tmp = rb_funcall(__mpfr_class__, new, 1, other);
r_mpfr_get_struct(ptr_other, tmp);
val_ret = mpfr_cmp(ptr_self, ptr_other);
}else{
rb_raise(rb_eArgError, "Argument must be MPFR, Fixnum, Float, or Bignum.");
}
return INT2FIX(val_ret);
}
|
#cmp_si_2exp(other, exp) ⇒ Object
mpfr_cmp_si_2exp(self, p1, p2).
1380 1381 1382 1383 1384 1385 |
# File 'ext/mpfr/ruby_mpfr.c', line 1380
static VALUE r_mpfr_cmp_si_2exp(VALUE self, VALUE other, VALUE exp)
{
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
return INT2FIX(mpfr_cmp_si_2exp(ptr_self, NUM2INT(other), NUM2INT(exp)));
}
|
#cmp_ui_2exp(other, exp) ⇒ Object
mpfr_cmp_ui_2exp(self, p1, p2).
1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 |
# File 'ext/mpfr/ruby_mpfr.c', line 1364
static VALUE r_mpfr_cmp_ui_2exp(VALUE self, VALUE other, VALUE exp)
{
MPFR *ptr_self;
VALUE val_ret;
int i;
r_mpfr_get_struct(ptr_self, self);
i = NUM2INT(other);
if(i > 0){
val_ret = INT2FIX(mpfr_cmp_ui_2exp(ptr_self, i, (mp_exp_t)NUM2INT(exp)));
}else{
rb_raise(rb_eArgError, "First argument must be positive Fixnum.");
}
return val_ret;
}
|
#cmpabs(other) ⇒ Object
mpfr_cmpabs(self, p1).
1388 1389 1390 1391 1392 1393 1394 1395 1396 |
# File 'ext/mpfr/ruby_mpfr.c', line 1388
static VALUE r_mpfr_cmpabs(VALUE self, VALUE other)
{
MPFR *ptr_self, *ptr_other;
volatile VALUE tmp_other;
r_mpfr_get_struct(ptr_self, self);
tmp_other = r_mpfr_new_fr_obj(other);
r_mpfr_get_struct(ptr_other, tmp_other);
return INT2FIX(mpfr_cmpabs(ptr_self, ptr_other));
}
|
#coerce(other) ⇒ Object
Return array which have MPFR instance converted to from p1 and self.
565 566 567 568 |
# File 'ext/mpfr/ruby_mpfr.c', line 565
static VALUE r_mpfr_coerce(VALUE self, VALUE other)
{
return rb_ary_new3(2, r_mpfr_global_new(1, &other, r_mpfr_class), self);
}
|
#copysign(*args) ⇒ Object
mpfr_copysign(ret, self, p1, rnd)
1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 |
# File 'ext/mpfr/ruby_mpfr.c', line 1854
static VALUE r_mpfr_copysign(int argc, VALUE *argv, VALUE self)
{
mp_rnd_t rnd;
mp_prec_t prec;
MPFR *ptr_self, *ptr_return, *ptr_arg;
VALUE val_ret;
volatile VALUE tmp_argv0;
r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 2, 4, argc, argv);
r_mpfr_get_struct(ptr_self, self);
r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
tmp_argv0 = r_mpfr_new_fr_obj(argv[0]);
r_mpfr_get_struct(ptr_arg, tmp_argv0);
mpfr_copysign(ptr_return, ptr_self, ptr_arg, rnd);
return val_ret;
}
|
#equal_p(other) ⇒ Object
Return true if self == other, nil otherwise.
1526 1527 1528 1529 1530 1531 1532 1533 1534 |
# File 'ext/mpfr/ruby_mpfr.c', line 1526
static VALUE r_mpfr_equal_p(VALUE self, VALUE other)
{
MPFR *ptr_self, *ptr_other;
volatile VALUE tmp_other;
r_mpfr_get_struct(ptr_self, self);
tmp_other = r_mpfr_new_fr_obj(other);
r_mpfr_get_struct(ptr_other, tmp_other);
return (mpfr_equal_p(ptr_self, ptr_other) != 0 ? Qtrue : Qfalse);
}
|
#floor ⇒ Object
Return Fixnum object which is the maximum integer not over self.
838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 |
# File 'ext/mpfr/ruby_mpfr.c', line 838
static VALUE r_mpfr_floor_to_i(VALUE self)
{
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
if (mpfr_fits_slong_p(ptr_self, GMP_RNDD)) {
return LONG2NUM(mpfr_get_si(ptr_self, GMP_RNDD));
} else if (mpfr_nan_p(ptr_self)) {
rb_raise(__mpfr_domain_error__, "Can not convert NaN to an integer");
} else {
MPFR *tmp_int;
char *tmp_str;
VALUE bignum;
r_mpfr_temp_alloc_init2(tmp_int, mpfr_get_prec(ptr_self));
mpfr_floor(tmp_int, ptr_self);
if (!mpfr_asprintf(&tmp_str, "%Rf", tmp_int)) {
rb_raise(rb_eFatal, "Can not allocate a string by mpfr_asprintf.");
}
bignum = rb_cstr_to_inum(tmp_str, 10, false);
r_mpfr_temp_free(tmp_int);
return bignum;
}
}
|
#fmod(*args) ⇒ Object
mpfr_fmod(ret, self, p1, rnd)
1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 |
# File 'ext/mpfr/ruby_mpfr.c', line 1699
static VALUE r_mpfr_fmod(int argc, VALUE *argv, VALUE self)
{
mp_rnd_t rnd;
mp_prec_t prec;
MPFR *ptr_self, *ptr_other, *ptr_return;
VALUE val_ret;
volatile VALUE tmp_argv0;
r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 1, 3, argc, argv);
r_mpfr_get_struct(ptr_self, self);
r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
tmp_argv0 = r_mpfr_new_fr_obj(argv[0]);
r_mpfr_get_struct(ptr_other, tmp_argv0);
mpfr_fmod(ptr_return, ptr_self, ptr_other, rnd);
return val_ret;
}
|
#fr_ceil(*args) ⇒ Object
mpfr_ceil(ret, self)
1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 |
# File 'ext/mpfr/ruby_mpfr.c', line 1566
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);
r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
mpfr_ceil(ptr_return, ptr_self);
return val_ret;
}
|
#fr_floor(*args) ⇒ Object
mpfr_floor(ret, self)
1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 |
# File 'ext/mpfr/ruby_mpfr.c', line 1578
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);
r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
mpfr_floor(ptr_return, ptr_self);
return val_ret;
}
|
#fr_rint(*args) ⇒ Object
mpfr_rint(ret, self, rnd)
1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 |
# File 'ext/mpfr/ruby_mpfr.c', line 1552
static VALUE r_mpfr_fr_rint(int argc, VALUE *argv, VALUE self)
{
mp_rnd_t rnd;
mp_prec_t prec;
MPFR *ptr_self, *ptr_return;
VALUE val_ret;
r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 0, 2, argc, argv);
r_mpfr_get_struct(ptr_self, self);
r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
mpfr_rint(ptr_return, ptr_self, rnd);
return val_ret;
}
|
#fr_round(*args) ⇒ Object
mpfr_round(ret, self)
1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 |
# File 'ext/mpfr/ruby_mpfr.c', line 1590
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);
r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
mpfr_round(ptr_return, ptr_self);
return val_ret;
}
|
#fr_trunc(*args) ⇒ Object
mpfr_trunc(ret, self)
1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 |
# File 'ext/mpfr/ruby_mpfr.c', line 1602
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);
r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
mpfr_trunc(ptr_return, ptr_self);
return val_ret;
}
|
#frac(*args) ⇒ Object
mpfr_frac(ret, self, rnd)
1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 |
# File 'ext/mpfr/ruby_mpfr.c', line 1670
static VALUE r_mpfr_frac(int argc, VALUE *argv, VALUE self)
{
mp_rnd_t rnd;
mp_prec_t prec;
MPFR *ptr_self, *ptr_return;
VALUE val_ret;
r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 0, 2, argc, argv);
r_mpfr_get_struct(ptr_self, self);
r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
mpfr_frac(ptr_return, ptr_self, rnd);
return val_ret;
}
|
#get_d(*args) ⇒ Object Also known as: to_f
Return Float object by converting self. Optional argument is rnd meaning rounding mode. See MPFR reference for detail.
770 771 772 773 774 775 |
# File 'ext/mpfr/ruby_mpfr.c', line 770
static VALUE r_mpfr_get_d(int argc, VALUE *argv, VALUE self)
{
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
return rb_float_new(mpfr_get_d(ptr_self, r_mpfr_rnd_from_optional_argument(0, 1, argc, argv)));
}
|
#get_d_2exp(*args) ⇒ Object
d times 2 raised to exp equals self rounded to double precision. See MPFR reference for detail.
779 780 781 782 783 784 785 786 787 |
# File 'ext/mpfr/ruby_mpfr.c', line 779
static VALUE r_mpfr_get_d_2exp(int argc, VALUE *argv, VALUE self)
{
MPFR *ptr_self;
double ret_val1;
long int ret_val2;
r_mpfr_get_struct(ptr_self, self);
ret_val1 = mpfr_get_d_2exp(&ret_val2, ptr_self, r_mpfr_rnd_from_optional_argument(0, 1, argc, argv));
return rb_ary_new3(2, rb_float_new(ret_val1), LONG2NUM(ret_val2));
}
|
#get_exp ⇒ Object
If self is not number, return nil. Otherwise return an integer mpfr_get_exp(self).
1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 |
# File 'ext/mpfr/ruby_mpfr.c', line 1807
static VALUE r_mpfr_get_exp(VALUE self)
{
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
if(mpfr_number_p(ptr_self) != 0){
return INT2FIX(mpfr_get_exp(ptr_self));
}else{
return Qnil;
}
}
|
#get_prec ⇒ Object
Return precision actually used for assignments of self.
632 633 634 635 636 637 |
# File 'ext/mpfr/ruby_mpfr.c', line 632
static VALUE r_mpfr_get_prec(VALUE self)
{
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
return INT2NUM((int)mpfr_get_prec(ptr_self));
}
|
#get_str ⇒ Object
Return array having String object meaning mantissa and Fixnum object meaning exponent. See MPFR reference for detail.
886 887 888 889 890 891 892 893 894 895 896 897 |
# File 'ext/mpfr/ruby_mpfr.c', line 886
static VALUE r_mpfr_get_str(VALUE self)
{
MPFR *ptr_self;
mp_exp_t e;
char *str;
VALUE ret_str;
r_mpfr_get_struct(ptr_self, self);
str = mpfr_get_str(NULL, &e, 10, 0, ptr_self, GMP_RNDN);
ret_str = rb_str_new2(str);
mpfr_free_str(str);
return rb_ary_new3(2, ret_str, INT2FIX((int)e));
}
|
#get_z_2exp ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'ext/gmp/mpfr/ruby_mpfr_gmp.c', line 39
static VALUE r_mpfr_get_z_2exp(VALUE self)
{
VALUE ptr_return;
MPFR *ptr_self;
MP_INT *ptr_mpz;
long int exp;
r_mpfr_get_struct(ptr_self, self);
mpz_make_struct_init(ptr_return, ptr_mpz);
exp = mpfr_get_z_2exp(ptr_mpz, ptr_self);
return rb_ary_new3(2, ptr_return, INT2NUM(exp));
}
|
#greater_p(other) ⇒ Object
Return true if self > other, nil otherwise.
1471 1472 1473 1474 1475 1476 1477 1478 1479 |
# File 'ext/mpfr/ruby_mpfr.c', line 1471
static VALUE r_mpfr_greater_p(VALUE self, VALUE other)
{
MPFR *ptr_self, *ptr_other;
volatile VALUE tmp_other;
r_mpfr_get_struct(ptr_self, self);
tmp_other = r_mpfr_new_fr_obj(other);
r_mpfr_get_struct(ptr_other, tmp_other);
return (mpfr_greater_p(ptr_self, ptr_other) != 0 ? Qtrue : Qfalse);
}
|
#greaterequal_p(other) ⇒ Object
Return true if self >= other, nil otherwise.
1482 1483 1484 1485 1486 1487 1488 1489 1490 |
# File 'ext/mpfr/ruby_mpfr.c', line 1482
static VALUE r_mpfr_greaterequal_p(VALUE self, VALUE other)
{
MPFR *ptr_self, *ptr_other;
volatile VALUE tmp_other;
r_mpfr_get_struct(ptr_self, self);
tmp_other = r_mpfr_new_fr_obj(other);
r_mpfr_get_struct(ptr_other, tmp_other);
return (mpfr_greaterequal_p(ptr_self, ptr_other) != 0 ? Qtrue : Qfalse);
}
|
#inf_p ⇒ Object
Return true if self is infinity, nil otherwise.
1411 1412 1413 1414 1415 1416 |
# File 'ext/mpfr/ruby_mpfr.c', line 1411
static VALUE r_mpfr_inf_p(VALUE self)
{
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
return (mpfr_inf_p(ptr_self) != 0 ? Qtrue : Qfalse);
}
|
#infinite? ⇒ Boolean
Return 1 if self is plus infinity, -1 if minus infinity. nil otherwise.
1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 |
# File 'ext/mpfr/ruby_mpfr.c', line 1419
static VALUE r_mpfr_inf_p2(VALUE self)
{
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
if(mpfr_inf_p(ptr_self) != 0){
return (mpfr_sgn(ptr_self) > 0 ? INT2NUM(1) : INT2NUM(-1));
}else{
return Qfalse;
}
}
|
#inspect ⇒ Object
Output for debugging.
750 751 752 753 754 755 756 757 758 759 760 761 762 763 |
# File 'ext/mpfr/ruby_mpfr.c', line 750
static VALUE r_mpfr_inspect(VALUE self)
{
MPFR *ptr_s;
char *ret_str;
VALUE ret_val;
r_mpfr_get_struct(ptr_s, self);
if (!mpfr_asprintf(&ret_str, "#<MPFR:%lx,'%0.Re',%d>", NUM2LONG(rb_funcall(self, object_id, 0)),
ptr_s, mpfr_get_prec(ptr_s))) {
rb_raise(rb_eFatal, "Can not allocate a string by mpfr_asprintf.");
}
ret_val = rb_str_new2(ret_str);
mpfr_free_str(ret_str);
return ret_val;
}
|
#integer_p ⇒ Object Also known as: integer?
If value of self is integer, return true. Otherwise, nil.
1765 1766 1767 1768 1769 1770 |
# File 'ext/mpfr/ruby_mpfr.c', line 1765
static VALUE r_mpfr_integer_p(VALUE self)
{
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
return (mpfr_integer_p(ptr_self) != 0 ? Qtrue : Qnil);
}
|
#less_p(other) ⇒ Object
Return true if self < other, nil otherwise.
1493 1494 1495 1496 1497 1498 1499 1500 1501 |
# File 'ext/mpfr/ruby_mpfr.c', line 1493
static VALUE r_mpfr_less_p(VALUE self, VALUE other)
{
MPFR *ptr_self, *ptr_other;
volatile VALUE tmp_other;
r_mpfr_get_struct(ptr_self, self);
tmp_other = r_mpfr_new_fr_obj(other);
r_mpfr_get_struct(ptr_other, tmp_other);
return (mpfr_less_p(ptr_self, ptr_other) != 0 ? Qtrue : Qfalse);
}
|
#lessequal_p(other) ⇒ Object
Return true if self <= other, nil otherwise.
1504 1505 1506 1507 1508 1509 1510 1511 1512 |
# File 'ext/mpfr/ruby_mpfr.c', line 1504
static VALUE r_mpfr_lessequal_p(VALUE self, VALUE other)
{
MPFR *ptr_self, *ptr_other;
volatile VALUE tmp_other;
r_mpfr_get_struct(ptr_self, self);
tmp_other = r_mpfr_new_fr_obj(other);
r_mpfr_get_struct(ptr_other, tmp_other);
return (mpfr_lessequal_p(ptr_self, ptr_other) != 0 ? Qtrue : Qfalse);
}
|
#lessgreater_p(other) ⇒ Object
Return true if self < other or self > other, nil otherwise.
1515 1516 1517 1518 1519 1520 1521 1522 1523 |
# File 'ext/mpfr/ruby_mpfr.c', line 1515
static VALUE r_mpfr_lessgreater_p(VALUE self, VALUE other)
{
MPFR *ptr_self, *ptr_other;
volatile VALUE tmp_other;
r_mpfr_get_struct(ptr_self, self);
tmp_other = r_mpfr_new_fr_obj(other);
r_mpfr_get_struct(ptr_other, tmp_other);
return (mpfr_lessgreater_p(ptr_self, ptr_other) != 0 ? Qtrue : Qfalse);
}
|
#marshal_dump ⇒ Object
2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 |
# File 'ext/mpfr/ruby_mpfr.c', line 2951
static VALUE r_mpfr_marshal_dump(VALUE self)
{
MPFR *ptr_s;
char *ret_str;
VALUE ret_val;
r_mpfr_get_struct(ptr_s, self);
ret_str = r_mpfr_dump_to_string(ptr_s);
ret_val = rb_str_new2(ret_str);
mpfr_free_str(ret_str);
return ret_val;
}
|
#marshal_load(dump_string) ⇒ Object
3005 3006 3007 3008 3009 3010 3011 3012 |
# File 'ext/mpfr/ruby_mpfr.c', line 3005
static VALUE r_mpfr_marshal_load(VALUE self, VALUE dump_string)
{
MPFR *ptr_s;
r_mpfr_get_struct(ptr_s, self);
Check_Type(dump_string, T_STRING);
r_mpfr_load_string(ptr_s, RSTRING_PTR(dump_string));
return self;
}
|
#min_prec ⇒ Object
mpfr_min_prec(self)
1913 1914 1915 1916 1917 1918 |
# File 'ext/mpfr/ruby_mpfr.c', line 1913
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));
}
|
#modf(*args) ⇒ Object
Return [ret1, ret2] such that mpfr_modf(ret1, ret2, self, rnd).
1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 |
# File 'ext/mpfr/ruby_mpfr.c', line 1684
static VALUE r_mpfr_modf(int argc, VALUE *argv, VALUE self)
{
mp_rnd_t rnd;
mp_prec_t prec;
MPFR *ptr_self, *ptr_return1, *ptr_return2;
VALUE val_ret1, val_ret2;
r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 0, 2, argc, argv);
r_mpfr_get_struct(ptr_self, self);
r_mpfr_make_struct_init2(val_ret1, ptr_return1, prec);
r_mpfr_make_struct_init2(val_ret2, ptr_return2, prec);
mpfr_modf(ptr_return1, ptr_return2, ptr_self, rnd);
return rb_ary_new3(2, val_ret1, val_ret2);
}
|
#nan_p ⇒ Object Also known as: nan?
Return true if self is NaN, nil otherwise.
1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 |
# File 'ext/mpfr/ruby_mpfr.c', line 1399
static VALUE r_mpfr_nan_p(VALUE self)
{
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
if(mpfr_nan_p(ptr_self) != 0){
return Qtrue;
}else{
return Qfalse;
}
}
|
#neg(*args) ⇒ Object
Return negative value of self.
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 |
# File 'ext/mpfr/ruby_mpfr.c', line 1037
static VALUE r_mpfr_neg(int argc, VALUE *argv, VALUE self)
{
mp_rnd_t rnd;
mp_prec_t prec;
MPFR *ptr_self, *ptr_return;
VALUE val_ret;
r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 0, 2, argc, argv);
r_mpfr_get_struct(ptr_self, self);
r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
mpfr_neg(ptr_return, ptr_self, rnd);
return val_ret;
}
|
#nextabove ⇒ Object
mpfr_nextabove(self)
1789 1790 1791 1792 1793 1794 1795 |
# File 'ext/mpfr/ruby_mpfr.c', line 1789
static VALUE r_mpfr_nextabove(VALUE self)
{
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
mpfr_nextabove(ptr_self);
return self;
}
|
#nextbelow ⇒ Object
mpfr_nextbelow(self)
1798 1799 1800 1801 1802 1803 1804 |
# File 'ext/mpfr/ruby_mpfr.c', line 1798
static VALUE r_mpfr_nextbelow(VALUE self)
{
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
mpfr_nextbelow(ptr_self);
return self;
}
|
#nexttoward(other) ⇒ Object
mpfr_nexttoward(self, p1)
1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 |
# File 'ext/mpfr/ruby_mpfr.c', line 1777
static VALUE r_mpfr_nexttoward(VALUE self, VALUE other)
{
MPFR *ptr_self, *ptr_other;
volatile VALUE tmp_other;
r_mpfr_get_struct(ptr_self, self);
tmp_other = r_mpfr_new_fr_obj(other);
r_mpfr_get_struct(ptr_other, tmp_other);
mpfr_nexttoward(ptr_self, ptr_other);
return self;
}
|
#nonzero? ⇒ Boolean
Return true if self is non zero, nil otherwise.
1447 1448 1449 1450 1451 1452 |
# File 'ext/mpfr/ruby_mpfr.c', line 1447
static VALUE r_mpfr_nonzero_p(VALUE self)
{
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
return (mpfr_zero_p(ptr_self) == 0 ? Qtrue : Qfalse);
}
|
#number_p ⇒ Object Also known as: finite?
Return true if self is number, nil otherwise
1431 1432 1433 1434 1435 1436 |
# File 'ext/mpfr/ruby_mpfr.c', line 1431
static VALUE r_mpfr_number_p(VALUE self)
{
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
return (mpfr_number_p(ptr_self) != 0 ? Qtrue : Qfalse);
}
|
#prec_round(*args) ⇒ Object
mpfr_prec_round(ret, prec, rnd)
1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 |
# File 'ext/mpfr/ruby_mpfr.c', line 1875
static VALUE r_mpfr_prec_round(int argc, VALUE *argv, VALUE self)
{
mp_rnd_t rnd;
mp_prec_t prec;
MPFR *ptr_self, *ptr_return;
VALUE val_ret;
r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 0, 2, argc, argv);
r_mpfr_get_struct(ptr_self, self);
r_mpfr_make_struct_init2(val_ret, ptr_return, mpfr_get_prec(ptr_self));
mpfr_set(ptr_return, ptr_self, mpfr_get_default_prec());
mpfr_prec_round(ptr_return, prec, rnd);
return val_ret;
}
|
#prec_round!(*args) ⇒ Object
mpfr_prec_round(self, prec, rnd)
1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 |
# File 'ext/mpfr/ruby_mpfr.c', line 1890
static VALUE r_mpfr_prec_round2(int argc, VALUE *argv, VALUE self)
{
mp_rnd_t rnd;
mp_prec_t prec;
MPFR *ptr_self;
r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 0, 2, argc, argv);
r_mpfr_get_struct(ptr_self, self);
mpfr_prec_round(ptr_self, prec, rnd);
return self;
}
|
#regular? ⇒ Boolean
Return true if self is regular number, nil otherwise.
1455 1456 1457 1458 1459 1460 |
# File 'ext/mpfr/ruby_mpfr.c', line 1455
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);
}
|
#remainder(*args) ⇒ Object
mpfr_remainder(ret, self, p1, rnd)
1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 |
# File 'ext/mpfr/ruby_mpfr.c', line 1716
static VALUE r_mpfr_remainder(int argc, VALUE *argv, VALUE self)
{
mp_rnd_t rnd;
mp_prec_t prec;
MPFR *ptr_self, *ptr_other, *ptr_return;
VALUE val_ret;
volatile VALUE tmp_argv0;
r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 1, 3, argc, argv);
r_mpfr_get_struct(ptr_self, self);
r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
tmp_argv0 = r_mpfr_new_fr_obj(argv[0]);
r_mpfr_get_struct(ptr_other, tmp_argv0);
mpfr_remainder(ptr_return, ptr_self, ptr_other, rnd);
return val_ret;
}
|
#remquo(*args) ⇒ Object
mpfr_remquo(ret1, ret2, self, p1, rnd)
1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 |
# File 'ext/mpfr/ruby_mpfr.c', line 1747
static VALUE r_mpfr_remquo(int argc, VALUE *argv, VALUE self)
{
mp_rnd_t rnd;
mp_prec_t prec;
MPFR *ptr_self, *ptr_other, *ptr_return;
VALUE val_ret;
long q;
volatile VALUE tmp_argv0;
r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 1, 3, argc, argv);
r_mpfr_get_struct(ptr_self, self);
r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
tmp_argv0 = r_mpfr_new_fr_obj(argv[0]);
r_mpfr_get_struct(ptr_other, tmp_argv0);
mpfr_remquo(ptr_return, &q, ptr_self, ptr_other, rnd);
return rb_ary_new3(2, val_ret, LONG2FIX(q));
}
|
#rint_ceil(*args) ⇒ Object
mpfr_rint_ceil(ret, self, rnd)
1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 |
# File 'ext/mpfr/ruby_mpfr.c', line 1614
static VALUE r_mpfr_rint_ceil(int argc, VALUE *argv, VALUE self)
{
mp_rnd_t rnd;
mp_prec_t prec;
MPFR *ptr_self, *ptr_return;
VALUE val_ret;
r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 0, 2, argc, argv);
r_mpfr_get_struct(ptr_self, self);
r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
mpfr_rint_ceil(ptr_return, ptr_self, rnd);
return val_ret;
}
|
#rint_floor(*args) ⇒ Object
mpfr_rint_floor(ret, self, rnd)
1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 |
# File 'ext/mpfr/ruby_mpfr.c', line 1628
static VALUE r_mpfr_rint_floor(int argc, VALUE *argv, VALUE self)
{
mp_rnd_t rnd;
mp_prec_t prec;
MPFR *ptr_self, *ptr_return;
VALUE val_ret;
r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 0, 2, argc, argv);
r_mpfr_get_struct(ptr_self, self);
r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
mpfr_rint_floor(ptr_return, ptr_self, rnd);
return val_ret;
}
|
#rint_round(*args) ⇒ Object
mpfr_rint_round(ret, self, rnd)
1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 |
# File 'ext/mpfr/ruby_mpfr.c', line 1642
static VALUE r_mpfr_rint_round(int argc, VALUE *argv, VALUE self)
{
mp_rnd_t rnd;
mp_prec_t prec;
MPFR *ptr_self, *ptr_return;
VALUE val_ret;
r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 0, 2, argc, argv);
r_mpfr_get_struct(ptr_self, self);
r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
mpfr_rint_round(ptr_return, ptr_self, rnd);
return val_ret;
}
|
#rint_trunc(*args) ⇒ Object
mpfr_rint_trunc(ret, self, rnd)
1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 |
# File 'ext/mpfr/ruby_mpfr.c', line 1656
static VALUE r_mpfr_rint_trunc(int argc, VALUE *argv, VALUE self)
{
mp_rnd_t rnd;
mp_prec_t prec;
MPFR *ptr_self, *ptr_return;
VALUE val_ret;
r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 0, 2, argc, argv);
r_mpfr_get_struct(ptr_self, self);
r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
mpfr_rint_trunc(ptr_return, ptr_self, rnd);
return val_ret;
}
|
#round ⇒ Object
Return Fixnum object which is nearest integer to self.
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 |
# File 'ext/mpfr/ruby_mpfr.c', line 790
static VALUE r_mpfr_round_to_i(VALUE self)
{
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
if (mpfr_fits_slong_p(ptr_self, GMP_RNDN)) {
return LONG2NUM(mpfr_get_si(ptr_self, GMP_RNDN));
} else if (mpfr_nan_p(ptr_self)) {
rb_raise(__mpfr_domain_error__, "Can not convert NaN to an integer");
} else {
MPFR *tmp_int;
char *tmp_str;
VALUE bignum;
r_mpfr_temp_alloc_init2(tmp_int, mpfr_get_prec(ptr_self));
mpfr_round(tmp_int, ptr_self);
if (!mpfr_asprintf(&tmp_str, "%Rf", tmp_int)) {
rb_raise(rb_eFatal, "Can not allocate a string by mpfr_asprintf.");
}
bignum = rb_cstr_to_inum(tmp_str, 10, false);
r_mpfr_temp_free(tmp_int);
return bignum;
}
}
|
#set(*args) ⇒ Object
Arguments are val, rnd, and prec. Set the value of self from val. rnd and prec are optional.
640 641 642 643 644 645 646 647 648 |
# File 'ext/mpfr/ruby_mpfr.c', line 640
static VALUE r_mpfr_set(int argc, VALUE *argv, VALUE self)
{
MPFR *ptr_self;
mp_rnd_t rnd;
r_mpfr_get_struct(ptr_self, self);
rnd = r_mpfr_rnd_from_optional_argument(1, 2, argc, argv);
r_mpfr_set_robj(ptr_self, argv[0], rnd);
return self;
}
|
#set_exp(arg_exp) ⇒ Object
arg_exp is integer and we execute mpfr_set_exp(self, arg_exp).
1819 1820 1821 1822 1823 1824 1825 1826 1827 |
# File 'ext/mpfr/ruby_mpfr.c', line 1819
static VALUE r_mpfr_set_exp(VALUE self, VALUE arg_exp)
{
MPFR *ptr_self;
mp_exp_t exp;
r_mpfr_get_struct(ptr_self, self);
exp = NUM2INT(arg_exp);
mpfr_set_exp(ptr_self, exp);
return self;
}
|
#set_fixnum_2exp(*args) ⇒ Object
Arguments are num, exp, rnd, and prec. Set the value of self from num multiplied by two to the power exp. Set the value of self from val. rnd and prec are optional.
654 655 656 657 658 659 660 661 662 |
# File 'ext/mpfr/ruby_mpfr.c', line 654
static VALUE r_mpfr_set_fixnum_2exp(int argc, VALUE *argv, VALUE self)
{
MPFR *ptr_self;
mp_rnd_t rnd;
r_mpfr_get_struct(ptr_self, self);
rnd = r_mpfr_rnd_from_optional_argument(2, 3, argc, argv);
mpfr_set_si_2exp(ptr_self, NUM2INT(argv[0]), NUM2INT(argv[1]), rnd);
return self;
}
|
#set_inf(sign) ⇒ Object
If p1 is nonnegative Fixnum, set the value of self to plus Inf. Otherwise, set the value of self to minus Inf.
668 669 670 671 672 673 674 |
# File 'ext/mpfr/ruby_mpfr.c', line 668
static VALUE r_mpfr_set_inf(VALUE self, VALUE sign)
{
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
mpfr_set_inf(ptr_self, NUM2INT(sign));
return self;
}
|
#set_nan ⇒ Object
Set the value of self to NaN.
677 678 679 680 681 682 683 |
# File 'ext/mpfr/ruby_mpfr.c', line 677
static VALUE r_mpfr_set_nan(VALUE self)
{
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
mpfr_set_nan(ptr_self);
return self;
}
|
#set_prec(prec) ⇒ Object
Reset the precision of self to be exactly p1 bits and set its value to NaN.
623 624 625 626 627 628 629 |
# File 'ext/mpfr/ruby_mpfr.c', line 623
static VALUE r_mpfr_set_prec(VALUE self, VALUE prec)
{
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
mpfr_set_prec(ptr_self, NUM2INT(prec));
return INT2NUM((int)mpfr_get_prec(ptr_self));
}
|
#set_zero(*args) ⇒ Object
Set the value of self to zero.
686 687 688 689 690 691 692 693 694 695 696 697 698 |
# File 'ext/mpfr/ruby_mpfr.c', line 686
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;
}
|
#setsign(*args) ⇒ Object
mpfr_setsign(ret, self, p1, rnd)
1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 |
# File 'ext/mpfr/ruby_mpfr.c', line 1838
static VALUE r_mpfr_setsign(int argc, VALUE *argv, VALUE self)
{
mp_rnd_t rnd;
mp_prec_t prec;
MPFR *ptr_self, *ptr_return;
VALUE val_ret;
int s;
r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 2, 4, argc, argv);
r_mpfr_get_struct(ptr_self, self);
r_mpfr_make_struct_init2(val_ret, ptr_return, prec);
s = NUM2INT(argv[0]);
mpfr_setsign(ptr_return, ptr_self, s, rnd);
return val_ret;
}
|
#sgn ⇒ Object
mpfr_sgn(self).
1463 1464 1465 1466 1467 1468 |
# File 'ext/mpfr/ruby_mpfr.c', line 1463
static VALUE r_mpfr_sgn(VALUE self)
{
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
return INT2FIX(mpfr_sgn(ptr_self));
}
|
#signbit ⇒ Object
Return integer which is mpfr_signbit(self).
1830 1831 1832 1833 1834 1835 |
# File 'ext/mpfr/ruby_mpfr.c', line 1830
static VALUE r_mpfr_signbit(VALUE self)
{
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
return INT2FIX(mpfr_signbit(ptr_self));
}
|
#subnormalize(*args) ⇒ Object
Execute mpfr_subnormalize( self, p1, rnd ) and return self.
333 334 335 336 337 338 339 340 |
# File 'ext/mpfr/ruby_mpfr.c', line 333
static VALUE r_mpfr_subnormalize(int argc, VALUE *argv, VALUE self)
{
mp_rnd_t rnd = r_mpfr_rnd_from_optional_argument(1, 2, argc, argv);
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
mpfr_subnormalize(ptr_self, NUM2INT(argv[0]), rnd);
return self;
}
|
#swap(other) ⇒ Object
Swap the values self and p1 efficiently. p1 must be MPFR object.
701 702 703 704 705 706 707 708 709 710 711 712 |
# File 'ext/mpfr/ruby_mpfr.c', line 701
static VALUE r_mpfr_swap(VALUE self, VALUE other)
{
MPFR *ptr_self, *ptr_other;
r_mpfr_get_struct(ptr_self, self);
if(MPFR_P(other)){
r_mpfr_get_struct(ptr_other, other);
}else{
rb_raise(rb_eArgError, "Argument must be MPFR object.");
}
mpfr_swap(ptr_self, ptr_other);
return self;
}
|
#to_mpf(*args) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'ext/gmp/mpfr/ruby_mpfr_gmp.c', line 9
static VALUE r_mpfr_to_mpf(int argc, VALUE *argv, VALUE self)
{
VALUE ptr_return;
MPFR *ptr_self;
MP_FLOAT *ptr_mpf;
mp_rnd_t rnd;
rnd = r_mpfr_rnd_from_optional_argument(0, 1, argc, argv);
r_mpfr_get_struct(ptr_self, self);
mpf_make_struct_init(ptr_return, ptr_mpf, mpfr_get_prec(ptr_self));
#if defined(MPFR) && defined(HAVE_MPFR_H)
mpfr_set(ptr_mpf, ptr_self, rnd);
#else
mpfr_get_f(ptr_mpf, ptr_self, rnd);
#endif
return ptr_return;
}
|
#to_mpz(*args) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'ext/gmp/mpfr/ruby_mpfr_gmp.c', line 26
static VALUE r_mpfr_to_mpz(int argc, VALUE *argv, VALUE self)
{
VALUE ptr_return;
MPFR *ptr_self;
MP_INT *ptr_mpz;
mp_rnd_t rnd;
rnd = r_mpfr_rnd_from_optional_argument(0, 1, argc, argv);
r_mpfr_get_struct(ptr_self, self);
mpz_make_struct_init(ptr_return, ptr_mpz);
mpfr_get_z(ptr_mpz, ptr_self, rnd);
return ptr_return;
}
|
#to_s ⇒ Object
Convert to string.
735 736 737 738 739 740 741 742 743 744 745 746 747 |
# File 'ext/mpfr/ruby_mpfr.c', line 735
static VALUE r_mpfr_to_s(VALUE self)
{
MPFR *ptr_self;
char *ret_str;
VALUE ret_val;
r_mpfr_get_struct(ptr_self, self);
if (!mpfr_asprintf(&ret_str, "%.Re", ptr_self)) {
rb_raise(rb_eFatal, "Can not allocate a string by mpfr_asprintf.");
}
ret_val = rb_str_new2(ret_str);
mpfr_free_str(ret_str);
return ret_val;
}
|
#to_strf(format_str) ⇒ Object
Output self by mpfr_asprintf( some_val, p1, self ). For example, p1 are “%.Re”, “%.Rf” or “%.30Re” etc.
719 720 721 722 723 724 725 726 727 728 729 730 731 732 |
# File 'ext/mpfr/ruby_mpfr.c', line 719
static VALUE r_mpfr_to_strf(VALUE self, VALUE format_str)
{
MPFR *ptr_self;
char *format, *ret_str;
VALUE ret_val;
r_mpfr_get_struct(ptr_self, self);
format = StringValuePtr(format_str);
if (!mpfr_asprintf(&ret_str, format, ptr_self)) {
rb_raise(rb_eFatal, "Can not allocate a string by mpfr_asprintf.");
}
ret_val = rb_str_new2(ret_str);
mpfr_free_str(ret_str);
return ret_val;
}
|
#truncate ⇒ Object Also known as: to_i, to_int
Return Fixnum object by truncating self.
862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 |
# File 'ext/mpfr/ruby_mpfr.c', line 862
static VALUE r_mpfr_truncate_to_i(VALUE self)
{
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
if (mpfr_fits_slong_p(ptr_self, GMP_RNDZ)) {
return LONG2NUM(mpfr_get_si(ptr_self, GMP_RNDZ));
} else if (mpfr_nan_p(ptr_self)) {
rb_raise(__mpfr_domain_error__, "Can not convert NaN to an integer");
} else {
MPFR *tmp_int;
char *tmp_str;
VALUE bignum;
r_mpfr_temp_alloc_init2(tmp_int, mpfr_get_prec(ptr_self));
mpfr_trunc(tmp_int, ptr_self);
if (!mpfr_asprintf(&tmp_str, "%Rf", tmp_int)) {
rb_raise(rb_eFatal, "Can not allocate a string by mpfr_asprintf.");
}
bignum = rb_cstr_to_inum(tmp_str, 10, false);
r_mpfr_temp_free(tmp_int);
return bignum;
}
}
|
#unordered_p(other) ⇒ Object
Return true if self or other is a NaN, nil otherwise
1537 1538 1539 1540 1541 1542 1543 1544 1545 |
# File 'ext/mpfr/ruby_mpfr.c', line 1537
static VALUE r_mpfr_unordered_p(VALUE self, VALUE other)
{
MPFR *ptr_self, *ptr_other;
volatile VALUE tmp_other;
r_mpfr_get_struct(ptr_self, self);
tmp_other = r_mpfr_new_fr_obj(other);
r_mpfr_get_struct(ptr_other, tmp_other);
return (mpfr_unordered_p(ptr_self, ptr_other) != 0 ? Qtrue : Qfalse);
}
|
#zero_p ⇒ Object Also known as: zero?
Return true if self is 0, nil otherwise.
1439 1440 1441 1442 1443 1444 |
# File 'ext/mpfr/ruby_mpfr.c', line 1439
static VALUE r_mpfr_zero_p(VALUE self)
{
MPFR *ptr_self;
r_mpfr_get_struct(ptr_self, self);
return (mpfr_zero_p(ptr_self) != 0 ? Qtrue : Qfalse);
}
|