mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
refactor: Make code more simple in maclaurin_series (#7522)
This commit is contained in:
parent
f32f78a9e0
commit
a0cbc2056e
|
@ -52,8 +52,7 @@ def maclaurin_sin(theta: float, accuracy: int = 30) -> float:
|
|||
div = theta // (2 * pi)
|
||||
theta -= 2 * div * pi
|
||||
return sum(
|
||||
(((-1) ** r) * ((theta ** (2 * r + 1)) / factorial(2 * r + 1)))
|
||||
for r in range(accuracy)
|
||||
(-1) ** r * theta ** (2 * r + 1) / factorial(2 * r + 1) for r in range(accuracy)
|
||||
)
|
||||
|
||||
|
||||
|
@ -104,12 +103,14 @@ def maclaurin_cos(theta: float, accuracy: int = 30) -> float:
|
|||
theta = float(theta)
|
||||
div = theta // (2 * pi)
|
||||
theta -= 2 * div * pi
|
||||
return sum(
|
||||
(((-1) ** r) * ((theta ** (2 * r)) / factorial(2 * r))) for r in range(accuracy)
|
||||
)
|
||||
return sum((-1) ** r * theta ** (2 * r) / factorial(2 * r) for r in range(accuracy))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import doctest
|
||||
|
||||
doctest.testmod()
|
||||
|
||||
print(maclaurin_sin(10))
|
||||
print(maclaurin_sin(-10))
|
||||
print(maclaurin_sin(10, 15))
|
||||
|
|
Loading…
Reference in New Issue
Block a user