Skip to content

Commit

Permalink
fix docstrings, indentations, ..., from reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
rfourquet committed May 26, 2017
1 parent 24a7ae6 commit e655c03
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 35 deletions.
15 changes: 1 addition & 14 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,10 @@ Convert a number to an unsigned integer. If the argument is signed, it is reinte
unsigned without checking for negative values.
See also [`signed`](@ref).
unsigned(T::Type) -> UnsignedType
Return the return-type of `unsigned(x::T)`, so that `unsigned(x)::unsigned(typeof(x))`.
```jldoctest
julia> unsigned(12)
0x000000000000000c
julia> unsigned(Int64)
UInt64
julia> unsigned(2.0)
0x0000000000000002
Expand All @@ -174,23 +167,17 @@ Convert a number to a signed integer. If the argument is unsigned, it is reinter
signed without checking for overflow.
See also [`unsigned`](@ref).
signed(T::Type) -> SignedType
Return the return-type of `signed(x::T)`, so that `signed(x)::signed(typeof(x))`.
```jldoctest
julia> signed(0xc)
12
julia> signed(UInt64)
Int64
julia> signed(2.0)
2
julia> signed(2.2)
ERROR: InexactError()
[...]
```
"""
signed(x::UInt) = reinterpret(Int, x)

Expand Down
25 changes: 24 additions & 1 deletion base/int.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,34 @@ const BitFloat = Union{BitFloat_types...}
const BitReal_types = (BitInteger_types..., BitFloat_types...)
const BitReal = Union{BitReal_types...}

## integer signed-ness conversions

reinterpret(::Type{Unsigned}, x::BitInteger) = unsigned(x)
reinterpret(::Type{ Signed}, x::BitInteger) = signed(x)

"""
unsigned(T::Type) -> UnsignedType
Return the return-type of `unsigned(x::T)`, so that `unsigned(x)::unsigned(typeof(x))`.
```jldoctest
julia> unsigned(Int64)
UInt64
```
"""
unsigned(::Type{T}) where {T<:Unsigned} = T
signed( ::Type{T}) where {T<:Signed} = T

"""
signed(T::Type) -> SignedType
Return the return-type of `signed(x::T)`, so that `signed(x)::signed(typeof(x))`.
```jldoctest
julia> signed(UInt64)
Int64
```
"""
signed(::Type{T}) where {T<:Signed} = T

unsigned(::Type{<:Union{Bool,BitFloat}}) = UInt
signed( ::Type{<:Union{Bool,BitFloat}}) = Int
Expand Down
39 changes: 19 additions & 20 deletions base/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

# this construction is not available when put in int.jl and running in Core
for (S,U,F) in zip(BitSigned_types, BitUnsigned_types,
(nothing, Float16, Float32, Float64, nothing))
@eval begin
unsigned(::Type{$S}) = $U
unsigned(::Type{$U}) = $U
signed( ::Type{$S}) = $S
signed( ::Type{$U}) = $S
reinterpret(::Type{Unsigned}, ::Type{$S}) = $U
reinterpret(::Type{Unsigned}, ::Type{$U}) = $U
reinterpret(::Type{Signed}, ::Type{$S}) = $S
reinterpret(::Type{Signed}, ::Type{$U}) = $S
end
F === nothing && continue
@eval begin
reinterpret(::Type{Unsigned}, ::Type{$F}) = $U
reinterpret(::Type{Signed}, ::Type{$F}) = $S
end
(nothing, Float16, Float32, Float64, nothing))
@eval begin
unsigned(::Type{$S}) = $U
unsigned(::Type{$U}) = $U
signed( ::Type{$S}) = $S
signed( ::Type{$U}) = $S
reinterpret(::Type{Unsigned}, ::Type{$S}) = $U
reinterpret(::Type{Unsigned}, ::Type{$U}) = $U
reinterpret(::Type{Signed}, ::Type{$S}) = $S
reinterpret(::Type{Signed}, ::Type{$U}) = $S
end
F === nothing && continue
@eval begin
reinterpret(::Type{Unsigned}, ::Type{$F}) = $U
reinterpret(::Type{Signed}, ::Type{$F}) = $S
end
end

## number-theoretic functions ##

Expand Down Expand Up @@ -506,17 +506,16 @@ end
"""
num2hex(f)
An hexadecimal string of the binary representation of a number.
A hexadecimal string of the binary representation of a number.
See also the [`bits`](@ref) function, which is similar but gives
a binary string, and [`hex2num`] which does the opposite conversion.
a binary string, and [`hex2num`](@ref) which does the opposite conversion.
```jldoctest
julia> num2hex(Int64(4))
"0000000000000004"
julia> num2hex(2.2)
"400199999999999a"
```
"""
num2hex(n::BitReal) = hex(reinterpret(Unsigned, n), sizeof(n)*2)
Expand Down Expand Up @@ -632,7 +631,7 @@ dec
A string giving the literal bit representation of a number.
See also the [`num2hex`](@ref) function, which is similar but
gives an hexadecimal string.
gives a hexadecimal string.
```jldoctest
julia> bits(4)
Expand Down

0 comments on commit e655c03

Please sign in to comment.