aboutsummaryrefslogtreecommitdiffstats
path: root/ext/-test-/num2int/num2int.c
blob: f433858f7f438bd6c492fbfaafd4f53499a4c03a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include <ruby.h>

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);
    return Qnil;
}

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);
    return Qnil;
}

static VALUE
print_num2int(VALUE obj, VALUE num)
{
    char buf[128];
    VALUE str;

    sprintf(buf, "%d", NUM2INT(num));
    str = rb_str_new_cstr(buf);
    rb_io_write(rb_stdout, str);
    return Qnil;
}

static VALUE
print_num2uint(VALUE obj, VALUE num)
{
    char buf[128];
    VALUE str;

    sprintf(buf, "%u", NUM2UINT(num));
    str = rb_str_new_cstr(buf);
    rb_io_write(rb_stdout, str);
    return Qnil;
}

static VALUE
print_num2long(VALUE obj, VALUE num)
{
    char buf[128];
    VALUE str;

    sprintf(buf, "%ld", NUM2LONG(num));
    str = rb_str_new_cstr(buf);
    rb_io_write(rb_stdout, str);
    return Qnil;
}

static VALUE
print_num2ulong(VALUE obj, VALUE num)
{
    char buf[128];
    VALUE str;

    sprintf(buf, "%lu", NUM2ULONG(num));
    str = rb_str_new_cstr(buf);
    rb_io_write(rb_stdout, str);
    return Qnil;
}

#ifdef HAVE_LONG_LONG
static VALUE
print_num2ll(VALUE obj, VALUE num)
{
    char buf[128];
    VALUE str;

    sprintf(buf, "%"PRI_LL_PREFIX"d", NUM2LL(num));
    str = rb_str_new_cstr(buf);
    rb_io_write(rb_stdout, str);
    return Qnil;
}

static VALUE
print_num2ull(VALUE obj, VALUE num)
{
    char buf[128];
    VALUE str;

    sprintf(buf, "%"PRI_LL_PREFIX"u", NUM2ULL(num));
    str = rb_str_new_cstr(buf);
    rb_io_write(rb_stdout, str);
    return Qnil;
}
#endif

static VALUE
print_fix2short(VALUE obj, VALUE num)
{
    char buf[128];
    VALUE str;

    sprintf(buf, "%d", FIX2SHORT(num));
    str = rb_str_new_cstr(buf);
    rb_io_write(rb_stdout, str);
    return Qnil;
}

static VALUE
print_fix2int(VALUE obj, VALUE num)
{
    char buf[128];
    VALUE str;

    sprintf(buf, "%d", FIX2INT(num));
    str = rb_str_new_cstr(buf);
    rb_io_write(rb_stdout, str);
    return Qnil;
}

static VALUE
print_fix2uint(VALUE obj, VALUE num)
{
    char buf[128];
    VALUE str;

    sprintf(buf, "%u", FIX2UINT(num));
    str = rb_str_new_cstr(buf);
    rb_io_write(rb_stdout, str);
    return Qnil;
}

static VALUE
print_fix2long(VALUE obj, VALUE num)
{
    char buf[128];
    VALUE str;

    sprintf(buf, "%ld", FIX2LONG(num));
    str = rb_str_new_cstr(buf);
    rb_io_write(rb_stdout, str);
    return Qnil;
}

static VALUE
print_fix2ulong(VALUE obj, VALUE num)
{
    char buf[128];
    VALUE str;

    sprintf(buf, "%lu", FIX2ULONG(num));
    str = rb_str_new_cstr(buf);
    rb_io_write(rb_stdout, str);
    return Qnil;
}

void
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);

    rb_define_singleton_method(cNum2int, "print_num2long", print_num2long, 1);
    rb_define_singleton_method(cNum2int, "print_num2ulong", print_num2ulong, 1);

#ifdef HAVE_LONG_LONG
    rb_define_singleton_method(cNum2int, "print_num2ll", print_num2ll, 1);
    rb_define_singleton_method(cNum2int, "print_num2ull", print_num2ull, 1);
#endif

    rb_define_singleton_method(cNum2int, "print_fix2short", print_fix2short, 1);

    rb_define_singleton_method(cNum2int, "print_fix2int", print_fix2int, 1);
    rb_define_singleton_method(cNum2int, "print_fix2uint", print_fix2uint, 1);

    rb_define_singleton_method(cNum2int, "print_fix2long", print_fix2long, 1);
    rb_define_singleton_method(cNum2int, "print_fix2ulong", print_fix2ulong, 1);
}