Skip to content

searchsorted* misbehave with unsigned integers #10966

@simonster

Description

@simonster

searchsortedfirst also has a lot of fun bugs with unsigned integers. If you're lucky, it throws an error, but sometimes the results are silently incorrect.

julia> searchsortedfirst(UInt64(2):UInt64(2), 0) # also happens with a UInt64 x
0x0000000000000002

julia> searchsortedfirst(UInt64(2):UInt64(2), 2) # works with a UInt64 x
ERROR: InexactError()
 in searchsortedfirst at sort.jl:209

julia> searchsortedlast(UInt64(2):UInt64(2), 0) # also happens with a UInt64 x
0x0000000000000001

julia> searchsorted(UInt64(2):UInt64(2), 2) # works with a UInt64 x
ERROR: InexactError()
 in searchsortedfirst at sort.jl:209
 in searchsorted at sort.jl:229

julia> searchsortedfirst(UInt64(1):1//2:UInt64(5), 0) # also happens with a UInt64 x
ERROR: OverflowError()
 in - at rational.jl:166
 in searchsortedfirst at sort.jl:192

julia> searchsortedlast(UInt64(1):1//2:UInt64(5), 0) # also happens with a UInt64 x
ERROR: OverflowError()
 in - at rational.jl:166
 in searchsortedlast at sort.jl:183

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorhelp wantedIndicates that a maintainer wants help on an issue or pull request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions