mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* rational.c (nurat_int_check): function for DRY integer check.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15886 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
339dca41fc
commit
f67f196b1d
3 changed files with 26 additions and 57 deletions
|
@ -1,3 +1,7 @@
|
|||
Wed Apr 2 22:29:35 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* rational.c (nurat_int_check): function for DRY integer check.
|
||||
|
||||
Wed Apr 2 06:52:31 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* .gdbinit (rp): supports rational and complex numbers. it's
|
||||
|
|
73
rational.c
73
rational.c
|
@ -427,6 +427,18 @@ f_rational_new_bang2(VALUE klass, VALUE x, VALUE y)
|
|||
|
||||
#define f_unify_p(klass) rb_const_defined(klass, id_Unify)
|
||||
|
||||
static inline void
|
||||
nurat_int_check(VALUE num)
|
||||
{
|
||||
switch (TYPE(num)) {
|
||||
case T_FIXNUM:
|
||||
case T_BIGNUM:
|
||||
break;
|
||||
default:
|
||||
rb_raise(rb_eArgError, "not an integer");
|
||||
}
|
||||
}
|
||||
|
||||
inline static VALUE
|
||||
nurat_s_canonicalize_internal(VALUE klass, VALUE num, VALUE den)
|
||||
{
|
||||
|
@ -487,21 +499,8 @@ nurat_s_canonicalize(int argc, VALUE *argv, VALUE klass)
|
|||
break;
|
||||
}
|
||||
|
||||
switch (TYPE(num)) {
|
||||
case T_FIXNUM:
|
||||
case T_BIGNUM:
|
||||
break;
|
||||
default:
|
||||
rb_raise(rb_eArgError, "not an integer");
|
||||
}
|
||||
|
||||
switch (TYPE(den)) {
|
||||
case T_FIXNUM:
|
||||
case T_BIGNUM:
|
||||
break;
|
||||
default:
|
||||
rb_raise(rb_eArgError, "not an integer");
|
||||
}
|
||||
nurat_int_check(num);
|
||||
nurat_int_check(den);
|
||||
|
||||
return nurat_s_canonicalize_internal(klass, num, den);
|
||||
}
|
||||
|
@ -518,21 +517,8 @@ nurat_s_new(int argc, VALUE *argv, VALUE klass)
|
|||
break;
|
||||
}
|
||||
|
||||
switch (TYPE(num)) {
|
||||
case T_FIXNUM:
|
||||
case T_BIGNUM:
|
||||
break;
|
||||
default:
|
||||
rb_raise(rb_eArgError, "not an integer");
|
||||
}
|
||||
|
||||
switch (TYPE(den)) {
|
||||
case T_FIXNUM:
|
||||
case T_BIGNUM:
|
||||
break;
|
||||
default:
|
||||
rb_raise(rb_eArgError, "not an integer");
|
||||
}
|
||||
nurat_int_check(num);
|
||||
nurat_int_check(den);
|
||||
|
||||
return nurat_s_canonicalize_internal(klass, num, den);
|
||||
}
|
||||
|
@ -1223,42 +1209,21 @@ nurat_marshal_load(VALUE self, VALUE a)
|
|||
VALUE
|
||||
rb_gcd(VALUE self, VALUE other)
|
||||
{
|
||||
switch (TYPE(other)) {
|
||||
case T_FIXNUM:
|
||||
case T_BIGNUM:
|
||||
break;
|
||||
default:
|
||||
rb_raise(rb_eArgError, "not an integer");
|
||||
}
|
||||
|
||||
nurat_int_check(other);
|
||||
return f_gcd(self, other);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_lcm(VALUE self, VALUE other)
|
||||
{
|
||||
switch (TYPE(other)) {
|
||||
case T_FIXNUM:
|
||||
case T_BIGNUM:
|
||||
break;
|
||||
default:
|
||||
rb_raise(rb_eArgError, "not an integer");
|
||||
}
|
||||
|
||||
nurat_int_check(other);
|
||||
return f_lcm(self, other);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_gcdlcm(VALUE self, VALUE other)
|
||||
{
|
||||
switch (TYPE(other)) {
|
||||
case T_FIXNUM:
|
||||
case T_BIGNUM:
|
||||
break;
|
||||
default:
|
||||
rb_raise(rb_eArgError, "not an integer");
|
||||
}
|
||||
|
||||
nurat_int_check(other);
|
||||
return rb_assoc_new(f_gcd(self, other), f_lcm(self, other));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#define RUBY_VERSION "1.9.0"
|
||||
#define RUBY_RELEASE_DATE "2008-04-01"
|
||||
#define RUBY_RELEASE_DATE "2008-04-02"
|
||||
#define RUBY_VERSION_CODE 190
|
||||
#define RUBY_RELEASE_CODE 20080401
|
||||
#define RUBY_RELEASE_CODE 20080402
|
||||
#define RUBY_PATCHLEVEL 0
|
||||
|
||||
#define RUBY_VERSION_MAJOR 1
|
||||
|
@ -9,7 +9,7 @@
|
|||
#define RUBY_VERSION_TEENY 0
|
||||
#define RUBY_RELEASE_YEAR 2008
|
||||
#define RUBY_RELEASE_MONTH 4
|
||||
#define RUBY_RELEASE_DAY 1
|
||||
#define RUBY_RELEASE_DAY 2
|
||||
|
||||
#ifdef RUBY_EXTERN
|
||||
RUBY_EXTERN const char ruby_version[];
|
||||
|
|
Loading…
Reference in a new issue