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.
Class Method Summary collapse
- .const_catalan ⇒ Object
- .const_euler ⇒ Object
- .const_log2 ⇒ Object
- .const_pi ⇒ Object
- .default_prec ⇒ Object
- .default_prec=(arg) ⇒ Object
-
.default_rounding_mode ⇒ Object
Rounding Related Functions.
- .default_rounding_mode= ⇒ Object
- .mpfr_buildopt_decimal_p ⇒ Object
- .mpfr_buildopt_tls_p ⇒ Object
-
.GMP::F.new(arg) ⇒ Object
Creates a new GMP::F float, with arg as its value, converting where necessary.
-
.sprintf2 ⇒ Object
Formatted Output Functions.
Instance Method Summary collapse
- #* ⇒ Object
- #** ⇒ Object (also: #pow)
- #+ ⇒ Object
-
#- ⇒ Object
Float Arithmetic.
- #-@ ⇒ Object
- #/ ⇒ Object (also: #divide)
- #< ⇒ Object
- #<= ⇒ Object
-
#<=> ⇒ Object
Float Comparison.
- #== ⇒ Object
- #> ⇒ Object
- #>= ⇒ Object
- #abs ⇒ Object
- #abs! ⇒ Object
- #acos ⇒ Object
- #acosh ⇒ Object
-
#agm ⇒ Object
“fms”, r_gmpfr_fms.
- #asin ⇒ Object
- #asinh ⇒ Object
- #atan ⇒ Object
- #atan2 ⇒ Object
- #atanh ⇒ Object
- #can_round? ⇒ Boolean
- #cbrt ⇒ Object
-
#ceil ⇒ Object
Miscellaneous Functions.
- #ceil! ⇒ Object
-
#coerce(arg) ⇒ Object
new method - testing.
- #cos ⇒ Object
- #cosh ⇒ Object
- #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
- #hypot ⇒ Object
- #infinite? ⇒ Boolean
- #initialize(*args) ⇒ Object constructor
-
#integer? ⇒ Boolean
“integer?”, r_gmpfr_integer_p.
- #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
- #sech ⇒ Object
- #sgn ⇒ Object
- #sin ⇒ Object
- #sin_cos ⇒ Object
- #sinh ⇒ Object
- #sinh_cosh ⇒ Object
-
#sqrt ⇒ Object
Basic Arithmetic Functions.
- #tan ⇒ Object
- #tanh ⇒ Object
- #to_d ⇒ Object (also: #to_f)
-
#to_s ⇒ Object
(also: #inspect)
Converting Floats.
- #trunc ⇒ Object
- #trunc! ⇒ Object
- #y0 ⇒ Object
- #y1 ⇒ Object
- #yn ⇒ Object
- #zero? ⇒ Boolean
- #zeta ⇒ Object
Constructor Details
#initialize(*args) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 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 |
# File 'ext/gmpf.c', line 73
VALUE r_gmpf_initialize(int argc, VALUE *argv, VALUE self)
{
MP_FLOAT *self_val, *arg_val_f;
unsigned long prec = 0;
VALUE arg;
int base = 10;
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
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) {
// TODO: FIGURE IT OUT. ACCEPT A ROUNDING MODE!
}
mpf_set_value2 (self_val, arg, base);
return Qnil;
}
#else
(void)base;
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
.const_pi ⇒ Object
.default_prec ⇒ Object
41 42 43 44 45 |
# File 'ext/gmp.c', line 41
static VALUE r_gmpfsg_get_default_prec(VALUE klass)
{
(void)klass;
return INT2NUM(mpf_get_default_prec());
}
|
.default_prec=(arg) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'ext/gmp.c', line 47
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
Rounding Related Functions
.default_rounding_mode= ⇒ Object
.mpfr_buildopt_decimal_p ⇒ Object
.mpfr_buildopt_tls_p ⇒ Object
.GMP::F.new(arg) ⇒ Object
Creates a new GMP::F float, with arg as its value, converting where necessary.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'ext/gmpf.c', line 58
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;
}
|
.sprintf2 ⇒ Object
Formatted Output Functions
Instance Method Details
#* ⇒ Object
#** ⇒ Object Also known as: pow
#+ ⇒ Object
#- ⇒ Object
Float Arithmetic
#-@ ⇒ Object
#/ ⇒ Object Also known as: divide
#< ⇒ Object
#<= ⇒ Object
#<=> ⇒ Object
Float Comparison
#== ⇒ Object
#> ⇒ Object
#>= ⇒ Object
#abs ⇒ Object
#abs! ⇒ Object
#acos ⇒ Object
#acosh ⇒ Object
#agm ⇒ Object
“fms”, r_gmpfr_fms
#asin ⇒ Object
#asinh ⇒ Object
#atan ⇒ Object
#atan2 ⇒ Object
#atanh ⇒ Object
#can_round? ⇒ Boolean
#cbrt ⇒ Object
#ceil ⇒ Object
Miscellaneous Functions
#ceil! ⇒ Object
#coerce(arg) ⇒ Object
new method - testing
36 37 38 39 |
# File 'ext/gmp.c', line 36
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
#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
#hypot ⇒ Object
#infinite? ⇒ Boolean
#integer? ⇒ Boolean
“integer?”, r_gmpfr_integer_p
#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
#sech ⇒ Object
#sgn ⇒ Object
#sin ⇒ Object
#sin_cos ⇒ Object
#sinh ⇒ Object
#sinh_cosh ⇒ Object
#sqrt ⇒ Object
Basic Arithmetic Functions
#tan ⇒ Object
#tanh ⇒ Object
#to_d ⇒ Object Also known as: to_f
#to_s ⇒ Object Also known as: inspect
Converting Floats