Class: GMP::F
- Inherits:
-
Numeric
- Object
- Numeric
- GMP::F
- Defined in:
- ext/gmpf.c,
ext/gmp.c,
ext/gmpf.c
Overview
GMP Multiple Precision floating point numbers.
Instances of this class can store variables of the type mpf_t. This class also contains many methods that act as the functions for mpf_t variables, as well as a few methods that attempt to make this library more Ruby-ish.
The following list is just a simple checklist for me, really. A better reference should be found in the rdocs.
Ruby method C Extension function GMP function
to_d r_gmpf_to_d mpf_get_d
to_s r_gmpf_to_s mpf_get_s
+ r_gmpf_add mpf_add
- r_gmpf_sub mpf_sub
* r_gmpf_mul mpf_mul
/ r_gmpf_div mpf_div
Class Method Summary collapse
- .const_catalan ⇒ Object
- .const_euler ⇒ Object
-
.const_log2 ⇒ Object
“ai”, r_gmpfr_ai !! 3.0.0.
- .const_pi ⇒ Object
- .default_prec ⇒ Object
- .default_prec=(arg) ⇒ Object
- .default_rounding_mode ⇒ Object
- .default_rounding_mode=(arg) ⇒ Object
-
.GMP::R.new(arg) ⇒ Object
Creates a new GMP::R float, with arg as its value, converting where necessary.
Instance Method Summary collapse
- #* ⇒ Object
- #** ⇒ Object (also: #pow)
- #+ ⇒ Object
-
#- ⇒ Object
Float Arithmetic.
- #-@ ⇒ Object
- #/ ⇒ Object
- #< ⇒ Object
- #<= ⇒ Object
-
#<=> ⇒ Object
Float Comparison.
- #== ⇒ Object
- #> ⇒ Object
- #>= ⇒ Object
- #abs ⇒ Object
- #abs! ⇒ Object
- #acos ⇒ Object
- #acosh ⇒ Object
- #asin ⇒ Object
- #asinh ⇒ Object
- #atan ⇒ Object
- #atanh ⇒ Object
- #cbrt ⇒ Object
-
#ceil ⇒ Object
Miscellaneous Functions.
- #ceil! ⇒ Object
-
#coerce(arg) ⇒ Object
new method - testing.
- #cos ⇒ Object
-
#cosh ⇒ Object
“atan2”, r_gmpfr_atan2.
- #cot ⇒ Object
- #coth ⇒ Object
- #csc ⇒ Object
- #csch ⇒ Object
- #digamma ⇒ Object
- #eint ⇒ Object
- #erf ⇒ Object
- #erfc ⇒ Object
- #exp ⇒ Object
- #exp10 ⇒ Object
- #exp2 ⇒ Object
- #expm1 ⇒ Object
- #finite? ⇒ Boolean
- #floor ⇒ Object
- #floor! ⇒ Object
- #gamma ⇒ Object
- #infinite? ⇒ Boolean
- #initialize(*args) ⇒ Object constructor
- #j0 ⇒ Object
- #j1 ⇒ Object
- #jn ⇒ Object
- #li2 ⇒ Object
- #lngamma ⇒ Object
-
#log ⇒ Object
Special Functions.
- #log10 ⇒ Object
-
#log1p ⇒ Object
“fac”, r_gmpfr_fac.
- #log2 ⇒ Object
-
#nan? ⇒ Boolean
Comparison Functions.
- #neg! ⇒ Object
- #number? ⇒ Boolean
- #prec ⇒ Object
- #prec= ⇒ Object
- #prec_raw= ⇒ Object
- #rec_sqrt ⇒ Object
- #regular? ⇒ Boolean
-
#sec ⇒ Object
“sin_cos”, r_gmpfr_sin_cos.
-
#sech ⇒ Object
“sinh_cosh”, r_gmpfr_sinh_cosh.
- #sgn ⇒ Object
- #sin ⇒ Object
- #sinh ⇒ Object
-
#sqrt ⇒ Object
Basic Arithmetic Functions.
- #tan ⇒ Object
- #tanh ⇒ Object
- #to_d ⇒ Object (also: #to_f)
-
#to_s ⇒ Object
Converting Floats.
- #trunc ⇒ Object
- #trunc! ⇒ Object
- #y0 ⇒ Object
- #y1 ⇒ Object
- #yn ⇒ Object
- #zero? ⇒ Boolean
- #zeta ⇒ Object
Constructor Details
#initialize(*args) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'ext/gmpf.c', line 84
VALUE r_gmpf_initialize(int argc, VALUE *argv, VALUE self)
{
MP_FLOAT *self_val, *arg_val_f;
unsigned long prec = 0;
VALUE arg;
mpf_get_struct (self, self_val);
if (argc==0) {
#ifdef MPFR
mpfr_init (self_val);
mpfr_set_si (self_val, 0, __gmp_default_rounding_mode);
#else
r_mpf_init (self_val);
mpf_set_si (self_val, 0);
#endif
return Qnil;
}
arg = argv[0];
//argc >= 2 ==> argv[0] is value, argv[1] is prec
if (argc >= 2) {
if (FIXNUM_P(argv[1])) {
if (FIX2INT(argv[1]) >= 0)
prec = FIX2INT(argv[1]);
else {
r_mpf_init (self_val);
rb_raise(rb_eRangeError, "prec must be non-negative");
}
} else {
r_mpf_init (self_val);
rb_raise(rb_eTypeError, "prec must be a Fixnum");
}
} else if (GMPF_P(arg)) {
mpf_get_struct (arg, arg_val_f);
prec = mpf_get_prec (arg_val_f);
}
#ifdef MPFR
int base = 10;
if (prec == 0)
mpfr_init (self_val);
else
mpfr_init2 (self_val, prec);
if (STRING_P(argv[0])) {
if (argc >= 3) {
if (FIXNUM_P(argv[2])) {
if (FIX2INT(argv[2]) >= 2 && FIX2INT(argv[2]) <= 36)
base = FIX2INT(argv[2]);
else
rb_raise(rb_eRangeError, "base must be between 2 and 36");
}
else {
rb_raise(rb_eTypeError, "base must be a Fixnum");
}
}
if (argc == 4) {
// FIGURE IT OUT. ACCEPT A ROUNDING MODE!
}
mpf_set_value2 (self_val, arg, base);
return Qnil;
}
#else
if (prec == 0)
r_mpf_init (self_val);
else
r_mpf_init2 (self_val, prec);
#endif
if (GMPF_P(arg)) {
mpf_get_struct (arg, arg_val_f);
mpf_set(self_val, arg_val_f);
} else {
mpf_set_value(self_val, arg);
}
return Qnil;
}
|
Class Method Details
.const_catalan ⇒ Object
.const_euler ⇒ Object
.const_log2 ⇒ Object
“ai”, r_gmpfr_ai !! 3.0.0
.const_pi ⇒ Object
.default_prec ⇒ Object
80 81 82 83 84 |
# File 'ext/gmp.c', line 80
static VALUE r_gmpfsg_get_default_prec(VALUE klass)
{
(void)klass;
return INT2NUM(mpf_get_default_prec());
}
|
.default_prec=(arg) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'ext/gmp.c', line 86
static VALUE r_gmpfsg_set_default_prec(VALUE klass, VALUE arg)
{
(void)klass;
if (FIXNUM_P(arg)) {
if (FIX2NUM(arg) <= 0) {
rb_raise(rb_eRangeError, "prec must be positive");
}
mpf_set_default_prec (FIX2NUM(arg));
} else {
rb_raise(rb_eTypeError, "prec must be FixNum");
}
return Qnil;
}
|
.default_rounding_mode ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'ext/gmp.c', line 101
static VALUE r_gmpfsg_get_default_rounding_mode(VALUE klass)
{
(void)klass;
const char *rounding_string_val;
rounding_string_val = mpfr_print_rnd_mode (mpfr_get_default_rounding_mode ());
if ( rounding_string_val == NULL ) {
return Qnil;
}
else {
return rb_const_get (mGMP, rb_intern (rounding_string_val));
}
}
|
.default_rounding_mode=(arg) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'ext/gmp.c', line 114
static VALUE r_gmpfsg_set_default_rounding_mode(VALUE klass, VALUE arg)
{
(void)klass;
VALUE mode;
if (GMPRND_P(arg)) {
mode = rb_funcall (arg, rb_intern("mode"), 0);
if (FIX2INT(mode) < 0 || FIX2INT(mode) > 3) {
rb_raise(rb_eRangeError, "rounding mode must be one of the rounding mode constants.");
}
} else {
rb_raise(rb_eTypeError, "rounding mode must be one of the rounding mode constants.");
}
switch (FIX2INT(mode)) {
case 0:
mpfr_set_default_rounding_mode (GMP_RNDN);
break;
case 1:
mpfr_set_default_rounding_mode (GMP_RNDZ);
break;
case 2:
mpfr_set_default_rounding_mode (GMP_RNDU);
break;
case 3:
mpfr_set_default_rounding_mode (GMP_RNDD);
break;
#if MPFR_VERSION_MAJOR>2
case 4:
mpfr_set_default_rounding_mode (MPFR_RNDA);
break;
#endif
}
return Qnil;
}
|
.GMP::R.new(arg) ⇒ Object
Creates a new GMP::R float, with arg as its value, converting where necessary.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'ext/gmpf.c', line 69
VALUE r_gmpfsg_new(int argc, VALUE *argv, VALUE klass)
{
MP_FLOAT *res_val;
VALUE res;
(void)klass;
if (argc > 4)
rb_raise(rb_eArgError, "wrong # of arguments(%d for 0, 1 2, 3, or 4)", argc);
mpf_make_struct (res, res_val);
rb_obj_call_init(res, argc, argv);
return res;
}
|
Instance Method Details
#* ⇒ Object
#** ⇒ Object Also known as: pow
#+ ⇒ Object
#- ⇒ Object
Float Arithmetic
#-@ ⇒ Object
#/ ⇒ Object
#< ⇒ Object
#<= ⇒ Object
#<=> ⇒ Object
Float Comparison
#== ⇒ Object
#> ⇒ Object
#>= ⇒ Object
#abs ⇒ Object
#abs! ⇒ Object
#acos ⇒ Object
#acosh ⇒ Object
#asin ⇒ Object
#asinh ⇒ Object
#atan ⇒ Object
#atanh ⇒ Object
#cbrt ⇒ Object
#ceil ⇒ Object
Miscellaneous Functions
#ceil! ⇒ Object
#coerce(arg) ⇒ Object
new method - testing
75 76 77 78 |
# File 'ext/gmp.c', line 75
static VALUE r_gmpf_coerce(VALUE self, VALUE arg)
{
return rb_assoc_new(r_gmpfsg_new(1, &arg, cGMP_F), self);
}
|
#cos ⇒ Object
#cosh ⇒ Object
“atan2”, r_gmpfr_atan2
#cot ⇒ Object
#coth ⇒ Object
#csc ⇒ Object
#csch ⇒ Object
#digamma ⇒ Object
#eint ⇒ Object
#erf ⇒ Object
#erfc ⇒ Object
#exp ⇒ Object
#exp10 ⇒ Object
#exp2 ⇒ Object
#expm1 ⇒ Object
#finite? ⇒ Boolean
#floor ⇒ Object
#floor! ⇒ Object
#gamma ⇒ Object
#infinite? ⇒ Boolean
#j0 ⇒ Object
#j1 ⇒ Object
#jn ⇒ Object
#li2 ⇒ Object
#lngamma ⇒ Object
#log ⇒ Object
Special Functions
#log10 ⇒ Object
#log1p ⇒ Object
“fac”, r_gmpfr_fac
#log2 ⇒ Object
#nan? ⇒ Boolean
Comparison Functions
#neg! ⇒ Object
#number? ⇒ Boolean
#prec ⇒ Object
#prec= ⇒ Object
#prec_raw= ⇒ Object
#rec_sqrt ⇒ Object
#regular? ⇒ Boolean
#sec ⇒ Object
“sin_cos”, r_gmpfr_sin_cos
#sech ⇒ Object
“sinh_cosh”, r_gmpfr_sinh_cosh
#sgn ⇒ Object
#sin ⇒ Object
#sinh ⇒ Object
#sqrt ⇒ Object
Basic Arithmetic Functions
#tan ⇒ Object
#tanh ⇒ Object
#to_d ⇒ Object Also known as: to_f
#to_s ⇒ Object
Converting Floats