@@ -4,7 +4,7 @@ import Base: ==, <, <=, -, +, *, /, ~, isapprox,
44 convert, promote_rule, show, bitstring, abs, decompose,
55 isnan, isinf, isfinite, isinteger,
66 zero, oneunit, one, typemin, typemax, floatmin, floatmax, eps, reinterpret,
7- big, rationalize, float, trunc, round, floor, ceil, bswap,
7+ big, rationalize, float, trunc, round, floor, ceil, bswap, clamp,
88 div, fld, rem, mod, mod1, fld1, min, max, minmax,
99 rand, length
1010
@@ -183,6 +183,12 @@ bitstring(x::FixedPoint) = bitstring(x.i)
183183
184184bswap (x:: X ) where {X <: FixedPoint } = sizeof (X) == 1 ? x : X (bswap (x. i), 0 )
185185
186+ # At least on Julia v1.5.0 or earlier, the following specialization helps the
187+ # SIMD vectorization. (cf. PR #194)
188+ clamp (x:: X , lo:: X , hi:: X ) where {X <: FixedPoint } = X (clamp (x. i, lo. i, hi. i), 0 )
189+
190+ clamp (x, :: Type{X} ) where {X <: FixedPoint } = clamp (x, typemin (X), typemax (X)) % X
191+
186192for f in (:zero , :oneunit , :one , :eps , :rawone , :rawtype , :floattype )
187193 @eval begin
188194 $ f (x:: FixedPoint ) = $ f (typeof (x))
0 commit comments