From a2fb0a4418f113e963407c794bfe2e2361ac8c13 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Wed, 5 Apr 2017 05:00:57 -0500 Subject: [PATCH] Support unsafe_trunc(::Type{<:Integer}, ::Integer) --- README.md | 3 +++ src/Compat.jl | 4 ++++ test/runtests.jl | 3 +++ 3 files changed, 10 insertions(+) diff --git a/README.md b/README.md index 8c60d70d1..8025e9ceb 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,8 @@ Currently, the `@compat` macro supports the following syntaxes: * `convert` can convert between different `Set` types on 0.5 and below. ([#18727]) +* `unsafe_trunc(::Type{<:Integer}, ::Integer)` is supported on 0.5. ([#18629]) + ## Renamed functions * `pointer_to_array` and `pointer_to_string` have been replaced with `unsafe_wrap(Array, ...)` and `unsafe_wrap(String, ...)` respectively @@ -352,3 +354,4 @@ includes this fix. Find the minimum version from there. [#20414]: https://github.com/JuliaLang/julia/issues/20414 [#20418]: https://github.com/JuliaLang/julia/issues/20418 [#20500]: https://github.com/JuliaLang/julia/issues/20500 +[#18629]: https://github.com/JuliaLang/julia/pull/18629 diff --git a/src/Compat.jl b/src/Compat.jl index e240e6348..0171e3df1 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1450,6 +1450,10 @@ if VERSION < v"0.6.0-dev.838" Base.convert{T}(::Type{Set{T}}, s::Set) = Set{T}(s) end +if VERSION < v"0.6.0-dev.735" + Base.unsafe_trunc{T<:Integer}(::Type{T}, x::Integer) = rem(x, T) +end + include("to-be-deprecated.jl") end # module Compat diff --git a/test/runtests.jl b/test/runtests.jl index 41bc349c3..533f81324 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1805,6 +1805,9 @@ let @test cssset == Set(["foo", "bar"]) end +@test unsafe_trunc(Int8, 128) === Int8(-128) +@test_throws InexactError trunc(Int8, 128) + include("to-be-deprecated.jl") nothing