summaryrefslogtreecommitdiff
path: root/spec/ruby/optional/capi/ext/numeric_spec.c
blob: d3639580a8050435ec3ade29afe6964b71ee645b (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
#include "ruby.h"
#include "rubyspec.h"

#ifdef __cplusplus
extern "C" {
#endif

static VALUE numeric_spec_size_of_VALUE(VALUE self) {
  return INT2FIX(sizeof(VALUE));
}

static VALUE numeric_spec_size_of_long_long(VALUE self) {
  return INT2FIX(sizeof(LONG_LONG));
}

static VALUE numeric_spec_NUM2CHR(VALUE self, VALUE value) {
  return INT2FIX(NUM2CHR(value));
}

static VALUE numeric_spec_rb_int2inum_14(VALUE self) {
  return rb_int2inum(14);
}

static VALUE numeric_spec_rb_uint2inum_14(VALUE self) {
  return rb_uint2inum(14);
}

static VALUE numeric_spec_rb_uint2inum_n14(VALUE self) {
  return rb_uint2inum(-14);
}

static VALUE numeric_spec_rb_Integer(VALUE self, VALUE str) {
  return rb_Integer(str);
}

static VALUE numeric_spec_rb_ll2inum_14(VALUE self) {
  return rb_ll2inum(14);
}

static VALUE numeric_spec_rb_ull2inum_14(VALUE self) {
  return rb_ull2inum(14);
}

static VALUE numeric_spec_rb_ull2inum_n14(VALUE self) {
  return rb_ull2inum(-14);
}

static VALUE numeric_spec_NUM2DBL(VALUE self, VALUE num) {
  return rb_float_new(NUM2DBL(num));
}

static VALUE numeric_spec_NUM2INT(VALUE self, VALUE num) {
  return LONG2NUM(NUM2INT(num));
}

static VALUE numeric_spec_INT2NUM(VALUE self, VALUE num) {
  return INT2NUM(NUM2INT(num));
}

static VALUE numeric_spec_NUM2LONG(VALUE self, VALUE num) {
  return LONG2NUM(NUM2LONG(num));
}

static VALUE numeric_spec_NUM2SHORT(VALUE self, VALUE num) {
  return LONG2NUM(NUM2SHORT(num));
}

static VALUE numeric_spec_NUM2UINT(VALUE self, VALUE num) {
  return ULONG2NUM(NUM2UINT(num));
}

static VALUE numeric_spec_NUM2ULONG(VALUE self, VALUE num) {
  return ULONG2NUM(NUM2ULONG(num));
}

static VALUE numeric_spec_rb_num_zerodiv(VALUE self) {
  rb_num_zerodiv();
  return Qnil;
}

static VALUE numeric_spec_rb_cmpint(VALUE self, VALUE val, VALUE b) {
  return INT2FIX(rb_cmpint(val, val, b));
}

static VALUE numeric_spec_rb_num_coerce_bin(VALUE self, VALUE x, VALUE y, VALUE op) {
  return rb_num_coerce_bin(x, y, SYM2ID(op));
}

static VALUE numeric_spec_rb_num_coerce_cmp(VALUE self, VALUE x, VALUE y, VALUE op) {
  return rb_num_coerce_cmp(x, y, SYM2ID(op));
}

static VALUE numeric_spec_rb_num_coerce_relop(VALUE self, VALUE x, VALUE y, VALUE op) {
  return rb_num_coerce_relop(x, y, SYM2ID(op));
}

static VALUE numeric_spec_rb_absint_singlebit_p(VALUE self, VALUE num) {
  return INT2FIX(rb_absint_singlebit_p(num));
}

void Init_numeric_spec(void) {
  VALUE cls = rb_define_class("CApiNumericSpecs", rb_cObject);
  rb_define_method(cls, "size_of_VALUE", numeric_spec_size_of_VALUE, 0);
  rb_define_method(cls, "size_of_long_long", numeric_spec_size_of_long_long, 0);
  rb_define_method(cls, "NUM2CHR", numeric_spec_NUM2CHR, 1);
  rb_define_method(cls, "rb_int2inum_14", numeric_spec_rb_int2inum_14, 0);
  rb_define_method(cls, "rb_uint2inum_14", numeric_spec_rb_uint2inum_14, 0);
  rb_define_method(cls, "rb_uint2inum_n14", numeric_spec_rb_uint2inum_n14, 0);
  rb_define_method(cls, "rb_Integer", numeric_spec_rb_Integer, 1);
  rb_define_method(cls, "rb_ll2inum_14", numeric_spec_rb_ll2inum_14, 0);
  rb_define_method(cls, "rb_ull2inum_14", numeric_spec_rb_ull2inum_14, 0);
  rb_define_method(cls, "rb_ull2inum_n14", numeric_spec_rb_ull2inum_n14, 0);
  rb_define_method(cls, "NUM2DBL", numeric_spec_NUM2DBL, 1);
  rb_define_method(cls, "NUM2INT", numeric_spec_NUM2INT, 1);
  rb_define_method(cls, "NUM2LONG", numeric_spec_NUM2LONG, 1);
  rb_define_method(cls, "NUM2SHORT", numeric_spec_NUM2SHORT, 1);
  rb_define_method(cls, "INT2NUM", numeric_spec_INT2NUM, 1);
  rb_define_method(cls, "NUM2UINT", numeric_spec_NUM2UINT, 1);
  rb_define_method(cls, "NUM2ULONG", numeric_spec_NUM2ULONG, 1);
  rb_define_method(cls, "rb_num_zerodiv", numeric_spec_rb_num_zerodiv, 0);
  rb_define_method(cls, "rb_cmpint", numeric_spec_rb_cmpint, 2);
  rb_define_method(cls, "rb_num_coerce_bin", numeric_spec_rb_num_coerce_bin, 3);
  rb_define_method(cls, "rb_num_coerce_cmp", numeric_spec_rb_num_coerce_cmp, 3);
  rb_define_method(cls, "rb_num_coerce_relop", numeric_spec_rb_num_coerce_relop, 3);
rb_define_method(cls, "rb_absint_singlebit_p", numeric_spec_rb_absint_singlebit_p, 1);
}

#ifdef __cplusplus
}
#endif