Skip to content

Commit

Permalink
Use compact parametric syntax in base/c*.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloferz committed Feb 9, 2017
1 parent bacc024 commit 038c8c5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions base/c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ if !is_windows()
end

# construction from typed pointers
convert{T<:Union{Int8,UInt8}}(::Type{Cstring}, p::Ptr{T}) = bitcast(Cstring, p)
convert(::Type{Cstring}, p::Ptr{<:Union{Int8,UInt8}}) = bitcast(Cstring, p)
convert(::Type{Cwstring}, p::Ptr{Cwchar_t}) = bitcast(Cwstring, p)
convert{T<:Union{Int8,UInt8}}(::Type{Ptr{T}}, p::Cstring) = bitcast(Ptr{T}, p)
convert(::Type{Ptr{Cwchar_t}}, p::Cwstring) = bitcast(Ptr{Cwchar_t}, p)
Expand Down Expand Up @@ -161,7 +161,7 @@ function transcode end
transcode{T<:Union{UInt8,UInt16,UInt32,Int32}}(::Type{T}, src::Vector{T}) = src
transcode{T<:Union{Int32,UInt32}}(::Type{T}, src::String) = T[T(c) for c in src]
transcode{T<:Union{Int32,UInt32}}(::Type{T}, src::Vector{UInt8}) = transcode(T, String(src))
function transcode{S<:Union{Int32,UInt32}}(::Type{UInt8}, src::Vector{S})
function transcode(::Type{UInt8}, src::Vector{<:Union{Int32,UInt32}})
buf = IOBuffer()
for c in src; print(buf, Char(c)); end
take!(buf)
Expand Down
4 changes: 2 additions & 2 deletions base/channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,6 @@ function done(c::Channel, state::ChannelIterState)
end
end
end
next{T}(c::Channel{T}, state) = (v=state.val; state.hasval=false; (v, state))
next(c::Channel, state) = (v=state.val; state.hasval=false; (v, state))

iteratorsize{C<:Channel}(::Type{C}) = SizeUnknown()
iteratorsize(::Type{<:Channel}) = SizeUnknown()
2 changes: 1 addition & 1 deletion base/checked.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function checked_neg{T<:Integer}(x::T)
checked_sub(T(0), x)
end
if BrokenSignedInt != Union{}
function checked_neg{T<:BrokenSignedInt}(x::T)
function checked_neg(x::BrokenSignedInt)
r = -x
(x<0) & (r<0) && throw(OverflowError())
r
Expand Down
4 changes: 2 additions & 2 deletions base/combinatorics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ isperm(p::Tuple{}) = true
isperm(p::Tuple{Int}) = p[1] == 1
isperm(p::Tuple{Int,Int}) = ((p[1] == 1) & (p[2] == 2)) | ((p[1] == 2) & (p[2] == 1))

