Skip to content

Instantly share code, notes, and snippets.

Created May 19, 2016 14:05
Show Gist options
  • Save anonymous/8354fbab964178d5caabd84f5e2ac8e5 to your computer and use it in GitHub Desktop.
Save anonymous/8354fbab964178d5caabd84f5e2ac8e5 to your computer and use it in GitHub Desktop.
use "path:/usr/local/Cellar/gsl/1.16/lib" if osx
use "lib:gsl"
use "collections"
primitive Gsl
fun acosh(x: F64): F64 => @gsl_acosh[F64](x)
fun hypot(x: F64, y: F64): F64 => @gsl_hypot[F64](x,y)
primitive Math
// Simple double loop that uses gsl functions at each iteration
fun calc(n: USize = 50000, thin: USize = 1000, out:OutStream) =>
var x:F64 = 0.0
var y:F64 = 0.0
var iter: F64 = 0.0
out.print("Iter x y")
for i in Range(0, n) do
for j in Range(0, thin) do
x = Gsl.acosh(iter)
y = x + Gsl.hypot(1.0,x)
iter = iter + 1.0
end
out.print(i.string()+" "+x.string()+" "+y.string())
end
actor Main
new create(env:Env) =>
Math.calc(where out = env.out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment