Skip to content

Conversation

cmcaine
Copy link
Contributor

@cmcaine cmcaine commented Oct 9, 2025

No description provided.

@cmcaine cmcaine changed the title docs: add missing docs for #59603 parse/tryparse add missing docs and tests for #59603 parse/tryparse Oct 9, 2025
Co-authored-by: Lilith Orion Hafner <[email protected]>
Copy link
Member

Choose a reason for hiding this comment

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

We can use this PR to address the bugs that was introduced in my commit:

function parse_char(::Type{T}, c::AbstractChar, base::Integer, throw::Bool) where {T <: Real}
    a::UInt8 = (base <= 36 ? 10 : 36)
    (2 <= base <= 62) || _invalid_base(base)
    base = base % UInt8
    u = reinterpret(UInt32, Char(c)::Char)
    cp = u > 0x7a000000 ? 0xff : (cp >> 24) % UInt8
    d = UInt8('0')  cp  UInt8('9') ? cp - UInt8('0') :
        UInt8('A')  cp  UInt8('Z') ? cp - UInt8('A') + UInt8(10) :
        UInt8('a')  cp  UInt8('z') ? cp - UInt8('a') + a :
        0xff
    d < base || (throw ? _invalid_digit(base, c) : return nothing)
    convert(T, d)::T
end

Copy link
Member

Choose a reason for hiding this comment

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

This solves two bugs:

  • Most importantly, parse(Int, typemax(Char)) now behaves properly
  • I don't think parse(Complex, '3') should work. The user should specify e.g. Complex{Int}. This should be handled by a distinct method since complex parsing is more... complex 🥁

Copy link
Member

Choose a reason for hiding this comment

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

Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants