Browse Source

Add euler approximation example

David Peter 2 years ago
parent
commit
af0f856958
1 changed files with 8 additions and 0 deletions
  1. 8 0
      examples/euler_approximation.nbt

+ 8 - 0
examples/euler_approximation.nbt

@@ -0,0 +1,8 @@
+# Compute the number e from 1/0! + 1/1! + 1/2! + 1/3! + …
+
+fn approx_e(n: Scalar) -> Scalar =
+  if n == 0
+    then 1
+    else 1 / n! + approx_e(n - 1)
+
+assert_eq(approx_e(20), e, 1e-10)