diff --git a/src/stats.jl b/src/stats.jl index 65f5a37..b955f7f 100644 --- a/src/stats.jl +++ b/src/stats.jl @@ -456,7 +456,7 @@ function _merge!(o::Variance, o2::Variance) end function value(o::Variance{T}) where {T} if nobs(o) > 1 - o.σ2 * bessel(o) + o.σ2 * T(bessel(o)) else isfinite(mean(o)) ? T(1) ^ 2 : NaN * T(1) ^ 2 end diff --git a/test/test_stats.jl b/test/test_stats.jl index bb66150..fe82800 100644 --- a/test/test_stats.jl +++ b/test/test_stats.jl @@ -251,6 +251,8 @@ println(" > Variance") @test std(Variance()) == 1 @test std(fit!(Variance(), 1)) == 1 @test std(fit!(Variance(), [1, 2])) == sqrt(.5) + # https://github.com/joshday/OnlineStats.jl/issues/217 + @test value(fit!(Variance(Float32), randn(Float32, 10))) isa Float32 end end # end "Test Stats" \ No newline at end of file