From 709ff1429e91ecb4bc3389888a67edb74345f390 Mon Sep 17 00:00:00 2001 From: Nicola Mosco Date: Sun, 9 Oct 2022 18:03:51 +0200 Subject: [PATCH] Math operations with explicit types When called with explicit type we should return a result of that type. --- src/ColorVectorSpace.jl | 2 +- test/runtests.jl | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ColorVectorSpace.jl b/src/ColorVectorSpace.jl index fae3480..30d0998 100644 --- a/src/ColorVectorSpace.jl +++ b/src/ColorVectorSpace.jl @@ -221,7 +221,7 @@ end eps(::Type{Gray{T}}) where {T} = Gray(eps(T)) for f in (:trunc, :floor, :round, :ceil) - @eval $f(::Type{T}, g::Gray) where {T<:Integer} = Gray{T}($f(T, gray(g))) + @eval $f(::Type{T}, g::Gray) where {T<:Integer} = $f(T, gray(g)) end for f in (:mod, :rem, :mod1) diff --git a/test/runtests.jl b/test/runtests.jl index 68c6f6a..2afe798 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -300,7 +300,13 @@ ColorTypes.comp2(c::RGBA32) = alpha(c) for g in (Gray{N0f8}(0.4), Gray{N0f8}(0.6)) for op in (:trunc, :floor, :round, :ceil) v = @eval $op(Bool, gray($g)) - @test @eval($op(Bool, $g)) === Gray(v) + @test @eval($op(Bool, $g)) === v + end + end + for g in (Gray(1.4), Gray(1.6)) + for op in (:trunc, :floor, :round, :ceil) + v = @eval $op(Int, gray($g)) + @test @eval($op(Int, $g)) === v end end for (g1, g2) in ((Gray(0.4), Gray(0.3)), (Gray(N0f8(0.4)), Gray(N0f8(0.3))))