diff --git a/src/core_types.jl b/src/core_types.jl index 358266d..952a7a3 100644 --- a/src/core_types.jl +++ b/src/core_types.jl @@ -235,7 +235,7 @@ See [Wahba's problem](https://en.wikipedia.org/wiki/Wahba%27s_problem) for more function nearest_rotation(M::StaticMatrix{N,N}) where N u, _, v = svd(M) s = sign(det(u * v')) - d = @SVector ones(N-1) + d = @SVector ones(eltype(M), N-1) R = u * Diagonal(push(d,s)) * v' return RotMatrix{N}(R) end diff --git a/test/nearest_rotation.jl b/test/nearest_rotation.jl index 6bd0b86..ef52900 100644 --- a/test/nearest_rotation.jl +++ b/test/nearest_rotation.jl @@ -32,4 +32,11 @@ @test all(sort(eigvals(Symmetric(V)))[2:end] .≥ 0) end end + @testset "return eltype" begin + for T in (Float16, Float32, Float64) + M = @SMatrix randn(T, 3, 3) + R = nearest_rotation(M) + @test eltype(M) == eltype(R) + end + end end