carray 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -1
  3. data/ca_iter_block.c +32 -30
  4. data/ca_iter_dimension.c +24 -22
  5. data/ca_iter_window.c +25 -23
  6. data/ca_obj_array.c +58 -56
  7. data/ca_obj_bitarray.c +27 -27
  8. data/ca_obj_bitfield.c +46 -45
  9. data/ca_obj_block.c +77 -72
  10. data/ca_obj_fake.c +20 -20
  11. data/ca_obj_farray.c +22 -22
  12. data/ca_obj_field.c +31 -30
  13. data/ca_obj_grid.c +63 -62
  14. data/ca_obj_mapping.c +35 -32
  15. data/ca_obj_object.c +54 -54
  16. data/ca_obj_reduce.c +13 -13
  17. data/ca_obj_refer.c +42 -39
  18. data/ca_obj_repeat.c +50 -47
  19. data/ca_obj_select.c +24 -24
  20. data/ca_obj_shift.c +61 -58
  21. data/ca_obj_transpose.c +52 -51
  22. data/ca_obj_unbound_repeat.c +28 -27
  23. data/ca_obj_window.c +77 -72
  24. data/carray.gemspec +0 -2
  25. data/carray.h +190 -163
  26. data/carray_access.c +137 -136
  27. data/carray_attribute.c +24 -13
  28. data/carray_call_cfunc.c +21 -21
  29. data/carray_cast.c +106 -110
  30. data/carray_cast_func.rb +17 -17
  31. data/carray_class.c +3 -3
  32. data/carray_conversion.c +15 -15
  33. data/carray_copy.c +27 -27
  34. data/carray_core.c +22 -21
  35. data/carray_element.c +55 -47
  36. data/carray_generate.c +32 -32
  37. data/carray_iterator.c +36 -35
  38. data/carray_loop.c +37 -37
  39. data/carray_mask.c +21 -21
  40. data/carray_math.rb +18 -18
  41. data/carray_numeric.c +1 -1
  42. data/carray_operator.c +19 -18
  43. data/carray_order.c +30 -30
  44. data/carray_random.c +34 -32
  45. data/carray_sort_addr.c +12 -12
  46. data/carray_stat.c +127 -127
  47. data/carray_stat_proc.rb +152 -141
  48. data/carray_test.c +16 -16
  49. data/carray_utils.c +58 -56
  50. data/ext/calculus/carray_calculus.c +19 -20
  51. data/ext/calculus/carray_interp.c +12 -11
  52. data/ext/fortio/lib/fortio/fortran_sequential.rb +2 -2
  53. data/ext/fortio/ruby_fortio.c +1 -1
  54. data/ext/imagemap/carray_imagemap.c +14 -14
  55. data/ext/narray/ca_wrap_narray.c +30 -21
  56. data/extconf.rb +5 -0
  57. data/lib/carray/base/basic.rb +4 -3
  58. data/lib/carray/base/serialize.rb +3 -3
  59. data/lib/carray/graphics/gnuplot.rb +10 -7
  60. data/lib/carray/io/csv.rb +14 -9
  61. data/lib/carray/io/imagemagick.rb +7 -0
  62. data/lib/carray/io/sqlite3.rb +6 -4
  63. data/mkmath.rb +20 -20
  64. data/ruby_carray.c +2 -0
  65. data/ruby_ccomplex.c +3 -3
  66. data/test/test_130.rb +23 -0
  67. data/test/test_ALL.rb +2 -1
  68. data/test/test_order.rb +3 -3
  69. data/test/test_stat.rb +2 -2
  70. data/version.h +4 -4
  71. metadata +4 -37
  72. data/examples/ex001.rb +0 -10
  73. data/examples/test-int.rb +0 -13
  74. data/lib/carray/autoload/autoload_io_excel.rb +0 -5
  75. data/lib/carray/io/excel.rb +0 -26
data/carray_attribute.c CHANGED
@@ -17,7 +17,7 @@
17
17
  /* rdoc
18
18
  class CArray
19
19
  # returns the object type (e.g. CA_OBJ_ARRAY, CA_OBJ_BLOCK, ...).
20
- # Because the object type can be known from the class of the object,
20
+ # Since the object type can be known from the class of the object,
21
21
  # this attribute method is rarely used.
22
22
  def obj_type
23
23
  end
@@ -29,7 +29,7 @@ rb_ca_obj_type (VALUE self)
29
29
  {
30
30
  CArray *ca;
31
31
  Data_Get_Struct(self, CArray, ca);
32
- return LONG2NUM(ca->obj_type);
32
+ return INT2NUM(ca->obj_type);
33
33
  }
34
34
 
35
35
  /* rdoc
@@ -45,14 +45,17 @@ rb_ca_data_type (VALUE self)
45
45
  {
46
46
  CArray *ca;
47
47
  Data_Get_Struct(self, CArray, ca);
48
- return LONG2NUM(ca->data_type);
48
+ return INT2NUM(ca->data_type);
49
49
  }
50
50
 
51
51
  /* rdoc
52
52
  class CArray
53
- # returns the rank (e.g. 1 for 1D array, 3 for 3D array, ...).
53
+ # use CArray#ndims instead of this methods after carray-1.3.0
54
54
  def rank
55
55
  end
56
+ # returns the rank (e.g. 1 for 1D array, 3 for 3D array, ...).
57
+ def ndims
58
+ end
56
59
  end
57
60
  */
