diff --git a/src/xpu_numeric.cu b/src/xpu_numeric.cu index a395dcc9e..a1766912f 100644 --- a/src/xpu_numeric.cu +++ b/src/xpu_numeric.cu @@ -837,29 +837,6 @@ pgfn_numeric_mul(XPU_PGFUNCTION_ARGS) return true; } -INLINE_FUNCTION(int) -select_div_scale(int128_t ival) -{ - int n_digs = 0; - - assert(ival >= 0); - while (ival >= 10000) - { - ival /= 10000; - n_digs += 4; - } - if (ival >= 1000) - n_digs += 4; - else if (ival >= 100) - n_digs += 3; - else if (ival >= 10) - n_digs += 2; - else if (ival >= 1) - n_digs += 1; - - return Max(16 - n_digs, 0); -} - PUBLIC_FUNCTION(bool) pgfn_numeric_div(XPU_PGFUNCTION_ARGS) { @@ -932,7 +909,6 @@ pgfn_numeric_div(XPU_PGFUNCTION_ARGS) int128_t div = datum_b.u.value; int128_t x, ival = 0; int16_t weight = datum_a.weight - datum_b.weight; - int max_loops = -1; bool negative = false; if (rem < 0) @@ -949,16 +925,15 @@ pgfn_numeric_div(XPU_PGFUNCTION_ARGS) div = -div; } assert(rem >= 0 && div >= 0); - - ival = rem / div; - rem -= ival * div; - max_loops = select_div_scale(ival); - for (int loop=0; loop < max_loops; loop++) + for (;;) { x = rem / div; ival = 10 * ival + x; rem -= x * div; - if (rem == 0) + /* + * 999,999,999,999,999 = 0x03 8D7E A4C6 7FFF + */ + if (rem == 0 || (ival >> 50) != 0) break; rem *= 10; weight++;