-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Factorial, Combinations & Decimal_To_Fraction Functions #654
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #654 +/- ##
==========================================
+ Coverage 94.57% 94.64% +0.06%
==========================================
Files 285 288 +3
Lines 22906 23062 +156
==========================================
+ Hits 21664 21826 +162
+ Misses 1242 1236 -6 ☔ View full report in Codecov by Sentry. |
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.
The factorial function is already implemented in this repository, could you merge it with your implementation?
|
Could you remove the factorial in hello_bigmath? It's duplicated there now |
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.
Looks good, thanks!
Factorial
This Rust code provides implementations of the factorial calculation for positive integers, both iteratively and recursively. The code includes unit tests to ensure the correctness of the functions.
Iterative Factorial Calculation (
factorial
function)The
factorial
function uses a straightforward iterative approach. It checks for base cases (0! and 1!) and, for other cases, calculates the factorial using the product of the range from 2 to the given number (inclusive). Theproduct
method is used to efficiently calculate the product of the range.Recursive Factorial Calculation (
factorial_recursive
function)The
factorial_recursive
function employs a recursive approach. It also checks for base cases and recursively calculates the factorial by multiplying the current number with the factorial of (n - 1). This recursive method provides a clear representation of the factorial definition.Combinations
Implemented a Rust version of the combinations function, which calculates the number of combinations of k elements from a set of n elements. The function now panics when provided with negative values for n or k, ensuring that only positive values are accepted.
Decimal to fraction
The decimal_to_fraction function in Rust converts decimal numbers to their simplest fraction form. It takes a floating-point number as input and returns a tuple representing the numerator and denominator of the simplified fraction.
Type of change
Please delete options that are not relevant.
Checklist:
cargo clippy --all -- -D warnings
just before my last commit and fixed any issue that was found.cargo fmt
just before my last commit.cargo test
just before my last commit and all tests passed.mod.rs
file within its own folder, and in any parent folder(s).DIRECTORY.md
with the correct link.COUNTRIBUTING.md
and my code follows its guidelines.