I defined a function as follows:
function approx_pi(n)
tot = Float64(0.0)
for i in 1:n
x = rand()
y = rand()
if x^2 + y^2 < 1
tot+=1
end
end
tot / n * 4
end
println(approx_pi(100_000_000))
I would like to use the same function but return a Float128 instead:
using Quadmath
function approx_pi(n)
tot = Float128(0.0)
for i in 1:n
x = rand()
y = rand()
if x^2 + y^2 < 1
tot+=1
end
end
tot / n * 4
end
println(approx_pi(100_000_000))
I assume there is a way to achieve that through the equivalent of C# or Java generics:
function approx_pi{T}(n)
...
end
println(approx_pi{Float128}(100_000_000))
I could not figure out how to achieve this.