Class: GMP::Z
- Inherits:
-
Integer
- Object
- Integer
- GMP::Z
- Defined in:
- ext/ecm.c
Instance Method Summary collapse
-
#ecm_factor(b1, ecm_params) ⇒ Object
Search for a factor of ‘z`, using GMP-ECM’s ‘ecm_factor()` method.
Instance Method Details
#ecm_factor(b1, ecm_params) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'ext/ecm.c', line 178
VALUE r_ecm_factor (int argc, VALUE *argv, VALUE self_value) {
MP_INT *self, *res;
VALUE res_value, b1_value, params_arg, params_value;
ECM_PARAMS *params;
double b1;
int found;
(void)self;
mpz_get_struct (self_value, self);
mpz_make_struct (res_value, res);
mpz_init (res);
rb_scan_args (argc, argv, "02", &b1_value, ¶ms_arg);
if (params_arg == Qnil) {
params = NULL;
} else if (ECM_PARAMS_P (params_arg)) {
ecm_params_get_struct (params_arg, params);
} else if (TYPE (params_arg) == T_HASH) {
params_value = build_ecm_params_from_hash (params_arg);
ecm_params_get_struct (params_value, params);
} else {
rb_raise (rb_eArgError, "Second argument must be an ECMParams");
}
if (b1_value == Qnil) {
b1 = 1000000;
} else if (FIXNUM_P (b1_value)) {
b1 = (double) NUM2INT (b1_value);
} else if (FLOAT_P (b1_value)) {
b1 = NUM2DBL (b1_value);
} else {
rb_raise (rb_eArgError, "b1 argument must be a Fixnum");
}
found = ecm_factor (res, self, b1, params);
return rb_assoc_new(INT2FIX (found), res_value);
}
|