static VALUE nurat_s_new(int argc, VALUE *argv, VALUE klass) { VALUE num, den; switch (rb_scan_args(argc, argv, "11", &num, &den)) { case 1: num = nurat_int_value(num); den = ONE; break; default: num = nurat_int_value(num); den = nurat_int_value(den); break; } return nurat_s_canonicalize_internal(klass, num, den); }
/* * call-seq: * int.lcm(int2) -> integer * * Returns the least common multiple (always positive). 0.lcm(x) and * x.lcm(0) return zero. * * For example: * * 2.lcm(2) #=> 2 * 3.lcm(-7) #=> 21 * ((1<<31)-1).lcm((1<<61)-1) #=> 4951760154835678088235319297 */ VALUE rb_lcm(VALUE self, SEL sel, VALUE other) { other = nurat_int_value(other); return f_lcm(self, other); }
/* * call-seq: * int.gcdlcm(int2) -> array * * Returns an array; [int.gcd(int2), int.lcm(int2)]. * * For example: * * 2.gcdlcm(2) #=> [2, 2] * 3.gcdlcm(-7) #=> [1, 21] * ((1<<31)-1).gcdlcm((1<<61)-1) #=> [1, 4951760154835678088235319297] */ VALUE rb_gcdlcm(VALUE self, SEL sel, VALUE other) { other = nurat_int_value(other); return rb_assoc_new(f_gcd(self, other), f_lcm(self, other)); }
VALUE rb_gcd(VALUE self, VALUE other) { other = nurat_int_value(other); return f_gcd(self, other); }