DoubleDouble.jl
DoubleDouble.jl copied to clipboard
No sqrt(Double(0.0)) and sign(Double(0.0))
Simon,
presently sqrt(Double(0.0)) and sign(Double(0.0)) throw an error. Possible remedy for sqrt is to change
# Dekker sqrt2
function sqrt{T}(x::Double{T})
if x.hi <= 0
throw(DomainError("sqrt will only return a complex result if called with a complex argument."))
end
c = sqrt(x.hi)
u = Single(c)*Single(c)
cc = (((x.hi - u.hi) - u.lo) + x.lo)*map(typeof(x.hi),0.5)/c
double(c,cc)
end
into
# Dekker sqrt2
function sqrt{T}(x::Double{T})
if x.hi = 0
return Double(zero(T))
end
if x.hi < 0
throw(DomainError("sqrt will only return a complex result if called with a complex argument."))
end
c = sqrt(x.hi)
u = Single(c)*Single(c)
cc = (((x.hi - u.hi) - u.lo) + x.lo)*map(typeof(x.hi),0.5)/c
double(c,cc)
end
Cheers, Ivan
Sounds like a good idea. (Note that you need ==
instead of =
.)
Could you please make a PR and add a test. (Of course, the tests need to be rewritten...)
Won't your suggestion be wrong if a.hi
equals 0 but a.lo
is less than 0?