Puppet Function: math::sqrt
- Defined in:
- functions/sqrt.pp
- Function type:
- Puppet Language
Summary
returns the square root of the numeric value $x.Overview
Note:
This implementation uses Newton’s method.
5 6 7 8 9 10 11 12 13 14 |
# File 'functions/sqrt.pp', line 5
function math::sqrt(Numeric $x ) >> Numeric {
if $x < 0 {
return 'NaN'
}
# let initial guess be 1.0
$value = 10.reduce(1.0) |$z,$i| {
$z - ($z*$z - $x) / (2*$z) # magic
}
$value
}
|