Skip to content

Commit

Permalink
add rem(::Integer, ::Type{T<:Integer}}) functions from JuliaLang/juli…
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Aug 20, 2015
1 parent 66e962e commit c2d72bb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Currently, the `@compat` macro supports the following syntaxes:

## Renamed functions

* `itrunc`, `iround`, `iceil`, `ifloor` are now accessed via `trunc(T, x)`, etc. [#9133](https://github.com/JuliaLang/julia/pull/9133)
* `itrunc`, `iround`, `iceil`, `ifloor` are now accessed via `trunc(T, x)`, etc. ([#9133](https://github.com/JuliaLang/julia/pull/9133)). Truncated conversions between integer types are now `n % T` ([#8646](https://github.com/JuliaLang/julia/issues/8646)).

* `Base.Random.randmtzig_exprnd` is now `randexp` [#9144](https://github.com/JuliaLang/julia/pull/9144)

Expand Down
8 changes: 8 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ if VERSION < v"0.4.0-dev+1827"
end
end

if VERSION < v"0.4.0-dev+838"
Base.rem{T<:Integer}(n::Integer, ::Type{T}) = convert(T, n)
elseif VERSION < v"0.4.0-dev+1037"
Base.rem{T<:Integer}(n::Integer, ::Type{T}) = itrunc(T, n)
elseif VERSION < v"0.4.0-dev+1039"
Base.rem{T<:Integer}(n::Integer, ::Type{T}) = mod(n, T)
end

if VERSION < v"0.4.0-dev+1884"
randexp(rng::MersenneTwister) = Base.Random.randmtzig_exprnd(rng)
randexp() = Base.Random.randmtzig_exprnd()
Expand Down
18 changes: 18 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ end
@test trunc(Int, [1.1 1.1]) == [1 1]
@test trunc(Int, fill(1.1, 2, 3, 4)) == fill(1, 2, 3, 4)

# n % Type
for T in Any[Int16, Int32, UInt32, Int64, UInt64]
if !(T <: Unsigned)
@test convert(T, -200) % Int8 === @compat Int8(56)
@test convert(T, -200) % UInt8 === 0x38
@test convert(T, -300) % Int8 === @compat Int8(-44)
@test convert(T, -300) % UInt8 === 0xd4
@test convert(T, -128) % Int8 === @compat Int8(-128)
@test convert(T, -128) % UInt8 === 0x80
end
@test convert(T, 127) % Int8 === @compat Int8(127)
@test convert(T, 127) % UInt8 === 0x7f
@test convert(T, 128) % Int8 === @compat Int8(-128)
@test convert(T, 128) % UInt8 === 0x80
@test convert(T, 200) % Int8 === @compat Int8(-56)
@test convert(T, 300) % UInt8 === 0x2c
end

@test IPv4("1.2.3.4") == ip"1.2.3.4"
@test IPv6("2001:1:2:3::1") == ip"2001:1:2:3::1"
@test isless(ip"1.2.3.4", ip"1.2.3.5")
Expand Down

0 comments on commit c2d72bb

Please sign in to comment.