function permute!!{T<:Integer}(a, p::AbstractVector{T})
function permute!!(a, p::AbstractVector{<:Integer})
count = 0
start = 0
while count < length(a)
Expand Down Expand Up @@ -131,7 +131,7 @@ julia> A
"""
permute!(a, p::AbstractVector) = permute!!(a, copymutable(p))

function ipermute!!{T<:Integer}(a, p::AbstractVector{T})
function ipermute!!(a, p::AbstractVector{<:Integer})
count = 0
start = 0
while count < length(a)
Expand Down
26 changes: 13 additions & 13 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ conj(z::Complex) = Complex(real(z),-imag(z))
abs(z::Complex) = hypot(real(z), imag(z))
abs2(z::Complex) = real(z)*real(z) + imag(z)*imag(z)
inv(z::Complex) = conj(z)/abs2(z)
inv{T<:Integer}(z::Complex{T}) = inv(float(z))
inv(z::Complex{<:Integer}) = inv(float(z))

-(z::Complex) = Complex(-real(z), -imag(z))
+(z::Complex, w::Complex) = Complex(real(z) + real(w), imag(z) + imag(w))
Expand Down Expand Up @@ -288,7 +288,7 @@ function /{T<:Real}(a::Complex{T}, b::Complex{T})
end
end

inv{T<:Union{Float16,Float32}}(z::Complex{T}) =
inv(z::Complex{<:Union{Float16,Float32}}) =
oftype(z, conj(widen(z))/abs2(widen(z)))

/{T<:Union{Float16,Float32}}(z::Complex{T}, w::Complex{T}) =
Expand Down Expand Up @@ -377,7 +377,7 @@ function ssqs{T<:AbstractFloat}(x::T, y::T)
ρ, k
end

function sqrt{T<:AbstractFloat}(z::Complex{T})
function sqrt(z::Complex{<:AbstractFloat})
x, y = reim(z)
if x==y==0
return Complex(zero(x),y)
Expand Down Expand Up @@ -659,12 +659,12 @@ end
^(z::Complex, n::Bool) = n ? z : one(z)
^(z::Complex, n::Integer) = z^Complex(n)

^{T<:AbstractFloat}(z::Complex{T}, n::Bool) = n ? z : one(z) # to resolve ambiguity
^{T<:Integer}(z::Complex{T}, n::Bool) = n ? z : one(z) # to resolve ambiguity
^(z::Complex{<:AbstractFloat}, n::Bool) = n ? z : one(z) # to resolve ambiguity
^(z::Complex{<:Integer}, n::Bool) = n ? z : one(z) # to resolve ambiguity

^{T<:AbstractFloat}(z::Complex{T}, n::Integer) =
^(z::Complex{<:AbstractFloat}, n::Integer) =
n>=0 ? power_by_squaring(z,n) : power_by_squaring(inv(z),-n)
^{T<:Integer}(z::Complex{T}, n::Integer) = power_by_squaring(z,n) # DomainError for n<0
^(z::Complex{<:Integer}, n::Integer) = power_by_squaring(z,n) # DomainError for n<0

function sin{T}(z::Complex{T})
F = float(T)
Expand Down Expand Up @@ -722,7 +722,7 @@ function asin(z::Complex)
Complex(ξ,η)
end

function acos{T<:AbstractFloat}(z::Complex{T})
function acos(z::Complex{<:AbstractFloat})
zr, zi = reim(z)
if isnan(zr)
if isinf(zi) return Complex(zr, -zi)
Expand Down Expand Up @@ -863,7 +863,7 @@ breaking ties using the specified [`RoundingMode`](@ref)s. The first
[`RoundingMode`](@ref) is used for rounding the real components while the
second is used for rounding the imaginary components.
"""
function round{T<:AbstractFloat, MR, MI}(z::Complex{T}, ::RoundingMode{MR}, ::RoundingMode{MI})
function round{MR, MI}(z::Complex{<:AbstractFloat}, ::RoundingMode{MR}, ::RoundingMode{MI})
Complex(round(real(z), RoundingMode{MR}()),
round(imag(z), RoundingMode{MI}()))
end
Expand All @@ -874,15 +874,15 @@ function round(z::Complex, digits::Integer, base::Integer=10)
round(imag(z), digits, base))
end

float{T<:AbstractFloat}(z::Complex{T}) = z
float(z::Complex{<:AbstractFloat}) = z
float(z::Complex) = Complex(float(real(z)), float(imag(z)))

big{T<:AbstractFloat}(z::Complex{T}) = Complex{BigFloat}(z)
big{T<:Integer}(z::Complex{T}) = Complex{BigInt}(z)
big(z::Complex{<:AbstractFloat}) = Complex{BigFloat}(z)
big(z::Complex{<:Integer}) = Complex{BigInt}(z)

## Array operations on complex numbers ##

complex{T<:Complex}(A::AbstractArray{T}) = A
complex(A::AbstractArray{<:Complex}) = A

function complex{T}(A::AbstractArray{T})
if !isleaftype(T)
Expand Down

0 comments on commit 038c8c5

Please sign in to comment.