Skip to content

Commit

Permalink
Deprecate hex2num and num2hex
Browse files Browse the repository at this point in the history
See #22031.
  • Loading branch information
simonbyrne committed May 26, 2017
1 parent 62e8227 commit ab9f8f8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 39 deletions.
16 changes: 16 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,22 @@ end
@deprecate srand(filename::AbstractString, n::Integer=4) srand(read!(filename, Array{UInt32}(Int(n))))
@deprecate MersenneTwister(filename::AbstractString) srand(MersenneTwister(0), read!(filename, Array{UInt32}(Int(4))))

# 22031
function hex2num(s::AbstractString)
depwarn("hex2num(s) is deprecated. Use reinterpret(Float64, parse(UInt64, s, 16)) instead.", :hex2num)
if length(s) <= 4
return reinterpret(Float16, parse(UInt16, s, 16))
end
if length(s) <= 8
return reinterpret(Float32, parse(UInt32, s, 16))
end
return reinterpret(Float64, parse(UInt64, s, 16))
end

@deprecate num2hex(x::Union{Float16,Float32,Float64}) =
hex(reintepret(Unsigned, x), sizeof(x)*2)
@deprecate num2hex(n::Integer) = hex(n, sizeof(n)*2)

# END 0.7 deprecations

# BEGIN 1.0 deprecations
Expand Down
19 changes: 0 additions & 19 deletions base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -565,18 +565,6 @@ original string, otherwise they must be from distinct character ranges.
"""
eachmatch

"""
num2hex(f)
Get a hexadecimal string of the binary representation of a floating point number.
```jldoctest
julia> num2hex(2.2)
"400199999999999a"
```
"""
num2hex

"""
truncate(file,n)
Expand Down Expand Up @@ -1360,13 +1348,6 @@ false
"""
isempty

"""
hex2num(str)
Convert a hexadecimal string to the floating point number it represents.
"""
hex2num

"""
InexactError()
Expand Down
2 changes: 0 additions & 2 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ export
gamma,
gcd,
gcdx,
hex2num,
hypot,
imag,
inv,
Expand Down Expand Up @@ -378,7 +377,6 @@ export
nextpow2,
nextprod,
numerator,
num2hex,
one,
oneunit,
powermod,
Expand Down
14 changes: 0 additions & 14 deletions base/floatfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,6 @@ maxintfloat() = maxintfloat(Float64)

isinteger(x::AbstractFloat) = (x - trunc(x) == 0)

num2hex(x::Float16) = hex(bitcast(UInt16, x), 4)
num2hex(x::Float32) = hex(bitcast(UInt32, x), 8)
num2hex(x::Float64) = hex(bitcast(UInt64, x), 16)

function hex2num(s::AbstractString)
if length(s) <= 4
return bitcast(Float16, parse(UInt16, s, 16))
end
if length(s) <= 8
return bitcast(Float32, parse(UInt32, s, 16))
end
return bitcast(Float64, parse(UInt64, s, 16))
end

"""
round([T,] x, [digits, [base]], [r::RoundingMode])
Expand Down
2 changes: 0 additions & 2 deletions base/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,6 @@ function hex(x::Unsigned, pad::Int, neg::Bool)
String(a)
end

num2hex(n::Integer) = hex(n, sizeof(n)*2)

const base36digits = ['0':'9';'a':'z']
const base62digits = ['0':'9';'A':'Z';'a':'z']

Expand Down
2 changes: 0 additions & 2 deletions doc/src/stdlib/numbers.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ Base.Math.significand
Base.Math.exponent
Base.complex(::Complex)
Base.bswap
Base.num2hex
Base.hex2num
Base.hex2bytes
Base.bytes2hex
```
Expand Down

0 comments on commit ab9f8f8

Please sign in to comment.