-
-
Notifications
You must be signed in to change notification settings - Fork 360
Small change to monte_carlo.c #501
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good, removing the radius seems fair given that its not at all necessary to calculate pi.
|
||
printf("The estimate of pi is %f\n", estimate); | ||
|
||
printf("The estimate of pi is %g\n", estimate); | ||
printf("Percentage error: %0.2f%\n", 100 * fabs(M_PI - estimate) / M_PI); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a mistake here when last fixxing. %\n needs to be %%\n otherwise we get a format warning. Also I am reconsidering limiting the decimal places of the percentage. What do you think
bool in_circle(double x, double y, double radius) { | ||
return x * x + y * y < radius * radius; | ||
bool in_circle(double x, double y) { | ||
return x * x + y * y < 1; | ||
} | ||
|
||
double monte_carlo(int samples) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we're at it, let's convert everything inside monte_carlo
from int
to unsigned
.
} | ||
|
||
double monte_carlo(int samples) { | ||
double radius = 1.0; | ||
double monte_carlo(unsigned int samples) { | ||
int count = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also be unsigned int
.
} | ||
|
||
double monte_carlo(int samples) { | ||
double radius = 1.0; | ||
double monte_carlo(unsigned int samples) { | ||
int count = 0; | ||
|
||
for (int i = 0; i < samples; ++i) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also be unsigned int
.
It looks like this code is fine? Is there anything left to be done here @berquist ? |
I am happy. |
No description provided.