summaryrefslogtreecommitdiff
path: root/ext/-test-/num2int
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-11-14 03:54:34 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-11-14 03:54:34 +0000
commitb2a2ba119104b0ff2b6c20611d76de924596ca5b (patch)
tree198f6b99ec7f609a64e199a9efbc6dcb1e542b1e /ext/-test-/num2int
parentd3437b7c1a496143c2bff2698082af143f5e1dc0 (diff)
* include/ruby/ruby.h: add NUM2SHORT(), NUM2USHORT() macros.
* numeric.c: ditto. * test/-ext-/num2int/test_num2int.rb: add testcases for NUM2SHORT(). * ext/-test-/num2int/num2int.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33743 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/-test-/num2int')
-rw-r--r--ext/-test-/num2int/num2int.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/ext/-test-/num2int/num2int.c b/ext/-test-/num2int/num2int.c
index a7242a9..bafb0e0 100644
--- a/ext/-test-/num2int/num2int.c
+++ b/ext/-test-/num2int/num2int.c
@@ -3,6 +3,28 @@
extern VALUE rb_stdout;
static VALUE
+print_num2short(VALUE obj, VALUE num)
+{
+ char buf[128];
+ VALUE str;
+
+ sprintf(buf, "%d", NUM2SHORT(num));
+ str = rb_str_new_cstr(buf);
+ rb_io_write(rb_stdout, str);
+}
+
+static VALUE
+print_num2ushort(VALUE obj, VALUE num)
+{
+ char buf[128];
+ VALUE str;
+
+ sprintf(buf, "%u", NUM2USHORT(num));
+ str = rb_str_new_cstr(buf);
+ rb_io_write(rb_stdout, str);
+}
+
+static VALUE
print_num2int(VALUE obj, VALUE num)
{
char buf[128];
@@ -74,6 +96,9 @@ Init_num2int(void)
{
VALUE cNum2int = rb_path2class("TestNum2int::Num2int");
+ rb_define_singleton_method(cNum2int, "print_num2short", print_num2short, 1);
+ rb_define_singleton_method(cNum2int, "print_num2ushort", print_num2ushort, 1);
+
rb_define_singleton_method(cNum2int, "print_num2int", print_num2int, 1);
rb_define_singleton_method(cNum2int, "print_num2uint", print_num2uint, 1);