Skip to content

Commit

Permalink
fix #26571, use 10 as the default base in parse(T, ::Char)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Mar 23, 2018
1 parent 6647086 commit c6fc5ec
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,9 @@ This section lists changes that do not have deprecation warnings.

* `indexin` now returns the first rather than the last matching index ([#25998]).

* `parse(::Type, ::Char)` now uses a default base of 10, like other number parsing
methods, instead of 36 ([#26576]).

Library improvements
--------------------

Expand Down
2 changes: 1 addition & 1 deletion base/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ julia> parse(Complex{Float64}, "3.2e-1 + 4.5im")
"""
parse(T::Type, str; base = Int)

function parse(::Type{T}, c::AbstractChar; base::Integer = 36) where T<:Integer
function parse(::Type{T}, c::AbstractChar; base::Integer = 10) where T<:Integer
a::Int = (base <= 36 ? 10 : 36)
2 <= base <= 62 || throw(ArgumentError("invalid base: base must be 2 ≤ base ≤ 62, got $base"))
d = '0' <= c <= '9' ? c-'0' :
Expand Down
7 changes: 4 additions & 3 deletions test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@
@test parse(Int,"-10") == -10
@test parse(Int64,"3830974272") == 3830974272
@test parse(Int64,"-3830974272") == -3830974272

@test parse(Int,'3') == 3
@test parse(Int,'3', base = 8) == 3
@test parse(Int, 'a', base=16) == 10
@test_throws ArgumentError parse(Int, 'a')
@test_throws ArgumentError parse(Int,typemax(Char))

# Issue 20587
for T in Any[BigInt, Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8]
Expand Down Expand Up @@ -173,9 +177,6 @@ parsehex(s) = parse(Int,s, base = 16)
@test parse(Int, "3\u2003\u202F") == 3
@test_throws ArgumentError parse(Int, "3\u2003\u202F,")

@test parse(Int,'a') == 10
@test_throws ArgumentError parse(Int,typemax(Char))

@test parse(Int,"1234") == 1234
@test parse(Int,"0x1234") == 0x1234
@test parse(Int,"0o1234") == 0o1234
Expand Down

0 comments on commit c6fc5ec

Please sign in to comment.