Skip to content

Commit 61ec452

Browse files
committed
Support Ruby < 2.6
1 parent 97e794a commit 61ec452

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

ext/bigdecimal/bigdecimal.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,30 @@ rb_rational_den(VALUE rat)
127127
}
128128
#endif
129129

130+
#ifndef HAVE_RB_COMPLEX_REAL
131+
static inline VALUE
132+
rb_complex_real(VALUE cmp)
133+
{
134+
#ifdef HAVE_TYPE_STRUCT_RCOMPLEX
135+
return RCOMPLEX(cmp)->real;
136+
#else
137+
return rb_funcall(cmp, rb_intern("real"), 0);
138+
#endif
139+
}
140+
#endif
141+
142+
#ifndef HAVE_RB_COMPLEX_IMAG
143+
static inline VALUE
144+
rb_complex_imag(VALUE cmp)
145+
{
146+
#ifdef HAVE_TYPE_STRUCT_RCOMPLEX
147+
return RCOMPLEX(cmp)->imag;
148+
#else
149+
return rb_funcall(cmp, rb_intern("imag"), 0);
150+
#endif
151+
}
152+
#endif
153+
130154
#define BIGDECIMAL_POSITIVE_P(bd) ((bd)->sign > 0)
131155
#define BIGDECIMAL_NEGATIVE_P(bd) ((bd)->sign < 0)
132156

ext/bigdecimal/extconf.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ def check_bigdecimal_version(gemspec_path)
3636
have_type("struct RRational", "ruby.h")
3737
have_func("rb_rational_num", "ruby.h")
3838
have_func("rb_rational_den", "ruby.h")
39+
have_type("struct RComplex", "ruby.h")
40+
have_func("rb_complex_real", "ruby.h")
41+
have_func("rb_complex_imag", "ruby.h")
3942
have_func("rb_array_const_ptr", "ruby.h")
4043
have_func("rb_sym2str", "ruby.h")
4144
have_func("rb_opts_exception_p", "ruby.h")

0 commit comments

Comments
 (0)