Skip to content

Commit 54f9be8

Browse files
reduce the number of flops in c and s
Previously, integers were converted to 64-bit floating-point numbers within the square root. Now, the numerators and denominators are first calculated as integers. After converting to type T, they are divided in one flop. Thus, each c and s only involves a floating-point sqrt() and a type T division, which reduces the probability of a rounding error by about half (compared to the previous method).
1 parent 69e2c0f commit 54f9be8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/SphericalHarmonics/slowplan.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ end
4848
function Pnmp2toPlm{T}(::Type{T}, n::Int, m::Int)
4949
G = Vector{Givens{T}}(n)
5050
@inbounds for= 1:n
51-
c = sqrt((2+2m+3)/(+2m+3)*(2m+2)/(+2m+2))
52-
s = sqrt((ℓ+1)/(+2m+3)*/(ℓ+2m+2))
51+
c = sqrt(T((2m+2)*(2+2m+3))/T((+2m+2)*(ℓ+2m+3)))
52+
s = sqrt(T(ℓ*(ℓ+1))/T((+2m+2)*(ℓ+2m+3)))
5353
G[n+1-ℓ] = Givens(ℓ, ℓ+2, c, s)
5454
end
5555
Pnmp2toPlm(G)

0 commit comments

Comments
 (0)