58
61
 
@@ -61,7 +64,7 @@ rb_ca_rank (VALUE self)
61
64
  {
62
65
  CArray *ca;
63
66
  Data_Get_Struct(self, CArray, ca);
64
- return LONG2NUM(ca->rank);
67
+ return INT2NUM(ca->rank);
65
68
  }
66
69
 
67
70
  /* rdoc
@@ -81,7 +84,7 @@ rb_ca_bytes (VALUE self)
81
84
  {
82
85
  CArray *ca;
83
86
  Data_Get_Struct(self, CArray, ca);
84
- return LONG2NUM(ca->bytes);
87
+ return SIZE2NUM(ca->bytes);
85
88
  }
86
89
 
87
90
  /* rdoc:
@@ -103,16 +106,22 @@ rb_ca_elements (VALUE self)
103
106
  {
104
107
  CArray *ca;
105
108
  Data_Get_Struct(self, CArray, ca);
106
- return LONG2NUM(ca->elements);
109
+ return SIZE2NUM(ca->elements);
107
110
  }
108
111
 
109
112
  /* rdoc:
110
113
  class CArray
114
+ # use CArray#shape instead of this method after carray-1.3.0
111
115
  # returns the Array object contains the dimensional shape of array
112
116
  # (e.g. [2,3] for 2D 2x3 array, ...).
113
117
  def dim
114
118
  end
115
119
 
120
+ # returns the Array object contains the dimensional shape of array
121
+ # (e.g. [2,3] for 2D 2x3 array, ...).
122
+ def shape
123
+ end
124
+
116
125
  # short-hand for dim[0]
117
126
  def dim0
118
127
  end
@@ -140,7 +149,7 @@ rb_ca_dim (VALUE self)
140
149
  Data_Get_Struct(self, CArray, ca);
141
150
  dim = rb_ary_new2(ca->rank);
142
151
  for (i=0; i<ca->rank; i++) {
143
- rb_ary_store(dim, i, LONG2NUM(ca->dim[i]));
152
+ rb_ary_store(dim, i, SIZE2NUM(ca->dim[i]));
144
153
  }
145
154
  return dim;
146
155
  }
@@ -150,7 +159,7 @@ rb_ca_dim0 (VALUE self)
150
159
  {
151
160
  CArray *ca;
152
161
  Data_Get_Struct(self, CArray, ca);
153
- return INT2NUM(ca->dim[0]);
162
+ return SIZE2NUM(ca->dim[0]);
154
163
  }
155
164
 
156
165
  VALUE
@@ -158,7 +167,7 @@ rb_ca_dim1 (VALUE self)
158
167
  {
159
168
  CArray *ca;
160
169
  Data_Get_Struct(self, CArray, ca);
161
- return ( ca->rank >= 2 ) ? INT2NUM(ca->dim[1]) : Qnil;
170
+ return ( ca->rank >= 2 ) ? SIZE2NUM(ca->dim[1]) : Qnil;
162
171
  }
163
172
 
164
173
  VALUE
@@ -166,7 +175,7 @@ rb_ca_dim2 (VALUE self)
166
175
  {
167
176
  CArray *ca;
168
177
  Data_Get_Struct(self, CArray, ca);
169
- return ( ca->rank >= 3 ) ? INT2NUM(ca->dim[2]) : Qnil;
178
+ return ( ca->rank >= 3 ) ? SIZE2NUM(ca->dim[2]) : Qnil;
170
179
  }
171
180
 
172
181
  VALUE
@@ -174,7 +183,7 @@ rb_ca_dim3 (VALUE self)
174
183
  {
175
184
  CArray *ca;
176
185
  Data_Get_Struct(self, CArray, ca);
177
- return ( ca->rank >= 4 ) ? INT2NUM(ca->dim[3]) : Qnil;
186
+ return ( ca->rank >= 4 ) ? SIZE2NUM(ca->dim[3]) : Qnil;
178
187
  }
179
188
 
180
189
  /* rdoc:
@@ -859,7 +868,9 @@ Init_carray_attribute ()
859
868
  rb_define_method(rb_cCArray, "obj_type", rb_ca_obj_type, 0);
860
869
  rb_define_method(rb_cCArray, "data_type", rb_ca_data_type, 0);
861
870
  rb_define_method(rb_cCArray, "bytes", rb_ca_bytes, 0);
862
- rb_define_method(rb_cCArray, "rank", rb_ca_rank, 0);
871
+ rb_define_method(rb_cCArray, "rank", rb_ca_rank, 0);
872
+ rb_define_method(rb_cCArray, "ndim", rb_ca_rank, 0); /* after carray-1.3.0 */
873
+ rb_define_method(rb_cCArray, "shape", rb_ca_dim, 0); /* after carray-1.3.0 */
863
874
  rb_define_method(rb_cCArray, "dim", rb_ca_dim, 0);
