Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upsome trigonometric algorithm #2000
Open
Conversation
maths/maths.py
Outdated
| # >>> _abs(-10) | ||
| # 10 | ||
| # >>> _abs(10) | ||
| # 10 |
Comment on lines
10
to
13
This comment has been minimized.
This comment has been minimized.
cclauss
May 20, 2020
Member
Suggested change
| # >>> _abs(-10) | |
| # 10 | |
| # >>> _abs(10) | |
| # 10 | |
| """ | |
| >>> _abs(-10) | |
| 10 | |
| >>> _abs(-.5) | |
| 0.5 | |
| >>> _abs(0) | |
| 0 | |
| >>> _abs(.5) | |
| 0.5 | |
| >>> _abs(10) | |
| 10 | |
| """ |
Doctests must be in docstrings, not in comments. Please do python3 -m docstring -v maths.py on your computer and make sure that all tests run and pass.
|
|
||
|
|
||
| # newton iteration method | ||
| def _sqrt(value): |
This comment has been minimized.
This comment has been minimized.
cclauss
May 20, 2020
Member
Suggested change
| def _sqrt(value): | |
| def _sqrt(value): | |
| """ | |
| >>> _sqrt(9) | |
| 3 | |
| >>> _sqrt(25) | |
| 5 | |
| """ |
The docstring must appear at the top of the function before any code.
maths/maths.py
Outdated
| def _tan(value): | ||
| x = _sin(value) / _cos(value) | ||
|
|
||
| # >>> _tan(90) | ||
| # 0 | ||
| # >>> _tan(45) | ||
| # 1 | ||
| return x |
Comment on lines
105
to
112
This comment has been minimized.
This comment has been minimized.
cclauss
May 20, 2020
•
Member
Suggested change
| def _tan(value): | |
| x = _sin(value) / _cos(value) | |
| # >>> _tan(90) | |
| # 0 | |
| # >>> _tan(45) | |
| # 1 | |
| return x | |
| def _tan(value): | |
| """ | |
| >>> _tan(90) | |
| 0 | |
| >>> _tan(45) | |
| 1 | |
| >>> from math import tan | |
| >>> for i in range 360: | |
| >>> assert _tan(i) == tan(i), (i, _tan(i), tan(i)) | |
| """ | |
| return _sin(value) / _cos(value) |
maths/maths.py
Outdated
|
|
||
| # factorial | ||
| def _factor(value): | ||
| # regulations 0! = 1 |
This comment has been minimized.
This comment has been minimized.
cclauss
May 20, 2020
Member
Suggested change
| # regulations 0! = 1 | |
| """ | |
| regulations 0! = 1 | |
| >>> from math import factorial | |
| >>> for i in range 360: | |
| >>> assert _factor(i) == factorial(i), (i, _factor(i), factorial(i)) | |
| """ |
| return -value if value < 0 else value | ||
|
|
||
|
|
||
| def _power(value, n): |
This comment has been minimized.
This comment has been minimized.
cclauss
May 20, 2020
•
Member
Suggested change
| def _power(value, n): | |
| def _power(value, n): | |
| """ | |
| >>> from math import pow | |
| >>> for i in range 360: | |
| >>> assert _power(10, i) == pow(10, i), (i, _power(10, i), pow(10, i)) | |
| """ |
This comment has been minimized.
This comment has been minimized.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
zhbi98 commentedMay 18, 2020
Describe your change:
Created a new file maths.py
Internally implemented some trigonometric functions, root root, factorial, power algorithm