Skip to content

Commit dd24036

Browse files
committed
Reorder operations to have less divisions in _expm
1 parent 5440787 commit dd24036

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/expm.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ end
5252
z = sqrt((a-d)*(a-d) + 4.0*b*c )
5353
e = exp(a/2.0 + d/2.0 - z/2.0)
5454
f = exp(a/2.0 + d/2.0 + z/2.0)
55+
zr = 1/z
5556

56-
m11 = -(e*(a - d - z))/(2.0* z) + (f*(a - d + z))/(2.0* z)
57-
m12 = -((e * b)/z) + (f * b)/z
58-
m21 = -((e * c)/z) + (f * c)/z
59-
m22 = -(e*(-a + d - z))/(2.0* z) + (f*(-a + d + z))/(2.0* z)
57+
m11 = (-e*(a - d - z) + f*(a - d + z)) * 0.5 * zr
58+
m12 = (f-e) * b * zr
59+
m21 = (f-e) * c * zr
60+
m22 = (-e*(-a + d - z) + f*(-a + d + z)) * 0.5 * zr
6061

6162
(newtype)((m11, m21, m12, m22))
6263
end

0 commit comments

Comments
 (0)