Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate hex2num and num2hex #22088

Merged
merged 3 commits into from
Aug 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,7 @@ 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))))


# PR #21974
@deprecate versioninfo(verbose::Bool) versioninfo(verbose=verbose)
@deprecate versioninfo(io::IO, verbose::Bool) versioninfo(io, verbose=verbose)
Expand Down Expand Up @@ -1645,6 +1646,22 @@ end
# PR #23187
@deprecate cpad(s, n::Integer, p=" ") rpad(lpad(s, div(n+strwidth(s), 2), p), n, p) false

# PR #22088
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reintepret -> reinterpret

@deprecate num2hex(n::Integer) hex(n, sizeof(n)*2)


# END 0.7 deprecations

# BEGIN 1.0 deprecations
Expand Down
20 changes: 0 additions & 20 deletions base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -428,19 +428,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.

# Examples
```jldoctest
julia> num2hex(2.2)
"400199999999999a"
```
"""
num2hex

"""
truncate(file,n)

Expand Down Expand Up @@ -1301,13 +1288,6 @@ false
"""
isempty

"""
hex2num(str)

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

"""
InexactError(name::Symbol, T, val)

Expand Down
2 changes: 0 additions & 2 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ export
gamma,
gcd,
gcdx,
hex2num,
hypot,
imag,
inv,
Expand Down Expand Up @@ -377,7 +376,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 @@ -37,20 +37,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 @@ -584,8 +584,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 @@ -58,8 +58,6 @@ Base.Math.significand
Base.Math.exponent
Base.complex(::Complex)
Base.bswap
Base.num2hex
Base.hex2num
Base.hex2bytes
Base.bytes2hex
```
Expand Down
6 changes: 0 additions & 6 deletions test/floatfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ for elty in (Float16,Float32,Float64)
@test !isinteger(elty(NaN))
end

# num2hex, hex2num
for elty in (Float16,Float32,Float64), _ = 1:10
x = rand(elty)
@test hex2num(num2hex(x)) ≈ x
end

# round
for elty in (Float32,Float64)
x = rand(elty)
Expand Down
1 change: 0 additions & 1 deletion test/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ end

@test hex(12) == "c"
@test hex(-12, 3) == "-00c"
@test num2hex(1243) == (Int == Int32 ? "000004db" : "00000000000004db")

@test base(2, 5, 7) == "0000101"

Expand Down
14 changes: 0 additions & 14 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -387,20 +387,6 @@ end
@test base(12,typemin(Int128)) == "-2a695925806818735399a37a20a31b3534a8"
@test base(12,typemax(Int128)) == "2a695925806818735399a37a20a31b3534a7"

@test hex2num("3ff0000000000000") == 1.
@test hex2num("bff0000000000000") == -1.
@test hex2num("4000000000000000") == 2.
@test hex2num("7ff0000000000000") == Inf
@test hex2num("fff0000000000000") == -Inf
@test isnan(hex2num("7ff8000000000000"))
@test isnan(hex2num("fff8000000000000"))
@test hex2num("3f800000") == 1.0f0
@test hex2num("bf800000") == -1.0f0
@test hex2num("7f800000") == Inf32
@test hex2num("ff800000") == -Inf32
@test isnan(hex2num("7fc00000"))
@test isnan(hex2num("ffc00000"))

# floating-point printing
@test repr(1.0) == "1.0"
@test repr(-1.0) == "-1.0"
Expand Down