summaryrefslogtreecommitdiff
path: root/ext/bigdecimal
diff options
context:
space:
mode:
authorKenta Murata <mrkn@mrkn.jp>2019-10-09 10:50:59 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-07-06 01:15:46 +0900
commit40b82afe6a20749a375d36ce17e941e890ef8b0e (patch)
treead4d44a808e4f30f9c1c17e99b50a00aca7d40d9 /ext/bigdecimal
parent03a33603c66bf6eca6937d221f87daf3f5a489f7 (diff)
[ruby/bigdecimal] Support Ruby < 2.6
https://github.com/ruby/bigdecimal/commit/61ec452599
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3295
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r--ext/bigdecimal/bigdecimal.c24
-rw-r--r--ext/bigdecimal/extconf.rb3
2 files changed, 27 insertions, 0 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 5d0fc85..3800152 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -128,6 +128,30 @@ rb_rational_den(VALUE rat)
}
#endif
+#ifndef HAVE_RB_COMPLEX_REAL
+static inline VALUE
+rb_complex_real(VALUE cmp)
+{
+#ifdef HAVE_TYPE_STRUCT_RCOMPLEX
+ return RCOMPLEX(cmp)->real;
+#else
+ return rb_funcall(cmp, rb_intern("real"), 0);
+#endif
+}
+#endif
+
+#ifndef HAVE_RB_COMPLEX_IMAG
+static inline VALUE
+rb_complex_imag(VALUE cmp)
+{
+#ifdef HAVE_TYPE_STRUCT_RCOMPLEX
+ return RCOMPLEX(cmp)->imag;
+#else
+ return rb_funcall(cmp, rb_intern("imag"), 0);
+#endif
+}
+#endif
+
#define BIGDECIMAL_POSITIVE_P(bd) ((bd)->sign > 0)
#define BIGDECIMAL_NEGATIVE_P(bd) ((bd)->sign < 0)
diff --git a/ext/bigdecimal/extconf.rb b/ext/bigdecimal/extconf.rb
index b4098fd..fc448ed 100644
--- a/ext/bigdecimal/extconf.rb
+++ b/ext/bigdecimal/extconf.rb
@@ -36,6 +36,9 @@ have_func("isfinite", "math.h")
have_type("struct RRational", "ruby.h")
have_func("rb_rational_num", "ruby.h")
have_func("rb_rational_den", "ruby.h")
+have_type("struct RComplex", "ruby.h")
+have_func("rb_complex_real", "ruby.h")
+have_func("rb_complex_imag", "ruby.h")
have_func("rb_array_const_ptr", "ruby.h")
have_func("rb_sym2str", "ruby.h")
have_func("rb_opts_exception_p", "ruby.h")