-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
feat: Added a function for finding the least common multiple #840
Conversation
math/least_common_multiple.cpp
Outdated
@@ -0,0 +1,41 @@ | |||
// Copyright 2020 @author tjgurwara99 |
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.
Please change this to a comment structure like:
/**
* Copyright 2020 @author tjgurwara99
* @file
*
* (basic description about the program here)
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.
Everything seems to be good (apart from the above). 👍
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 suggest you to write some test cases to validate the algorithm properly, please add a function void tests()
and write some tests in this functions using assert
statements and call this function from main()
I have taken onboard all the comments and tried to fix the issues, please take a look now. |
@tjgurwara99 have a look at #807 files are very well documented in this PR, please do the documentaion in similar manner. |
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
* @params two integers x and y whose gcd we want to find. | ||
* @return greatest common divisor of x and y. | ||
*/ | ||
unsigned int gcd(unsigned int x, unsigned int y) { |
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.
Could you make another pull request in which the functions are templated?
Eg, gcd
and lcm
Function inputs can be short
, int
, long
, long long
, signed
or unsigned
.
template<typename T>
gcd(const T &a, const T &b)
{....}
Because it is a recursive function, use of const references gives a faster memory access. If the arguments cannot be made const references, that’s ok
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.
|
||
/** | ||
* Function for finding greatest common divisor of two numbers. | ||
* @params two integers x and y whose gcd we want to find. |
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.
/** | ||
* Function for finding the least common multiple of two numbers. | ||
* @params integer x and y whose lcm we want to find. | ||
* @return lcm of x and y using the relation x * y = gcd(x, y) * lcm(x, y) |
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.
You can use LaTeX syntax for math formulae in the documentation:
\f$x \cdot y = \mathrm{gcd}(x, y) \cdot /mathrm{lcm}(x, y)\f$
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 didn't know about this feature of Doxygen, thanks for pointing it out!
@tjgurwara99 This is the autogenerated documentation for this file -> link. Note:
|
@kvedala Could you show me the config file (cmake or Doxyfile) you use for Doxygen, I want to try and add that to other projects but don't seem to be able to do it. |
In my setup, the doxygen gets configured by cmake itself. -> right here |
Description of Change
I have added a function that outputs the least common multiple of two numbers.
Checklist
Notes: Function to find the least common multiple of two numbers.