From f67f196b1d89753af958249ffe7458aa2e3f42b6 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 2 Apr 2008 13:31:42 +0000 Subject: [PATCH] * 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 --- ChangeLog | 4 +++ rational.c | 73 ++++++++++++++---------------------------------------- version.h | 6 ++--- 3 files changed, 26 insertions(+), 57 deletions(-) diff --git a/ChangeLog b/ChangeLog index b6dfc05418..06aed5909d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Wed Apr 2 22:29:35 2008 Yukihiro Matsumoto + + * rational.c (nurat_int_check): function for DRY integer check. + Wed Apr 2 06:52:31 2008 Yukihiro Matsumoto * .gdbinit (rp): supports rational and complex numbers. it's diff --git a/rational.c b/rational.c index 3451fc65e5..dd5cd1046c 100644 --- a/rational.c +++ b/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)); } diff --git a/version.h b/version.h index f60ecd0324..084e9e4cd3 100644 --- a/version.h +++ b/version.h @@ -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[];