time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

commit 88c079235e3b2d95963bb6f7a48296bf43f1b431
parent f0493f695552b3b76c34d5e18f2f3f14ac8e4bd9
Author: NunoSempere <nuno.sempere@protonmail.com>
Date:   Sat, 20 May 2023 21:13:51 -0400

add starting version for nim

Diffstat:
Awip/nim/hello_world/hello_world | 0
Awip/nim/hello_world/hello_world.nim | 1+
Awip/nim/hello_world/makefile | 2++
Awip/nim/samples | 0
Awip/nim/samples.nim | 34++++++++++++++++++++++++++++++++++
5 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/wip/nim/hello_world/hello_world b/wip/nim/hello_world/hello_world Binary files differ. diff --git a/wip/nim/hello_world/hello_world.nim b/wip/nim/hello_world/hello_world.nim @@ -0,0 +1 @@ +echo "Hello world" diff --git a/wip/nim/hello_world/makefile b/wip/nim/hello_world/makefile @@ -0,0 +1,2 @@ +build: hello_world.nim + nim c hello_world.nim diff --git a/wip/nim/samples b/wip/nim/samples Binary files differ. diff --git a/wip/nim/samples.nim b/wip/nim/samples.nim @@ -0,0 +1,34 @@ +import std/random +import std/math +# randomize() + +proc pow2(x:float, y:int): float = + return pow(x, float(y)) + +proc sine(x: float): float = + let n = 100 + var result = 0.0 + for i in 0..n: + let k = 2*n + 1 + let taylor = pow2(x, k)/ float(k) + result = result + taylor + return result + +proc log(x: float): float = + var y = x - 1 + var result = 0.0 + let n = 1000 + for i in 1..n: + let taylor = pow2(-1, n+1) * pow2(y, n) / float(n) + let n = 1000 + result = result + taylor + return result + +proc normal(): float = + let u1 = rand(1.0) + let u2 = rand(1.0) + let z = 1 + # see https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform#Basic_form + + +echo log(1.0)