From 13b520d578d7e4cbfb904199574fa081458a64f8 Mon Sep 17 00:00:00 2001 From: Kenta Murata Date: Tue, 29 Dec 2020 16:34:23 +0900 Subject: [ruby/bigdecimal] Refactor to extract VpCheckException https://github.com/ruby/bigdecimal/commit/6fd171308b --- ext/bigdecimal/bigdecimal.c | 28 ++++++++++++++-------------- 1 file 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); -- cgit v1.2.3