Skip to content

Commit

Permalink
a few tweaks, prep for Base PR
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne committed Dec 12, 2017
1 parent a1b998b commit e210c07
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/KahanSummation.jl
Expand Up @@ -45,7 +45,7 @@ end
@inline function plus_kbn(x::T, y::T) where {T}
hi = x + y
nlo = abs(x) > abs(y) ? (hi - x ) - y : (hi - y) - x
TwicePrecisionN(hi, lo)
TwicePrecisionN(hi, nlo)
end
@inline function plus_kbn(x::T, y::TwicePrecisionN{T}) where {T}
hi = x + y.hi
Expand All @@ -68,15 +68,20 @@ end
TwicePrecisionN(hi, nlo)
end

Base.r_promote_type(::typeof(plus_kbn), ::Type{T}) where {T} =
TwicePrecisionN{T}

Base.convert(::Type{TwicePrecisionN{T}}, x::Number) where {T} =
TwicePrecisionN{T}(convert(T, x), zero(T))
Base.convert(::Type{T}, x::TwicePrecisionN) where {T} =
convert(T, x.hi - x.nlo)

Base.mr_empty(f, ::typeof(plus_kbn), T) = TwicePrecisionN(zero(T),zero(T))
@static if VERSION >= v"0.7.0-"
Base.mapreduce_empty(f, ::typeof(plus_kbn), T) = TwicePrecisionN(zero(T),zero(T))
Base.mapreduce_empty(::typeof(identity), ::typeof(plus_kbn), T) = TwicePrecisionN(zero(T),zero(T)) # disambiguate
Base.mapreduce_single(f, ::typeof(plus_kbn), x) = TwicePrecisionN(x, zero(x))
else
Base.r_promote_type(::typeof(plus_kbn), ::Type{T}) where {T} =
TwicePrecisionN{T}
Base.mr_empty(f, ::typeof(plus_kbn), T) = TwicePrecisionN(zero(T),zero(T))
end

singleprec(x::TwicePrecisionN{T}) where {T} = convert(T, x)

Expand Down

0 comments on commit e210c07

Please sign in to comment.