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
some trigonometric algorithm #2000
Open
+135
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
| @@ -0,0 +1,135 @@ | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # package maths.py | ||||||||||||||||||||||||||||||||||||||||
| # implement some math.py | ||||||||||||||||||||||||||||||||||||||||
| # trigonometric algorithm | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Pi = 3.14159265358979323846 | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| def _abs(value): | ||||||||||||||||||||||||||||||||||||||||
| # >>> _abs(-10) | ||||||||||||||||||||||||||||||||||||||||
| # 10 | ||||||||||||||||||||||||||||||||||||||||
| # >>> _abs(10) | ||||||||||||||||||||||||||||||||||||||||
| # 10 | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+10
to
+13
|
||||||||||||||||||||||||||||||||||||||||
| return -value if value < 0 else value | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| def _power(value, n): | ||||||||||||||||||||||||||||||||||||||||
cclauss
Member
|
||||||||||||||||||||||||||||||||||||||||
| 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.
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.
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)) | |
| """ |
Comment on lines
+128
to
+135
This comment has been minimized.
This comment has been minimized.
cclauss
May 20, 2020
•
edited
Member
edited
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) |
ProTip!
Use n and p to navigate between commits in a pull request.
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.


Doctests must be in docstrings, not in comments. Please do
python3 -m docstring -v maths.pyon your computer and make sure that all tests run and pass.