Module: GMP
- Defined in:
- lib/gmp.rb,
ext/gmp.c,
ext/gmpf.c,
ext/gmpq.c,
ext/gmpz.c,
ext/mprnd.c,
ext/gmpbench_timing.c
Defined Under Namespace
Classes: F, Q, RandState, Rnd, Z
Constant Summary collapse
- GMP_VERSION =
rb_str_new2(gmp_version)
- GMP_CC =
rb_str_new2(__GMP_CC)
- GMP_CFLAGS =
rb_str_new2(__GMP_CFLAGS)
- GMP_BITS_PER_LIMB =
INT2FIX(mp_bits_per_limb)
- GMP_NUMB_MAX =
ULONG2NUM(GMP_NUMB_MAX)
- MPFR_VERSION =
rb_str_new2(MPFR_VERSION_STRING)
- MPFR_VERSION_MAJOR =
INT2FIX(MPFR_VERSION_MAJOR)
- MPFR_VERSION_MINOR =
INT2FIX(MPFR_VERSION_MINOR)
- MPFR_VERSION_PATCHLEVEL =
INT2FIX(MPFR_VERSION_PATCHLEVEL)
- MPFR_PREC_MIN =
INT2FIX(MPFR_PREC_MIN)
- MPFR_PREC_MAX =
INT2FIX(MPFR_PREC_MAX)
- GMP_RNDN =
rb_funcall (cGMP_Rnd, new_id, 1, INT2FIX(0))
- GMP_RNDZ =
rb_funcall (cGMP_Rnd, new_id, 1, INT2FIX(1))
- GMP_RNDU =
rb_funcall (cGMP_Rnd, new_id, 1, INT2FIX(2))
- GMP_RNDD =
rb_funcall (cGMP_Rnd, new_id, 1, INT2FIX(3))
- MPFR_RNDN =
MPFR 3.0.0
rb_funcall (cGMP_Rnd, new_id, 1, INT2FIX(0))
- MPFR_RNDZ =
rb_funcall (cGMP_Rnd, new_id, 1, INT2FIX(1))
- MPFR_RNDU =
rb_funcall (cGMP_Rnd, new_id, 1, INT2FIX(2))
- MPFR_RNDD =
rb_funcall (cGMP_Rnd, new_id, 1, INT2FIX(3))
- MPFR_RNDA =
rb_funcall (cGMP_Rnd, new_id, 1, INT2FIX(4))
Class Method Summary collapse
- .cputime ⇒ Object
-
.GMP::F(arg) ⇒ Object
A convenience method for GMP::F.new(arg).
-
.GMP::Q(arg) ⇒ Object
A convenience method for GMP::Q.new(arg).
- .sprintf(format, *args) ⇒ Object
-
.sprintf2(format, arg) ⇒ Object
Formatted Output Functions.
- .time ⇒ Object
-
.GMP::Z(value) ⇒ Object
A convenience method for GMP::Z.new(value).
Class Method Details
.cputime ⇒ Object
48 49 50 51 52 53 |
# File 'ext/gmpbench_timing.c', line 48
VALUE
r_gmpmod_cputime (VALUE self)
{
(void)self;
return INT2FIX (cputime ());
}
|
.GMP::F(arg) ⇒ Object
A convenience method for GMP::F.new(arg).
354 355 356 357 358 |
# File 'ext/gmpf.c', line 354
VALUE r_gmpmod_f(int argc, VALUE *argv, VALUE module)
{
(void)module;
return r_gmpfsg_new(argc, argv, cGMP_F);
}
|
.GMP::Q(arg) ⇒ Object
A convenience method for GMP::Q.new(arg).
142 143 144 145 146 |
# File 'ext/gmpq.c', line 142
VALUE r_gmpmod_q(int argc, VALUE *argv, VALUE module)
{
(void)module;
return r_gmpqsg_new (argc, argv, cGMP_Q);
}
|
.sprintf(format, *args) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gmp.rb', line 13 def self.sprintf(format, *args) first_pct = format.index '%' result = format[0...first_pct] #format.gsub(/(?<!%)%[0#+ ']*[0-9]*.?[0-9]*[a-zA-Z][^%]*/) do |fragment| format.gsub(Regexp.new('(?<!%)%[0#+ \']*[0-9]*.?[0-9]*[a-zA-Z][^%]*')) do |fragment| arg = args.shift if fragment =~ /%[0#+ ']*[0-9]*.?[0-9]*[ZQF]/ result << sprintf2(fragment, arg) elsif fragment =~ /%[0#+ ']*[0-9]*.?[0-9]*[PR]/ && GMP.const_defined?(:MPFR_VERSION) result << GMP::F.sprintf2(fragment, arg) else result << (fragment % arg) end end result end |
.sprintf2(format, arg) ⇒ Object
Formatted Output Functions
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 |
# File 'ext/gmp.c', line 89
VALUE r_gmpsg_sprintf2(VALUE klass, VALUE format, VALUE arg) {
VALUE res;
char *buffer;
char *format_str;
MP_INT *arg_val_z;
MP_RAT *arg_val_q;
MP_FLOAT *arg_val_f;
(void)klass;
format_str = StringValuePtr(format);
if (GMPZ_P(arg)) {
mpz_get_struct (arg, arg_val_z);
gmp_asprintf(&buffer, format_str, arg_val_z);
} else if (GMPQ_P(arg)) {
mpq_get_struct (arg, arg_val_q);
gmp_asprintf(&buffer, format_str, arg_val_q);
} else if (GMPF_P(arg)) {
mpf_get_struct (arg, arg_val_f);
gmp_asprintf(&buffer, format_str, arg_val_f);
} else {
return format;
}
res = rb_str_new2(buffer);
free(buffer);
return res;
}
|
.time ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'ext/gmpbench_timing.c', line 55
VALUE
r_gmpmod_time (VALUE self)
{
long int __t0, __times, __t, __tmp;
(void)self;
__times = 1;
rb_need_block();
rb_yield (Qnil);
do {
__times <<= 1;
__t0 = cputime ();
for (__t = 0; __t < __times; __t++)
{rb_yield (Qnil);}
__tmp = cputime () - __t0;
} while (__tmp < 250);
return rb_float_new ((double) __tmp / __times);
}
|
.GMP::Z(value) ⇒ Object
A convenience method for GMP::Z.new(value).
776 777 778 779 780 |
# File 'ext/gmpz.c', line 776
VALUE r_gmpmod_z(int argc, VALUE *argv, VALUE module)
{
(void)module;
return r_gmpzsg_new(argc, argv, cGMP_Z);
}
|