Skip to content

Commit 723a3fb

Browse files
Update tripleword.jl
1 parent 350d9fa commit 723a3fb

File tree

1 file changed

+73
-7
lines changed

1 file changed

+73
-7
lines changed

src/doubletriple/tripleword.jl

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ function tripleword(a::T, b::T, c::T) where {T}
5454
e0, e1 = two_sum(d0, s1)
5555
# s0, s1, s2 = vseb(e0, e1, e2)
5656
r0, e1 = two_sum(e0, e1)
57-
if e1 != 0.0
58-
s0 = r0
59-
else
60-
e1 = r0
61-
end
62-
s1, s2 = two_sum(e1, e2)
63-
return (s0, s1, s2)
57+
if e1 != 0.0
58+
s0 = r0
59+
else
60+
e1 = r0
61+
end
62+
s1, s2 = two_sum(e1, e2)
63+
return (s0, s1, s2)
6464
end
6565

6666
using SetRounding
@@ -82,3 +82,69 @@ function Float64(x0::Float64, x1::Float64, x2::Float64)
8282
end
8383
return y
8484
end
85+
86+
87+
@inline max_min(x,y) = ifelse(abs(y) < abs(x), (x,y) , (y,x))
88+
89+
function maxtomin(a::T, b::T, c::T) where {T}
90+
b, c = max_min(b, c)
91+
a, c = max_min(a, c)
92+
a, b = max_min(a, b)
93+
return a, b, c
94+
end
95+
96+
function vec_sum(x1::T, x2::T, x3::T) where {T}
97+
s3 = x3
98+
s2, e3 = two_sum(x2, s3)
99+
s1, e2 = two_sum(x1, s2)
100+
return s1,e2,e3
101+
end
102+
103+
function vecsum_errbranch(x::NTuple{3,T}) where {T}
104+
y = r = e = zeros(T, 3)
105+
j = 1
106+
e[1] = x[1]
107+
for i = 1:1
108+
r[i], t = two_sum(e[i], x[i+1])
109+
if t !== zero(T)
110+
y[j] = r[i]
111+
e[i+1] = t
112+
j += 1
113+
else
114+
e[i+1] = r[i]
115+
end
116+
end
117+
y[j], y[j+1] = two_sum(e[3], x[4])
118+
return y
119+
end
120+
121+
function fast_vecsum_errbranch(x1::T,x2::T,x3::T) where {T}
122+
y = zeros(T, 3)
123+
j = 1
124+
# e[1] = x1
125+
# i = 1
126+
r, t = two_sum(x1, x2)
127+
if t !== zero(T)
128+
y[j] = r
129+
e = t
130+
j += 1
131+
else
132+
e = r
133+
end
134+
135+
y[j], y[j+1] = two_sum(e, x3)
136+
return y
137+
end
138+
139+
function tripleword(x1::T, x2::T, x3::T) where {T}
140+
a1, a2 = two_sum(x1, x2)
141+
c1, c2 = two_sum(a1, x3)
142+
e1to3 = vec_sum(c1,c2,a2)
143+
y = vecsum_errbranch(e1to3)
144+
return (y...,)
145+
end
146+
147+
@inline function fast_tripleword(x1::T, x2::T, x3::T) where {T}
148+
a,b,c,d = maxtomin(x1,x2,x3)
149+
return fast_vecsum_errbranch(a,b,c)
150+
end

0 commit comments

Comments
 (0)