diff --git a/Project.toml b/Project.toml index 00cf1046..f28cc2bb 100644 --- a/Project.toml +++ b/Project.toml @@ -4,9 +4,11 @@ version = "0.8.4" [deps] Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +Requires = "ae029012-a4dd-5104-9daa-d747884805df" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [compat] +Requires = "1" julia = "1" [extras] diff --git a/src/FixedPointNumbers.jl b/src/FixedPointNumbers.jl index 927d84a5..2c197aaf 100644 --- a/src/FixedPointNumbers.jl +++ b/src/FixedPointNumbers.jl @@ -9,7 +9,7 @@ import Base: ==, <, <=, -, +, *, /, ~, isapprox, signed, unsigned, copysign, flipsign, signbit, length -import Statistics # for _mean_promote +using Requires import Random: Random, AbstractRNG, SamplerType, rand! import Base.Checked: checked_neg, checked_abs, checked_add, checked_sub, checked_mul, @@ -557,10 +557,6 @@ Base.mul_prod(x::FixedPoint, y::FixedPoint) = Treduce(x) * Treduce(y) Base.reduce_empty(::typeof(Base.mul_prod), ::Type{F}) where {F<:FixedPoint} = one(Treduce) Base.reduce_first(::typeof(Base.mul_prod), x::FixedPoint) = Treduce(x) -if isdefined(Statistics, :_mean_promote) - Statistics._mean_promote(x::Real, y::FixedPoint) = Treduce(y) -end - """ sd, ad = scaledual(s::Number, a) @@ -629,4 +625,20 @@ if VERSION >= v"1.1" # work around https://github.com/JuliaLang/julia/issues/341 _precompile_() end +@static if VERSION >= v"1.9.0-DEV.873" + function __init__() + # Statistics and SparseArrays are moved out from sysimage + # https://github.com/JuliaLang/julia/pull/44247#issuecomment-1172847231 + @require Statistics="10745b16-79ce-11e8-11f9-7d13ad32a3b2" begin + Statistics._mean_promote(x::Real, y::FixedPoint) = Treduce(y) + end + end +else + import Statistics + if isdefined(Statistics, :_mean_promote) + # https://github.com/JuliaMath/FixedPointNumbers.jl/pull/183 + Statistics._mean_promote(x::Real, y::FixedPoint) = Treduce(y) + end +end + end # module