add starting version for nim
This commit is contained in:
parent
f0493f6955
commit
88c079235e
BIN
wip/nim/hello_world/hello_world
Executable file
BIN
wip/nim/hello_world/hello_world
Executable file
Binary file not shown.
1
wip/nim/hello_world/hello_world.nim
Normal file
1
wip/nim/hello_world/hello_world.nim
Normal file
|
@ -0,0 +1 @@
|
|||
echo "Hello world"
|
2
wip/nim/hello_world/makefile
Normal file
2
wip/nim/hello_world/makefile
Normal file
|
@ -0,0 +1,2 @@
|
|||
build: hello_world.nim
|
||||
nim c hello_world.nim
|
BIN
wip/nim/samples
Executable file
BIN
wip/nim/samples
Executable file
Binary file not shown.
34
wip/nim/samples.nim
Normal file
34
wip/nim/samples.nim
Normal file
|
@ -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)
|
Loading…
Reference in New Issue
Block a user