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

Calculating the N-th Root Correctly #6806

Closed
imambungo opened this issue Apr 23, 2019 · 2 comments
Closed

Calculating the N-th Root Correctly #6806

imambungo opened this issue Apr 23, 2019 · 2 comments

Comments

@imambungo
Copy link

public double calculateTheOldWay(double base, double n) {
	return Math.pow(base, 1.0/n);
}

the solution above gives correct answers more often than the solution from the article below:

public Double calculate(Double base, Double n) {
    return Math.pow(Math.E, Math.log(base)/n);
}

 
I just tested both solutions here. It turns out that, for base ranged from 2 to 10000 and n ranged from 2 to 8, the Math.log solution gives 26 correct answers and 114 wrong answers while Math.pow solution gives 119 correct answers and 21 wrong answers as seen in the result.

@eric-martin
Copy link
Collaborator

@imambungo We have logged an internal ticket to update the article. I'll keep this ticket updated with our progress.

@maibin
Copy link
Collaborator

maibin commented Oct 17, 2019

@imambungo the issue is fixed now, closing.
Thanks again for your feedback!

@maibin maibin closed this as completed Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants