summaryrefslogtreecommitdiff
path: root/ext/bigdecimal/bigdecimal.c
diff options
context:
space:
mode:
authorKenta Murata <mrkn@mrkn.jp>2019-10-09 10:27:08 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-07-06 01:15:46 +0900
commitf00efef30ad6eca30e5674493dacbd25b425a4eb (patch)
treefb772d0bb5ae51d9be23a537c1fe5825e8ec94e1 /ext/bigdecimal/bigdecimal.c
parentceb9d516c6d17b0619cf53dfba7cb7b29fe073e4 (diff)
downloadruby-f00efef30ad6eca30e5674493dacbd25b425a4eb.tar.gz
[ruby/bigdecimal] Support a Complex in Kernel.BigDecimal()
https://github.com/ruby/bigdecimal/commit/00795cb01f
Diffstat (limited to 'ext/bigdecimal/bigdecimal.c')
-rw-r--r--ext/bigdecimal/bigdecimal.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 23851eea58..3a46bd1c01 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -2629,6 +2629,7 @@ VpNewVarArg(int argc, VALUE *argv)
}
}
+ retry:
switch (TYPE(iniValue)) {
case T_DATA:
if (is_kind_of_BigDecimal(iniValue)) {
@@ -2666,6 +2667,18 @@ VpNewVarArg(int argc, VALUE *argv)
}
return GetVpValueWithPrec(iniValue, mf, 1);
+ case T_COMPLEX:
+ {
+ VALUE im;
+ im = rb_complex_imag(iniValue);
+ if (!is_zero(im)) {
+ rb_raise(rb_eArgError,
+ "Unable to make a BigDecimal from non-zero imaginary number");
+ }
+ iniValue = rb_complex_real(iniValue);
+ goto retry;
+ }
+
case T_STRING:
/* fall through */
default: