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

Unexpected behavior for searchsortedlast #35179

Closed
kshedden opened this issue Mar 20, 2020 · 1 comment
Closed

Unexpected behavior for searchsortedlast #35179

kshedden opened this issue Mar 20, 2020 · 1 comment

Comments

@kshedden
Copy link

Is this intended behavior? I am using Julia 1.3.1

julia> searchsortedlast([-2, -1, 0, 0, 1, 2], 0.0)
4 
julia> searchsortedlast([-2, -1, 0, 0, 1, 2], -0.0)
2

Version information:

julia> versioninfo() 
Julia Version 1.3.1
Commit 2d5741174c (2019-12-30 21:36 UTC)
Platform Info: 
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Xeon(R) CPU E5-2660 0 @ 2.20GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, sandybridge)
Environment:
JULIA_DEPOT_PATH = /nfs/kshedden/julia_libs
@haampie
Copy link
Contributor

haampie commented Mar 20, 2020

Yes, intended because

julia> isless(-0.0, 0.0)
true

julia> isless(0.0, 0.0)
false

Otherwise stick to Ints (there is no signed zero in Ints) or use < for Floats

julia> searchsortedlast([-2, -1, 0, 0, 1, 2], -0)
4

julia> searchsortedlast([-2, -1, 0, 0, 1, 2], -0.0, lt = <)
4

but do note that < on Floats is not a total order in the sense that

julia> NaN < 0
false

julia> 0 < NaN
false

so < should typically be avoided in the context of sorting unless you know your values are free of NaNs.

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

No branches or pull requests

3 participants