I was really impressed that my little recursive routine fpSqrtRooty was
expanded/unrolled explicitly so that there is overhead due to recursion.
Pretty cool! - Damian
// implement Newton's iteration for sqrt(s) where x is a guess
// and n is the number of iterations left to be done on 'x'
inline proc fpSqrtRoot(x : real, s : real, param n : int) : real
{
param half = 0.5;
return if n < 1 then x else fpSqrtRoot(x + half * (s / x - x), s, n -
1);
}
proc run()
{
var y = 2.0;
var x = fpSqrtRoot(1.3, 2.0, 4);
var eps = 1.0 / 8192.0;
eps *= eps;
eps *= eps;
// dump the result and show the error as a function of 'epsilon'
writeln(x, " ... ", abs(x * x / y - 1.0) / eps);
}
run();
Regards - Damian
Pacific Engineering Systems International, 277-279 Broadway, Glebe NSW 2037
Ph:+61-2-8571-0847 .. Fx:+61-2-9692-9623 | unsolicited email not wanted here
Views & opinions here are mine and not those of any past or present employer
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users