Module: GMP
- Defined in:
- lib/gmp.rb,
ext/gmp.c,
ext/gmpf.c,
ext/gmpq.c,
ext/gmpz.c,
ext/mprnd.c,
ext/gmprandstate.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 =
MPFR rounding mode roundTiesToEven for MPFR < 3.0
GMP_RNDN
- GMP_RNDZ =
MPFR rounding mode roundTowardZero for MPFR < 3.0
GMP_RNDZ
- GMP_RNDU =
MPFR rounding mode roundTowardPositive for MPFR < 3.0
GMP_RNDU
- GMP_RNDD =
MPFR rounding mode roundTowardNegative for MPFR < 3.0
GMP_RNDD
- MPFR_RNDN =
MPFR rounding mode roundTiesToEven
MPFR_RNDN
- MPFR_RNDZ =
MPFR rounding mode roundTowardZero
MPFR_RNDZ
- MPFR_RNDU =
MPFR rounding mode roundTowardPositive
MPFR_RNDU
- MPFR_RNDD =
MPFR rounding mode roundTowardNegative
MPFR_RNDU
- MPFR_RNDA =
MPFR rounding mode roundAwayFromZero
MPFR_RNDA
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).
-
.GMP::RandState(arg) ⇒ Object
A convenience method for GMP::RandState.new(arg).
- .sprintf(format, *args) ⇒ Object
-
.sprintf2(format, arg) ⇒ Object
should never get here.
- .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).
418 419 420 421 422 |
# File 'ext/gmpf.c', line 418
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).
166 167 168 169 170 |
# File 'ext/gmpq.c', line 166
VALUE r_gmpmod_q(int argc, VALUE *argv, VALUE module)
{
(void)module;
return r_gmpqsg_new (argc, argv, cGMP_Q);
}
|
.GMP::RandState(arg) ⇒ Object
A convenience method for GMP::RandState.new(arg).
118 119 120 121 122 |
# File 'ext/gmprandstate.c', line 118
VALUE r_gmpmod_randstate(int argc, VALUE *argv, VALUE module)
{
(void)module;
return r_gmprandstatesg_new(argc, argv, cGMP_RandState);
}
|
.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
should never get here
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 |
# File 'ext/gmp.c', line 91
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).
778 779 780 781 782 |
# File 'ext/gmpz.c', line 778
VALUE r_gmpmod_z(int argc, VALUE *argv, VALUE module)
{
(void)module;
return r_gmpzsg_new(argc, argv, cGMP_Z);
}
|