diff options
author | Kenta Murata <mrkn@mrkn.jp> | 2020-12-29 16:34:23 +0900 |
---|---|---|
committer | Kenta Murata <mrkn@mrkn.jp> | 2020-12-29 17:46:36 +0900 |
commit | 13b520d578d7e4cbfb904199574fa081458a64f8 (patch) | |
tree | 7099cba37d0665eb1b5540ee0cc5baeb1b31da20 /ext/bigdecimal | |
parent | 2f42243bceb60043ca06448a2b419724be0e6d0a (diff) |
[ruby/bigdecimal] Refactor to extract VpCheckException
https://github.com/ruby/bigdecimal/commit/6fd171308b
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r-- | ext/bigdecimal/bigdecimal.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index a7b099b1bb..f659359c60 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -208,21 +208,29 @@ is_kind_of_BigDecimal(VALUE const v) return rb_typeddata_is_kind_of(v, &BigDecimal_data_type); } -static VALUE -ToValue(Real *p) +static void +VpCheckException(Real *p, bool always) { if (VpIsNaN(p)) { - VpException(VP_EXCEPTION_NaN, "Computation results to 'NaN'(Not a Number)", 0); + VpException(VP_EXCEPTION_NaN, "Computation results to 'NaN'(Not a Number)", always); } else if (VpIsPosInf(p)) { - VpException(VP_EXCEPTION_INFINITY, "Computation results to 'Infinity'", 0); + VpException(VP_EXCEPTION_INFINITY, "Computation results to 'Infinity'", always); } else if (VpIsNegInf(p)) { - VpException(VP_EXCEPTION_INFINITY, "Computation results to '-Infinity'", 0); + VpException(VP_EXCEPTION_INFINITY, "Computation results to '-Infinity'", always); } +} + +static VALUE +VpCheckGetValue(Real *p) +{ + VpCheckException(p, false); return p->obj; } +#define ToValue(p) VpCheckGetValue(p) + NORETURN(static void cannot_be_coerced_into_BigDecimal(VALUE, VALUE)); static void @@ -838,15 +846,7 @@ BigDecimal_IsFinite(VALUE self) static void BigDecimal_check_num(Real *p) { - if (VpIsNaN(p)) { - VpException(VP_EXCEPTION_NaN, "Computation results to 'NaN'(Not a Number)", 1); - } - else if (VpIsPosInf(p)) { - VpException(VP_EXCEPTION_INFINITY, "Computation results to 'Infinity'", 1); - } - else if (VpIsNegInf(p)) { - VpException(VP_EXCEPTION_INFINITY, "Computation results to '-Infinity'", 1); - } + VpCheckException(p, true); } static VALUE BigDecimal_split(VALUE self); |