864
875
  rb_define_method(rb_cCArray, "dim0", rb_ca_dim0, 0);
865
876
  rb_define_method(rb_cCArray, "dim1", rb_ca_dim1, 0);
data/carray_call_cfunc.c CHANGED
@@ -17,7 +17,7 @@ ca_call_cfunc_1 (void (*func)(void *p0), const char *fsync,
17
17
  VALUE rcx0)
18
18
  {
19
19
  CArray *cx0;
20
- int32_t n;
20
+ ca_size_t n;
21
21
 
22
22
  if ( strlen(fsync) != 1 ) {
23
23
  rb_raise(rb_eRuntimeError,
@@ -31,8 +31,8 @@ ca_call_cfunc_1 (void (*func)(void *p0), const char *fsync,
31
31
  {
32
32
  char *p0;
33
33
  char *q0;
34
- int32_t s0;
35
- int32_t k;
34
+ ca_size_t s0;
35
+ ca_size_t k;
36
36
  n = ca_set_iterator(1, cx0, &q0, &s0);
37
37
  s0 *= cx0->bytes;
38
38
  #ifdef _OPENMP
@@ -57,7 +57,7 @@ ca_call_cfunc_2 (void (*func)(void *p0, void *p1), const char *fsync,
57
57
  {
58
58
  CArray *cx0, *cx1;
59
59
  boolean8_t *m0 = NULL, *m;
60
- int32_t n;
60
+ ca_size_t n;
61
61
 
62
62
  if ( strlen(fsync) != 2 ) {
63
63
  rb_raise(rb_eRuntimeError,
@@ -82,8 +82,8 @@ ca_call_cfunc_2 (void (*func)(void *p0, void *p1), const char *fsync,
82
82
  {
83
83
  char *p0, *p1;
84
84
  char *q0, *q1;
85
- int32_t s0, s1;
86
- int32_t k;
85
+ ca_size_t s0, s1;
86
+ ca_size_t k;
87
87
 
88
88
  n = ca_set_iterator(2, cx0, &q0, &s0,
89
89
  cx1, &q1, &s1);
@@ -129,7 +129,7 @@ ca_call_cfunc_3 (void (*func)(void *p0, void *p1, void *p2), const char *fsync,
129
129
  {
130
130
  CArray *cx0, *cx1, *cx2;
131
131
  boolean8_t *m0 = NULL, *m;
132
- int32_t n;
132
+ ca_size_t n;
133
133
 
134
134
  if ( strlen(fsync) != 3 ) {
135
135
  rb_raise(rb_eRuntimeError,
@@ -157,8 +157,8 @@ ca_call_cfunc_3 (void (*func)(void *p0, void *p1, void *p2), const char *fsync,
157
157
  {
158
158
  char *p0, *p1, *p2;
159
159
  char *q0, *q1, *q2;
160
- int32_t s0, s1, s2;
161
- int32_t k;
160
+ ca_size_t s0, s1, s2;
161
+ ca_size_t k;
162
162
 
163
163
  n = ca_set_iterator(3, cx0, &q0, &s0,
164
164
  cx1, &q1, &s1,
@@ -209,7 +209,7 @@ ca_call_cfunc_4 (void (*func)(void *p0, void *p1, void *p2, void *p3), const cha
209
209
  {
210
210
  CArray *cx0, *cx1, *cx2, *cx3;
211
211
  boolean8_t *m0 = NULL, *m;
212
- int32_t n;
212
+ ca_size_t n;
213
213
 
214
214
  if ( strlen(fsync) != 4 ) {
215
215
  rb_raise(rb_eRuntimeError,
@@ -240,8 +240,8 @@ ca_call_cfunc_4 (void (*func)(void *p0, void *p1, void *p2, void *p3), const cha
240
240
  {
241
241
  char *p0, *p1, *p2, *p3;
242
242
  char *q0, *q1, *q2, *q3;
243
- int32_t s0, s1, s2, s3;
244
- int32_t k;
243
+ ca_size_t s0, s1, s2, s3;
244
+ ca_size_t k;
245
245
 
246
246
  n = ca_set_iterator(4, cx0, &q0, &s0,
247
247
  cx1, &q1, &s1,
@@ -298,7 +298,7 @@ ca_call_cfunc_5 (void (*func)(void*,void*,void*,void*,void*), const char *fsync,
298
298
  {
299
299
  CArray *cx0, *cx1, *cx2, *cx3, *cx4;
300
300
  boolean8_t *m0 = NULL, *m;
301
- int32_t n;
301
+ ca_size_t n;
302
302
 
303
303
  if ( strlen(fsync) != 5 ) {
304
304
  rb_raise(rb_eRuntimeError,
@@ -332,8 +332,8 @@ ca_call_cfunc_5 (void (*func)(void*,void*,void*,void*,void*), const char *fsync,
332
332
  {
333
333
  char *p0, *p1, *p2, *p3, *p4;
334
334
  char *q0, *q1, *q2, *q3, *q4;
335
- int32_t s0, s1, s2, s3, s4;
336
- int32_t k;
335
+ ca_size_t s0, s1, s2, s3, s4;
336
+ ca_size_t k;
337
337
 
338
338
  n = ca_set_iterator(5, cx0, &q0, &s0,
339
339
  cx1, &q1, &s1,
@@ -395,7 +395,7 @@ ca_call_cfunc_6 (void (*func)(void*,void*,void*,void*,void*,void*), const char *
395
395
  {
396
396
  CArray *cx0, *cx1, *cx2, *cx3, *cx4, *cx5;
397
397
  boolean8_t *m0 = NULL, *m;
398
- int32_t n;
398
+ ca_size_t n;
399
399
 
400
400
  if ( strlen(fsync) != 6 ) {
401
401
  rb_raise(rb_eRuntimeError,
@@ -432,8 +432,8 @@ ca_call_cfunc_6 (void (*func)(void*,void*,void*,void*,void*,void*), const char *
432
432
  {
433
433
  char *p0, *p1, *p2, *p3, *p4, *p5;
434
434
  char *q0, *q1, *q2, *q3, *q4, *q5;
435
- int32_t s0, s1, s2, s3, s4, s5;
436
- int32_t k;
435
+ ca_size_t s0, s1, s2, s3, s4, s5;
436
+ ca_size_t k;
437
437
 
438
438
  n = ca_set_iterator(6, cx0, &q0, &s0,
439
439
  cx1, &q1, &s1,
@@ -500,7 +500,7 @@ ca_call_cfunc_7 (void (*func)(void*,void*,void*,void*,void*,void*,void*), const
500
500
  {
501
501
  CArray *cx0, *cx1, *cx2, *cx3, *cx4, *cx5, *cx6;
502
502
  boolean8_t *m0 = NULL, *m;
503
- int32_t n;
503
+ ca_size_t n;
504
504
 
505
505
  if ( strlen(fsync) != 7 ) {
506
506
  rb_raise(rb_eRuntimeError,
@@ -540,8 +540,8 @@ ca_call_cfunc_7 (void (*func)(void*,void*,void*,void*,void*,void*,void*), const
540
540
  {
541
541
  char *p0, *p1, *p2, *p3, *p4, *p5, *p6;
542
542
  char *q0, *q1, *q2, *q3, *q4, *q5, *q6;
543
- int32_t s0, s1, s2, s3, s4, s5, s6;
544
- int32_t k;
543
+ ca_size_t s0, s1, s2, s3, s4, s5, s6;
544
+ ca_size_t k;
545
545
 
546
546
  n = ca_set_iterator(7, cx0, &q0, &s0,
547
547
  cx1, &q1, &s1,
data/carray_cast.c CHANGED
@@ -22,7 +22,7 @@ OBJ2BOOL (VALUE v)
22
22
  return 1;
23
23
  }
24
24
  else if ( rb_obj_is_kind_of(v, rb_cInteger) ) {
25
- int flag = NUM2LONG(v);
25
+ int flag = NUM2INT(v);
26
26
  if ( flag == 0 || flag == 1 ) {
27
27
  return flag;
28
28
  }
@@ -37,7 +37,7 @@ OBJ2BOOL (VALUE v)
37
37
  VALUE
38
38
  BOOL2OBJ (boolean8_t x)
39
39
  {
40
- return ( x != 0 ) ? INT2FIX(1) : INT2FIX(0);
40
+ return ( x != 0 ) ? INT2NUM(1) : INT2NUM(0);
41
41
  }
42
42
 
43
43
  double
@@ -80,7 +80,7 @@ rb_obj2long (VALUE val)
80
80
  {
81
81
  switch ( TYPE(val) ) {
82
82
  case T_FIXNUM:
83
- return FIX2LONG(val);
83
+ return NUM2LONG(val);
84
84
  case T_BIGNUM:
85
85
  return (long) NUM2LL(val);
86
86
  case T_NIL:
@@ -96,7 +96,7 @@ rb_obj2ulong (VALUE val)
96
96
  {
97
97
  switch ( TYPE(val) ) {
98
98
  case T_FIXNUM:
99
- return FIX2ULONG(val);
99
+ return NUM2ULONG(val);
100
100
  case T_BIGNUM:
101
101
  return (unsigned long) rb_num2ull(val);
102
102
  case T_NIL:
@@ -112,7 +112,7 @@ rb_obj2ll (VALUE val)
112
112
  {
113
113
  switch ( TYPE(val) ) {
114
114
  case T_FIXNUM:
115
- return FIX2LONG(val);
115
+ return NUM2LONG(val);
116
116
  case T_NIL:
117
117
  rb_raise(rb_eTypeError, "no implicit conversion fron nil to integer");
118
118
  break;
@@ -126,7 +126,7 @@ rb_obj2ull (VALUE val)
126
126
  {
127
127
  switch ( TYPE(val) ) {
128
128
  case T_FIXNUM:
129
- return FIX2ULONG(val);
129
+ return NUM2ULONG(val);
130
130
  case T_NIL:
131
131
  rb_raise(rb_eTypeError, "no implicit conversion from nil to integer");
132
132
  break;
@@ -136,7 +136,7 @@ rb_obj2ull (VALUE val)
136
136
  }
137
137
 
138
138
  void
139
- ca_cast_block (int32_t n, void *ap1, void *ptr1,
139
+ ca_cast_block (ca_size_t n, void *ap1, void *ptr1,
140
140
  void *ap2, void *ptr2)
141
141
  {
142
142
  CArray *ca1 = (CArray *) ap1;
@@ -149,7 +149,7 @@ ca_cast_block (int32_t n, void *ap1, void *ptr1,
149
149
  }
150
150
 
151
151
  void
152
- ca_cast_block_with_mask (int32_t n, void *ap1, void *ptr1,
152
+ ca_cast_block_with_mask (ca_size_t n, void *ap1, void *ptr1,
153
153
  void *ap2, void *ptr2, boolean8_t *m)
154
154
  {
155
155
  CArray *ca1 = (CArray *) ap1;
@@ -251,7 +251,7 @@ rb_ca_data_class_to_object (VALUE self)
251
251
  }
252
252
 
253
253
  static VALUE
254
- rb_ca_object_to_data_class (VALUE self, VALUE rtype, int32_t bytes)
254
+ rb_ca_object_to_data_class (VALUE self, VALUE rtype, ca_size_t bytes)
255
255
  {
256
256
  volatile VALUE obj, rval;
257
257
  CArray *ca;
@@ -289,11 +289,11 @@ rb_ca_to_type_internal (int argc, VALUE *argv, VALUE self)
289
289
  volatile VALUE obj, rtype = Qnil, ropt, rbytes = Qnil;
290
290
  CArray *ca, *cb;
291
291
  int8_t data_type;
292
- int32_t bytes;
292
+ ca_size_t bytes;
293
293
 
294
294
  Data_Get_Struct(self, CArray, ca);
295
295
 
296
- rb_scan_args(argc, argv, "11", &rtype, &ropt);
296
+ rb_scan_args(argc, argv, "11", (VALUE *) &rtype, (VALUE *) &ropt);
297
297
  rb_scan_options(ropt, "bytes", &rbytes);
298
298
 
299
299
  rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
@@ -425,9 +425,9 @@ rb_ca_as_type_internal (int argc, VALUE *argv, VALUE self)
425
425
  volatile VALUE obj, rtype = Qnil, ropt, rbytes = Qnil;
426
426
  CArray *ca;
427
427
  int8_t data_type;
428
- int32_t bytes;
428
+ ca_size_t bytes;
429
429
 
430
- rb_scan_args(argc, argv, "11", &rtype, &ropt);
430
+ rb_scan_args(argc, argv, "11", (VALUE *) &rtype, (VALUE *) &ropt);
431
431
  rb_scan_options(ropt, "bytes", &rbytes);
432
432
 
433
433
  rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
@@ -470,7 +470,7 @@ rb_ca_as_fixlen (int argc, VALUE *argv, VALUE self)
470
470
  {
471
471
  volatile VALUE rtype, ropt = rb_pop_options(&argc, &argv);
472
472
  VALUE list[2];
473
- rb_scan_args(argc, argv, "01", &rtype);
473
+ rb_scan_args(argc, argv, "01", (VALUE *) &rtype);
474
474
  list[0] = ( NIL_P(rtype) ) ? INT2NUM(CA_FIXLEN) : rtype;
475
475
  list[1] = ropt;
476
476
  return rb_ca_as_type_internal(2, list, self);
@@ -530,7 +530,7 @@ VALUE rb_ca_as_type_method(VALUE, CA_OBJECT);
530
530
  /* ------------------------------------------------------------------------*/
531
531
 
532
532
  VALUE
533
- rb_ca_cast_block (int32_t n, VALUE ra1, void *ptr1,
533
+ rb_ca_cast_block (ca_size_t n, VALUE ra1, void *ptr1,
534
534
  VALUE ra2, void *ptr2)
535
535
  {
536
536
  CArray *ca1, *ca2;
@@ -652,7 +652,7 @@ static VALUE
652
652
  rb_ca_s_wrap_writable (int argc, VALUE *argv, VALUE klass)
653
653
  {
654
654
  volatile VALUE obj, rtype;
655
- rb_scan_args(argc, argv, "11", &obj, &rtype);
655
+ rb_scan_args(argc, argv, "11", (VALUE *) &obj, (VALUE *) &rtype);
656
656
  return rb_ca_wrap_writable(obj, rtype);
657
657
  }
658
658
 
@@ -770,7 +770,7 @@ static VALUE
770
770
  rb_ca_s_wrap_readonly (int argc, VALUE *argv, VALUE klass)
771
771
  {
772
772
  volatile VALUE obj, rtype;
773
- rb_scan_args(argc, argv, "11", &obj, &rtype);
773
+ rb_scan_args(argc, argv, "11", (VALUE *) &obj, (VALUE *) &rtype);
774
774
  return rb_ca_wrap_readonly(obj, rtype);
775
775
  }
776
776
 
@@ -781,15 +781,8 @@ rb_ca_cast (volatile VALUE self)
781
781
  if ( ! rb_obj_is_carray(obj) ) {
782
782
  switch ( TYPE(obj) ) {
783
783
  case T_FIXNUM:
784
- obj = rb_cscalar_new_with_value(CA_INT32, 0, obj);
785
- break;
786
784
  case T_BIGNUM:
787
- if ( ca_valid[CA_INT64] ) {
788
- obj = rb_cscalar_new_with_value(CA_INT64, 0, obj);
789
- }
790
- else {
791
- obj = rb_cscalar_new_with_value(CA_INT32, 0, obj);
792
- }
785
+ obj = rb_cscalar_new_with_value(CA_INT64, 0, obj);
793
786
  break;
794
787
  case T_FLOAT:
795
788
  obj = rb_cscalar_new_with_value(CA_FLOAT64, 0, obj);
@@ -837,37 +830,37 @@ rb_ca_cast_self_or_other (volatile VALUE *self, volatile VALUE *other)
837
830
  self_is_object = 1;
838
831
  if ( rb_ca_is_object_type(*other) ) {
839
832
  *self = rb_cscalar_new_with_value(CA_OBJECT, 0, *self);
840
- return;
841
833
  }
842
- switch ( TYPE(*self) ) {
843
- case T_FIXNUM:
844
- *self = rb_cscalar_new_with_value(CA_INT32, 0, *self);
845
- break;
846
- case T_BIGNUM:
847
- if ( ca_valid[CA_INT64] ) {
848
- *self = rb_cscalar_new_with_value(CA_INT64, 0, *self);
849
- }
850
- else {
851
- *self = rb_cscalar_new_with_value(CA_INT32, 0, *self);
852
- }
853
- break;
854
- case T_FLOAT:
834
+ else if ( rb_ca_is_float_type(*other) ) {
855
835
  *self = rb_cscalar_new_with_value(CA_FLOAT64, 0, *self);
856
- break;
857
- case T_TRUE:
858
- case T_FALSE:
859
- *self = rb_cscalar_new_with_value(CA_BOOLEAN, 0, *self);
860
- break;
861
- default:
836
+ }
862
837
  #ifdef HAVE_COMPLEX_H
863
- if ( rb_obj_is_kind_of(*self, rb_cCComplex) ) {
864
- *self = rb_cscalar_new_with_value(CA_CMPLX128, 0, *self);
838
+ else if ( rb_ca_is_complex_type(*other) ) {
839
+ *self = rb_cscalar_new_with_value(CA_CMPLX128, 0, *self);
840
+ }
841
+ #endif
842
+ else {
843
+ switch ( TYPE(*self) ) {
844
+ case T_FIXNUM:
845
+ *self = rb_cscalar_new_with_value(CA_INT64, 0, *self);
846
+ break;
847
+ case T_FLOAT:
848
+ *self = rb_cscalar_new_with_value(CA_FLOAT64, 0, *self);
849
+ break;
850
+ case T_TRUE:
851
+ case T_FALSE:
852
+ *self = rb_cscalar_new_with_value(CA_BOOLEAN, 0, *self);
853
+ break;
854
+ default:
855
+ #ifdef HAVE_COMPLEX_H
856
+ if ( rb_obj_is_kind_of(*self, rb_cCComplex) ) {
857
+ *self = rb_cscalar_new_with_value(CA_CMPLX128, 0, *self);
858
+ break;
859
+ }
860
+ #endif
861
+ *self = rb_cscalar_new_with_value(CA_OBJECT, 0, *self);
865
862
  break;
866
863
  }
867
- #endif
868
-
869
- *self = rb_cscalar_new_with_value(CA_OBJECT, 0, *self);
870
- break;
871
864
  }
872
865
  }
873
866
 
@@ -876,38 +869,38 @@ rb_ca_cast_self_or_other (volatile VALUE *self, volatile VALUE *other)
876
869
 
877
870
  if ( rb_ca_is_object_type(*self) ) {
878
871
  *other = rb_cscalar_new_with_value(CA_OBJECT, 0, *other);
879
- return;
880
872
  }
881
-
882
- switch ( TYPE(*other) ) {
883
- case T_FIXNUM:
884
- *other = rb_cscalar_new_with_value(CA_INT32, 0, *other);
885
- break;
886
- case T_BIGNUM:
887
- if ( ca_valid[CA_INT64] ) {
888
- *other = rb_cscalar_new_with_value(CA_INT64, 0, *other);
889
- }
890
- else {
891
- *other = rb_cscalar_new_with_value(CA_INT32, 0, *other);
892
- }
893
- break;
894
- case T_FLOAT:
873
+ else if ( rb_ca_is_float_type(*self) ) {
895
874
  *other = rb_cscalar_new_with_value(CA_FLOAT64, 0, *other);
896
- break;
897
- case T_TRUE:
898
- case T_FALSE:
899
- *other = rb_cscalar_new_with_value(CA_BOOLEAN, 0, *other);
900
- break;
901
- default:
875
+ }
902
876
  #ifdef HAVE_COMPLEX_H
903
- if ( rb_obj_is_kind_of(*other, rb_cCComplex) ) {
904
- *other = rb_cscalar_new_with_value(CA_CMPLX128, 0, *other);
877
+ else if ( rb_ca_is_complex_type(*self) ) {
878
+ *other = rb_cscalar_new_with_value(CA_CMPLX128, 0, *other);
879
+ }
880
+ #endif
881
+ else {
882
+ switch ( TYPE(*other) ) {
883
+ case T_FIXNUM:
884
+ case T_BIGNUM:
885
+ *other = rb_cscalar_new_with_value(CA_INT64, 0, *other);
905
886
  break;
906
- }
887
+ case T_FLOAT:
888
+ *other = rb_cscalar_new_with_value(CA_FLOAT64, 0, *other);
889
+ break;
890
+ case T_TRUE:
891
+ case T_FALSE:
892
+ *other = rb_cscalar_new_with_value(CA_BOOLEAN, 0, *other);
893
+ break;
894
+ default:
895
+ #ifdef HAVE_COMPLEX_H
896
+ if ( rb_obj_is_kind_of(*other, rb_cCComplex) ) {
897
+ *other = rb_cscalar_new_with_value(CA_CMPLX128, 0, *other);
898
+ break;
899
+ }
907
900
  #endif
908
-
909
- *other = rb_cscalar_new_with_value(CA_OBJECT, 0, *other);
910
- break;
901
+ *other = rb_cscalar_new_with_value(CA_OBJECT, 0, *other);
902
+ break;
903
+ }
911
904
  }
912
905
  }
913
906
 
@@ -934,7 +927,7 @@ rb_ca_cast_self_or_other (volatile VALUE *self, volatile VALUE *other)
934
927
  return;
935
928
  }
936
929
  else if ( test > 0 ) {
937
- *other = rb_ca_wrap_readonly(*other, INT2FIX(ca->data_type));
930
+ *other = rb_ca_wrap_readonly(*other, INT2NUM(ca->data_type));
938
931
  return;
939
932
  }
940
933
  }
@@ -945,7 +938,7 @@ rb_ca_cast_self_or_other (volatile VALUE *self, volatile VALUE *other)
945
938
  return;
946
939
  }
947
940
  else if ( test > 0 ) {
948
- *self = rb_ca_wrap_readonly(*self, INT2FIX(cb->data_type));
941
+ *self = rb_ca_wrap_readonly(*self, INT2NUM(cb->data_type));
949
942
  return;
950
943
  }
951
944
  }
@@ -957,14 +950,14 @@ rb_ca_cast_self_or_other (volatile VALUE *self, volatile VALUE *other)
957
950
  return;
958
951
  }
959
952
  else if ( test > 0 ) {
960
- *other = rb_ca_wrap_readonly(*other, INT2FIX(ca->data_type));
953
+ *other = rb_ca_wrap_readonly(*other, INT2NUM(ca->data_type));
961
954
  return;
962
955
  }
963
956
 
964
957
  test = ca_cast_table[ca->data_type][cb->data_type];
965
958
 
966
959
  if ( test > 0 ) {
967
- *self = rb_ca_wrap_readonly(*self, INT2FIX(cb->data_type));
960
+ *self = rb_ca_wrap_readonly(*self, INT2NUM(cb->data_type));
968
961
  return;
969
962
  }
970
963
 
@@ -998,44 +991,47 @@ rb_ca_cast_other (VALUE *self, volatile VALUE *other)
998
991
  if ( ! rb_obj_is_carray(*other) ) {
999
992
  if ( rb_ca_is_object_type(*self) ) {
1000
993
  *other = rb_cscalar_new_with_value(CA_OBJECT, 0, *other);
1001
- return;
1002
994
  }
1003
- switch ( TYPE(*other) ) {
1004
- case T_FIXNUM:
1005
- *other = rb_cscalar_new_with_value(CA_INT32, 0, *other);
1006
- break;
1007
- case T_BIGNUM:
1008
- if ( ca_valid[CA_INT64] ) {
1009
- *other = rb_cscalar_new_with_value(CA_INT64, 0, *other);
1010
- }
1011
- else {
1012
- *other = rb_cscalar_new_with_value(CA_INT32, 0, *other);
1013
- }
1014
- break;
1015
- case T_FLOAT:
995
+ else if ( rb_ca_is_float_type(*self) ) {
1016
996
  *other = rb_cscalar_new_with_value(CA_FLOAT64, 0, *other);
1017
- break;
1018
- case T_TRUE:
1019
- case T_FALSE:
1020
- *other = rb_cscalar_new_with_value(CA_BOOLEAN, 0, *other);
1021
- break;
1022
- default:
997
+ }
1023
998
  #ifdef HAVE_COMPLEX_H
1024
- if ( rb_obj_is_kind_of(*other, rb_cCComplex) ) {
1025
- *other = rb_cscalar_new_with_value(CA_CMPLX128, 0, *other);
999
+ else if ( rb_ca_is_complex_type(*self) ) {
1000
+ *other = rb_cscalar_new_with_value(CA_CMPLX128, 0, *other);
1001
+ return;
1002
+ }
1003
+ #endif
1004
+ else {
1005
+ switch ( TYPE(*other) ) {
1006
+ case T_FIXNUM:
1007
+ case T_BIGNUM:
1008
+ *other = rb_cscalar_new_with_value(CA_INT64, 0, *other);
1009
+ break;
1010
+ case T_FLOAT:
1011
+ *other = rb_cscalar_new_with_value(CA_FLOAT64, 0, *other);
1012
+ break;
1013
+ case T_TRUE:
1014
+ case T_FALSE:
1015
+ *other = rb_cscalar_new_with_value(CA_BOOLEAN, 0, *other);
1016
+ break;
1017
+ default:
1018
+ #ifdef HAVE_COMPLEX_H
1019
+ if ( rb_obj_is_kind_of(*other, rb_cCComplex) ) {
1020
+ *other = rb_cscalar_new_with_value(CA_CMPLX128, 0, *other);
1021
+ break;
1022
+ }
1023
+ #endif
1024
+ *other = rb_cscalar_new_with_value(CA_OBJECT, 0, *other);
1026
1025
  break;
1027
1026
  }
1028
- #endif
1029
- *other = rb_cscalar_new_with_value(CA_OBJECT, 0, *other);
1030
- break;
1031
1027
  }
1032
-
1028
+
1033
1029
  Data_Get_Struct(*other, CScalar, cs);
1034
1030
 
1035
1031
  test0 = ca_cast_table2[cs->data_type][ca->data_type];
1036
1032
 
1037
1033
  if ( test0 > 0 ) {
1038
- *other = rb_ca_wrap_readonly(*other, INT2FIX(ca->data_type));
1034
+ *other = rb_ca_wrap_readonly(*other, INT2NUM(ca->data_type));
1039
1035
  }
1040
1036
 
1041
1037
  }
@@ -1053,7 +1049,7 @@ rb_ca_cast_other (VALUE *self, volatile VALUE *other)
1053
1049
  return;
1054
1050
  }
1055
1051
  else if ( test1 > 0 ) {
1056
- *other = rb_ca_wrap_readonly(*other, INT2FIX(ca->data_type));
1052
+ *other = rb_ca_wrap_readonly(*other, INT2NUM(ca->data_type));
1057
1053
  return;
1058
1054
  }
1059
1055