瀏覽代碼

Add euler approximation example

David Peter 2 年之前
父節點
當前提交
af0f856958
共有 1 個文件被更改,包括 8 次插入0 次删除
  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)