diff --git a/stdlib/Statistics/src/Statistics.jl b/stdlib/Statistics/src/Statistics.jl index 19e73e6ab13bf..d16340aaa4d30 100644 --- a/stdlib/Statistics/src/Statistics.jl +++ b/stdlib/Statistics/src/Statistics.jl @@ -645,8 +645,8 @@ function corm(x::AbstractVector, mx, y::AbstractVector, my) @inbounds begin # Initialize the accumulators - xx = zero(sqrt(abs2(x[1]))) - yy = zero(sqrt(abs2(y[1]))) + xx = zero(sqrt(abs2(one(x[1])))) + yy = zero(sqrt(abs2(one(y[1])))) xy = zero(x[1] * y[1]') @simd for i in eachindex(x, y) diff --git a/stdlib/Statistics/test/runtests.jl b/stdlib/Statistics/test/runtests.jl index 1f1020970a5ae..fb77c535c299f 100644 --- a/stdlib/Statistics/test/runtests.jl +++ b/stdlib/Statistics/test/runtests.jl @@ -460,6 +460,8 @@ end @test cor(repeat(1:17, 1, 17))[2] <= 1.0 @test cor(1:17, 1:17) <= 1.0 @test cor(1:17, 18:34) <= 1.0 + @test cor(Any[1, 2], Any[1, 2]) == 1.0 + @test isnan(cor([0], Int8[81])) let tmp = range(1, stop=85, length=100) tmp2 = Vector(tmp) @test cor(tmp, tmp) <= 1.0