Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Conversation

jcrapuchettes
Copy link
Contributor

if (number < 1_000_000_000)
return 9;

if (number < 1_000_000_000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy paste error, I believe it should be:

else
    return 10;

See also: http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10Obvious

@Hackerpilot
Copy link
Contributor

@yebblies
Copy link
Contributor

yebblies commented Jun 6, 2014

I suggest finding the maximum count first then getting the maximum digits from that. Then there is no performance concern and you can use a loop instead of the huge digits function.

@jcrapuchettes
Copy link
Contributor Author

That is a good point. I'll make that change.

@jcrapuchettes
Copy link
Contributor Author

I'll try to fix the test files this weekend or next week so that the auto-tester will pass.

@jcrapuchettes
Copy link
Contributor Author

Now the test files will not have to be changed.

@MartinNowak
Copy link
Member

You can simply use printf to achieve this formatting.
See here.

@jcrapuchettes
Copy link
Contributor Author

Thank you for the example. I've integrated it into the code.

@@ -230,6 +250,39 @@ shared static ~this()
}
}

uint digits( uint number )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uint digits( uint number)
{
    if (number < 10)
        return 1;
    return digits(number / 10) + 1;
}

@yebblies
Copy link
Contributor

Auto-merge toggled on

@yebblies
Copy link
Contributor

Auto-merge toggled off

@yebblies
Copy link
Contributor

Actually please add a test case and squash those commits together but otherwise LGTM.

@jcrapuchettes
Copy link
Contributor Author

All tests are in the dmd repository. If I create a test for this change it will need to be merged in to dmd repo, which will break the auto-tester till this code is merged. Is there any other way that this can be done?

@yebblies
Copy link
Contributor

Auto-merge toggled on

yebblies added a commit that referenced this pull request Jun 11, 2014
Issue 4153 Changed code coverage so that all lines line up in the lst file.
@yebblies yebblies merged commit 52e499b into dlang:master Jun 11, 2014
@yebblies
Copy link
Contributor

All tests are in the dmd repository. If I create a test for this change it will need to be merged in to dmd repo, which will break the auto-tester till this code is merged. Is there any other way that this can be done?

Yeah, I can just merge this first.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants