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

fix #831: возведение в целую степень + тест #833

Merged
merged 1 commit into from Nov 13, 2018

Conversation

Mr-Rm
Copy link
Collaborator

@Mr-Rm Mr-Rm commented Nov 9, 2018

Остается ограничение на разрядность decimal (до 29 знаков)

{
decimal pow = 1;

while (true)
Copy link
Owner

Choose a reason for hiding this comment

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

Подсмотрел вариант while(exp), тогда цикл упростится с точки зрения читабельности.

        int res = 1;
	while (n) {
		if (n & 1)
			res *= a;
		a *= a;
		n >>= 1;
	}
	return res;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Будет лишнее умножение a *= a на последней итерации

@EvilBeaver EvilBeaver merged commit 3e505e2 into EvilBeaver:develop Nov 13, 2018
@Mr-Rm Mr-Rm deleted the fix-831 branch April 13, 2022 19:29
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

Successfully merging this pull request may close these issues.

None yet

2 participants