DoubleDouble.jl icon indicating copy to clipboard operation
DoubleDouble.jl copied to clipboard

No sqrt(Double(0.0)) and sign(Double(0.0))

Open ivanslapnicar opened this issue 8 years ago • 2 comments

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

ivanslapnicar avatar May 20 '16 09:05 ivanslapnicar

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...)

dpsanders avatar May 21 '16 01:05 dpsanders

Won't your suggestion be wrong if a.hi equals 0 but a.lo is less than 0?

dpsanders avatar May 21 '16 02:05 dpsanders