diff --git a/wip/nim/hello_world/hello_world b/wip/nim/hello_world/hello_world new file mode 100755 index 00000000..76ebc2c1 Binary files /dev/null and b/wip/nim/hello_world/hello_world differ diff --git a/wip/nim/hello_world/hello_world.nim b/wip/nim/hello_world/hello_world.nim new file mode 100644 index 00000000..bba153ac --- /dev/null +++ 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 new file mode 100644 index 00000000..e9b55c31 --- /dev/null +++ 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 new file mode 100755 index 00000000..847b8332 Binary files /dev/null and b/wip/nim/samples differ diff --git a/wip/nim/samples.nim b/wip/nim/samples.nim new file mode 100644 index 00000000..16f1f0e3 --- /dev/null +++ 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)