ryu icon indicating copy to clipboard operation
ryu copied to clipboard

More efficient removing of trailing zeros

Open plokhotnyuk opened this issue 5 years ago • 0 comments
trafficstars

Please, consider replacing of this loop by the following code:

      while (vm % 10 == 0) {
        vm /= 10;
        vr = vm;
        lastRemovedDigit = 0;
        ++removed;
      }

Also, I think that the same kind of loop can be optimized for 64-bit values too.

The logic behind this simplification is that after passing of vp / 10 > vm / 10 and vm % 10 == 0 checks it is guarantied that vr - vm < 5.

plokhotnyuk avatar Apr 08 '20 19:04 plokhotnyuk