-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
math: add tau constant, add factorial function #703
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
Value of Tau constant added Factorial function added, Tau constant added Factorial function added Factorial function made public Code cleaned
|
Hey None of major languages have factorials in the stdlib. Tau is fine. |
|
Python does have a factorial function in its math module. (math module docs) |
|
Indeed it does. Ok, can you make it return i64 and use for ;; loop? |
|
Done! |
| pub fn factorial(a int) i64 { | ||
| mut prod := 1 | ||
| for i:= 0; i < a; i++ { | ||
| prod = prod * (i+1) |
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.
@thescriptninja prod *= i+1
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.
Using i := 1 would be more efficient.
ntrel
left a comment
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 panic if a! is bigger than i64.max.
| pub fn factorial(a int) i64 { | ||
| mut prod := 1 | ||
| for i:= 0; i < a; i++ { | ||
| prod = prod * (i+1) |
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.
Using i := 1 would be more efficient.
|
@medvednikov maybe leave pulls open a bit longer for reviews ;-) |
ntrel
left a comment
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 also needs to panic when a < 0.
Hey! New to contributing so sorry for any errors in committing.
Added the Tau constant which is the ratio of a circle's circumference to its radius (2 * Pi)
Added the factorial function that calculates the factorial of an integer