Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More efficient removing of trailing zeros #156

Open
plokhotnyuk opened this issue Apr 8, 2020 · 0 comments
Open

More efficient removing of trailing zeros #156

plokhotnyuk opened this issue Apr 8, 2020 · 0 comments

Comments

@plokhotnyuk
Copy link
Contributor

plokhotnyuk commented Apr 8, 2020

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 plokhotnyuk changed the title More efficient removing of traling zeros More efficient removing of trailing zeros Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant