-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
remove lexless and lexcmp (was: behavior of cmp() on NaNs?) #5290
Comments
In my view, |
Also, currently |
What you just wrote seems to be the opposite of what is implemented, since it sounds like you want I'm fine with having non-canonical behavior, but at the very least the functions that will do so should be documented. |
IEEE 754 defines a standard total order on floats where NaN is greater than Inf, so Unfortunately the IEEE 754 order also puts -NaN less than everything, which is not how we prefer to sort things. Normally the sign of NaN is not interpreted, but has specified behavior for copy, negate, abs, copySign, and totalOrder. I would argue that making all NaNs IEEE 754 does specify that |
So is the claim that If the answer to my question is 'yes', then there are further behaviors that need fixing: julia> lexcmp(-0.0,0.0) #c.f. IEEE 754-2008 5.10.c.1: "totalOrder(−0, +0) is true."
0
julia> lexcmp(-0.0,float32(-0.0)) #??? I don't think the standard says anything about comparing different precisions - just let type promotion handle this?
0 And then there is the business of total ordering numerical equivalent bit patterns... |
for now cmp() uses the total ordering, but we might change it to give a DomainError for NaN arguments
This should be addressed at the same time as we change |
FWIW, future C standards TS 18661-1:2014 (free draft) will offer a |
The Here's one option for the comparison functions:
|
Crazy idea
|
My premise is that this is used for sorting things, not numerical algorithms, so the |
related? #9381 |
I think not much more design is needed here and my previous comment should just be implemented. |
Can we deprecate |
We could also remove
EDIT: Was partly quoting Stefan here; see his comment. |
Let's go the other direction:
|
Are we doing this by feature freeze? Seems like the design is ready, but there hasn't been much work since. |
Deprecating lexcmp and lexless is straightforward enough; do we also still want to change |
And should we also remove |
1. Inconsistent logic between
lexcmp
andnextfloat
Given the definition of
lexcmp
according to the help text, throwing an error is the right thing to do given that>
,==
and<
are all supposed to be false when either operand is aNaN
and so none of the standard return values (1, 0, -1) can be correct. However, it probably shouldn't throw anInexactError
, but something else instead (probablyDomainError
).In contrast, I don't see a meaningful sense in which
NaN
is the "next" number afterInf
. The standard rule for computing with floating-pointInf
s is to interpret it as a limit, in which case the correct result ofnextfloat(Inf)
should beInf
and notNaN
(and similarlyprevfloat(-Inf)
returning-Inf
. (Going by this rule,lexcmp(Inf,Inf)
does correctly fail since there is a coalescence ofx<x+eps()
,x==x+0
andx>x-eps()
as x->Inf
, so that there is no single limiting value.)2. Inconsistent behavior of
nextfloat
andprevfloat
at different precisionsIf we take the argument in the preceding paragraph to be correct, then in the following, only
nextfloat(Inf16)
is correct:The text was updated successfully, but these errors were encountered: