sums.nim (476B)
1 import std/math 2 3 proc factorial(n: int): int = 4 if n == 0 or n < 0: 5 return 1 6 else: 7 return n * factorial(n - 1) 8 9 proc sine(x: float): float = 10 let n = 8 11 # ^ Taylor will converge really quickly 12 # notice that the factorial of 17 is 13 # already pretty gigantic 14 var acc = 0.0 15 for i in 0..n: 16 var k = 2*i + 1 17 var taylor = pow(-1, i.float) * pow(x, k.float) / factorial(k).float 18 acc = acc + taylor 19 return acc 20 21 echo factorial(17) 22 echo sine(1.0)