Created
November 6, 2018 22:03
-
-
Save cossio/ccade03eae7ae7b924a75f27d30c47e0 to your computer and use it in GitHub Desktop.
midpoint of interval
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""midpoint of the interval [a,b]""" | |
function midpoint(a::Float64, b::Float64) | |
#= Based on F. Goualard. 2014, Table VII | |
DOI: 10.1145/2493882 =# | |
if !(a ≤ b) | |
return NaN | |
elseif a == -Inf | |
if b == Inf | |
return 0. | |
else | |
return nextfloat(-Inf) | |
end | |
elseif b == Inf | |
return prevfloat(Inf) | |
end | |
mid = 0.5*(a + b) | |
if isfinite(mid) | |
return mid | |
else | |
return 0.5 * a + 0.5 * b | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment