diff --git a/base/deprecated.jl b/base/deprecated.jl index 54f57c816bf34..54f98bdf96a54 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -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) @@ -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) +@deprecate num2hex(n::Integer) hex(n, sizeof(n)*2) + + # END 0.7 deprecations # BEGIN 1.0 deprecations diff --git a/base/docs/helpdb/Base.jl b/base/docs/helpdb/Base.jl index 47a32ae5cf895..71011c1d32047 100644 --- a/base/docs/helpdb/Base.jl +++ b/base/docs/helpdb/Base.jl @@ -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) @@ -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) diff --git a/base/exports.jl b/base/exports.jl index 80601067a1dce..eecd75f36d46e 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -338,7 +338,6 @@ export gamma, gcd, gcdx, - hex2num, hypot, imag, inv, @@ -377,7 +376,6 @@ export nextpow2, nextprod, numerator, - num2hex, one, oneunit, powermod, diff --git a/base/floatfuncs.jl b/base/floatfuncs.jl index 32612f3525ea2..5e04b96128d96 100644 --- a/base/floatfuncs.jl +++ b/base/floatfuncs.jl @@ -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]) diff --git a/base/intfuncs.jl b/base/intfuncs.jl index b95c54ef6f9ee..d6c782e33a89e 100644 --- a/base/intfuncs.jl +++ b/base/intfuncs.jl @@ -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'] diff --git a/doc/src/stdlib/numbers.md b/doc/src/stdlib/numbers.md index d04e7510a536f..91941c4a338fa 100644 --- a/doc/src/stdlib/numbers.md +++ b/doc/src/stdlib/numbers.md @@ -58,8 +58,6 @@ Base.Math.significand Base.Math.exponent Base.complex(::Complex) Base.bswap -Base.num2hex -Base.hex2num Base.hex2bytes Base.bytes2hex ``` diff --git a/test/floatfuncs.jl b/test/floatfuncs.jl index d1796d68d5a18..c97f077f05438 100644 --- a/test/floatfuncs.jl +++ b/test/floatfuncs.jl @@ -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) diff --git a/test/intfuncs.jl b/test/intfuncs.jl index 7498927596c11..0ecf36d203a97 100644 --- a/test/intfuncs.jl +++ b/test/intfuncs.jl @@ -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" diff --git a/test/numbers.jl b/test/numbers.jl index 9ce99dcd79840..45603503c66bf 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -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"