2011-11-14 03:45:47 +00:00
|
|
|
#include <ruby.h>
|
|
|
|
|
2011-11-14 03:54:34 +00:00
|
|
|
static VALUE
|
2013-04-01 11:58:55 +00:00
|
|
|
test_num2short(VALUE obj, VALUE num)
|
2011-11-14 03:54:34 +00:00
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
sprintf(buf, "%d", NUM2SHORT(num));
|
2013-04-01 11:58:55 +00:00
|
|
|
return rb_str_new_cstr(buf);
|
2011-11-14 03:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2013-04-01 11:58:55 +00:00
|
|
|
test_num2ushort(VALUE obj, VALUE num)
|
2011-11-14 03:54:34 +00:00
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
sprintf(buf, "%u", NUM2USHORT(num));
|
2013-04-01 11:58:55 +00:00
|
|
|
return rb_str_new_cstr(buf);
|
2011-11-14 03:54:34 +00:00
|
|
|
}
|
|
|
|
|
2011-11-14 03:45:47 +00:00
|
|
|
static VALUE
|
2013-04-01 11:58:55 +00:00
|
|
|
test_num2int(VALUE obj, VALUE num)
|
2011-11-14 03:45:47 +00:00
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
sprintf(buf, "%d", NUM2INT(num));
|
2013-04-01 11:58:55 +00:00
|
|
|
return rb_str_new_cstr(buf);
|
2011-11-14 03:45:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2013-04-01 11:58:55 +00:00
|
|
|
test_num2uint(VALUE obj, VALUE num)
|
2011-11-14 03:45:47 +00:00
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
sprintf(buf, "%u", NUM2UINT(num));
|
2013-04-01 11:58:55 +00:00
|
|
|
return rb_str_new_cstr(buf);
|
2011-11-14 03:45:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2013-04-01 11:58:55 +00:00
|
|
|
test_num2long(VALUE obj, VALUE num)
|
2011-11-14 03:45:47 +00:00
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
sprintf(buf, "%ld", NUM2LONG(num));
|
2013-04-01 11:58:55 +00:00
|
|
|
return rb_str_new_cstr(buf);
|
2011-11-14 03:45:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2013-04-01 11:58:55 +00:00
|
|
|
test_num2ulong(VALUE obj, VALUE num)
|
2011-11-14 03:45:47 +00:00
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
sprintf(buf, "%lu", NUM2ULONG(num));
|
2013-04-01 11:58:55 +00:00
|
|
|
return rb_str_new_cstr(buf);
|
2011-11-14 03:45:47 +00:00
|
|
|
}
|
|
|
|
|
2012-03-18 15:21:04 +00:00
|
|
|
#ifdef HAVE_LONG_LONG
|
2011-11-14 03:45:47 +00:00
|
|
|
static VALUE
|
2013-04-01 11:58:55 +00:00
|
|
|
test_num2ll(VALUE obj, VALUE num)
|
2011-11-14 03:45:47 +00:00
|
|
|
{
|
|
|
|
char buf[128];
|
2012-03-18 15:21:04 +00:00
|
|
|
sprintf(buf, "%"PRI_LL_PREFIX"d", NUM2LL(num));
|
2013-04-01 11:58:55 +00:00
|
|
|
return rb_str_new_cstr(buf);
|
2011-11-14 03:45:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2013-04-01 11:58:55 +00:00
|
|
|
test_num2ull(VALUE obj, VALUE num)
|
2011-11-14 03:45:47 +00:00
|
|
|
{
|
|
|
|
char buf[128];
|
2012-03-18 15:21:04 +00:00
|
|
|
sprintf(buf, "%"PRI_LL_PREFIX"u", NUM2ULL(num));
|
2013-04-01 11:58:55 +00:00
|
|
|
return rb_str_new_cstr(buf);
|
2011-11-14 03:45:47 +00:00
|
|
|
}
|
2012-03-18 15:21:04 +00:00
|
|
|
#endif
|
2011-11-14 03:45:47 +00:00
|
|
|
|
2013-03-31 16:14:15 +00:00
|
|
|
static VALUE
|
2013-04-01 11:58:55 +00:00
|
|
|
test_fix2short(VALUE obj, VALUE num)
|
2013-03-31 16:14:15 +00:00
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
sprintf(buf, "%d", FIX2SHORT(num));
|
2013-04-01 11:58:55 +00:00
|
|
|
return rb_str_new_cstr(buf);
|
2013-03-31 16:14:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2013-04-01 11:58:55 +00:00
|
|
|
test_fix2int(VALUE obj, VALUE num)
|
2013-03-31 16:14:15 +00:00
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
sprintf(buf, "%d", FIX2INT(num));
|
2013-04-01 11:58:55 +00:00
|
|
|
return rb_str_new_cstr(buf);
|
2013-03-31 16:14:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2013-04-01 11:58:55 +00:00
|
|
|
test_fix2uint(VALUE obj, VALUE num)
|
2013-03-31 16:14:15 +00:00
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
sprintf(buf, "%u", FIX2UINT(num));
|
2013-04-01 11:58:55 +00:00
|
|
|
return rb_str_new_cstr(buf);
|
2013-03-31 16:14:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2013-04-01 11:58:55 +00:00
|
|
|
test_fix2long(VALUE obj, VALUE num)
|
2013-03-31 16:14:15 +00:00
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
sprintf(buf, "%ld", FIX2LONG(num));
|
2013-04-01 11:58:55 +00:00
|
|
|
return rb_str_new_cstr(buf);
|
2013-03-31 16:14:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2013-04-01 11:58:55 +00:00
|
|
|
test_fix2ulong(VALUE obj, VALUE num)
|
2013-03-31 16:14:15 +00:00
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
sprintf(buf, "%lu", FIX2ULONG(num));
|
2013-04-01 11:58:55 +00:00
|
|
|
return rb_str_new_cstr(buf);
|
2013-03-31 16:14:15 +00:00
|
|
|
}
|
|
|
|
|
2011-11-14 03:45:47 +00:00
|
|
|
void
|
|
|
|
Init_num2int(void)
|
|
|
|
{
|
2013-04-02 10:26:02 +00:00
|
|
|
VALUE mNum2int = rb_define_module("Num2int");
|
2011-11-14 03:45:47 +00:00
|
|
|
|
2013-04-02 10:26:02 +00:00
|
|
|
rb_define_module_function(mNum2int, "NUM2SHORT", test_num2short, 1);
|
|
|
|
rb_define_module_function(mNum2int, "NUM2USHORT", test_num2ushort, 1);
|
2011-11-14 03:54:34 +00:00
|
|
|
|
2013-04-02 10:26:02 +00:00
|
|
|
rb_define_module_function(mNum2int, "NUM2INT", test_num2int, 1);
|
|
|
|
rb_define_module_function(mNum2int, "NUM2UINT", test_num2uint, 1);
|
|
|
|
|
|
|
|
rb_define_module_function(mNum2int, "NUM2LONG", test_num2long, 1);
|
|
|
|
rb_define_module_function(mNum2int, "NUM2ULONG", test_num2ulong, 1);
|
2011-11-14 03:45:47 +00:00
|
|
|
|
2012-03-18 15:21:04 +00:00
|
|
|
#ifdef HAVE_LONG_LONG
|
2013-04-02 10:26:02 +00:00
|
|
|
rb_define_module_function(mNum2int, "NUM2LL", test_num2ll, 1);
|
|
|
|
rb_define_module_function(mNum2int, "NUM2ULL", test_num2ull, 1);
|
2012-03-18 15:21:04 +00:00
|
|
|
#endif
|
2013-03-31 16:14:15 +00:00
|
|
|
|
2013-04-02 10:26:02 +00:00
|
|
|
rb_define_module_function(mNum2int, "FIX2SHORT", test_fix2short, 1);
|
2013-03-31 16:14:15 +00:00
|
|
|
|
2013-04-02 10:26:02 +00:00
|
|
|
rb_define_module_function(mNum2int, "FIX2INT", test_fix2int, 1);
|
|
|
|
rb_define_module_function(mNum2int, "FIX2UINT", test_fix2uint, 1);
|
2013-03-31 16:14:15 +00:00
|
|
|
|
2013-04-02 10:26:02 +00:00
|
|
|
rb_define_module_function(mNum2int, "FIX2LONG", test_fix2long, 1);
|
|
|
|
rb_define_module_function(mNum2int, "FIX2ULONG", test_fix2ulong, 1);
|
2011-11-14 03:45:47 +00:00
|
|
|
}
|
|
|
|
|