Skip to content
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
wants to merge 5 commits into
base: master
from
Open

some trigonometric algorithm #2000

wants to merge 5 commits into from

Conversation

@zhbi98
Copy link

zhbi98 commented May 18, 2020

Describe your change:

Created a new file maths.py
Internally implemented some trigonometric functions, root root, factorial, power algorithm

zhbi98 added 3 commits May 20, 2020
# >>> _abs(-10)
# 10
# >>> _abs(10)
# 10
Comment on lines +10 to +13

This comment has been minimized.

Copy link
@cclauss

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.

Copy link
@cclauss

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.

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.

Copy link
@cclauss

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)

# factorial
def _factor(value):
# regulations 0! = 1

This comment has been minimized.

Copy link
@cclauss

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.

Copy link
@cclauss

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))
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.