Skip to content

Commit

Permalink
restore former behavior of isless as a total order
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed May 7, 2014
1 parent 9a48950 commit 9738dd3
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
3 changes: 2 additions & 1 deletion base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ isequal(x::FloatingPoint, y::FloatingPoint) = (isnan(x) & isnan(y)) | (signbit(x
isequal(x::Real, y::FloatingPoint) = (isnan(x) & isnan(y)) | (signbit(x) == signbit(y)) & (x == y)
isequal(x::FloatingPoint, y::Real ) = (isnan(x) & isnan(y)) | (signbit(x) == signbit(y)) & (x == y)

isless(x::Any, y::Any) = x < y
isless(x::FloatingPoint, y::FloatingPoint) = (!isnan(x) & isnan(y)) | (signbit(x) & !signbit(y)) | (x < y)
isless(x::Real, y::FloatingPoint) = (!isnan(x) & isnan(y)) | (signbit(x) & !signbit(y)) | (x < y)
isless(x::FloatingPoint, y::Real ) = (!isnan(x) & isnan(y)) | (signbit(x) & !signbit(y)) | (x < y)
Expand All @@ -27,6 +26,7 @@ isless(x::FloatingPoint, y::Real ) = (!isnan(x) & isnan(y)) | (signbit(x
!=(x,y) = !(x==y)
!==(x,y) = !is(x,y)

<(x,y) = isless(x,y)
>(x,y) = y < x
<=(x,y) = !(y < x)
>=(x,y) = (y <= x)
Expand All @@ -35,6 +35,7 @@ isless(x::FloatingPoint, y::Real ) = (!isnan(x) & isnan(y)) | (signbit(x

# this definition allows Number types to implement < instead of isless,
# which is more idiomatic:
isless(x::Real, y::Real) = x<y
lexcmp(x::Real, y::Real) = isless(x,y) ? -1 : ifelse(isless(y,x), 1, 0)

ifelse(c::Bool, x, y) = Intrinsics.select_value(c, x, y)
Expand Down
2 changes: 1 addition & 1 deletion base/pkg/resolve/fieldvalue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Base.typemin(::Type{FieldValue}) = (x=typemin(Int); y=typemin(VersionWeight); Fi
Base.(:-)(a::FieldValue, b::FieldValue) = FieldValue(a.l0-b.l0, a.l1-b.l1, a.l2-b.l2, a.l3-b.l3, a.l4-b.l4)
Base.(:+)(a::FieldValue, b::FieldValue) = FieldValue(a.l0+b.l0, a.l1+b.l1, a.l2+b.l2, a.l3+b.l3, a.l4+b.l4)

function <(a::FieldValue, b::FieldValue)
function Base.isless(a::FieldValue, b::FieldValue)
a.l0 < b.l0 && return true
a.l0 > b.l0 && return false
c = cmp(a.l1, b.l1)
Expand Down
8 changes: 4 additions & 4 deletions base/pkg/resolve/versionweight.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function Base.cmp{T}(a::HierarchicalValue{T}, b::HierarchicalValue{T})
end
return cmp(a.rest, b.rest)
end
<{T}(a::HierarchicalValue{T}, b::HierarchicalValue{T}) = cmp(a,b) < 0
Base.isless{T}(a::HierarchicalValue{T}, b::HierarchicalValue{T}) = cmp(a,b) < 0
=={T}(a::HierarchicalValue{T}, b::HierarchicalValue{T}) = a.v == b.v && a.rest == b.rest

Base.abs{T}(a::HierarchicalValue{T}) = HierarchicalValue(T[abs(x) for x in a.v], abs(a.rest))
Expand Down Expand Up @@ -88,7 +88,7 @@ function Base.cmp(a::VWPreBuildItem, b::VWPreBuildItem)
c = cmp(a.s, b.s); c != 0 && return c
return cmp(a.i, b.i)
end
<(a::VWPreBuildItem, b::VWPreBuildItem) = cmp(a,b) < 0
Base.isless(a::VWPreBuildItem, b::VWPreBuildItem) = cmp(a,b) < 0
==(a::VWPreBuildItem, b::VWPreBuildItem) = cmp(a,b) == 0

Base.abs(a::VWPreBuildItem) = VWPreBuildItem(abs(a.nonempty), abs(a.s), abs(a.i))
Expand Down Expand Up @@ -125,7 +125,7 @@ function Base.cmp(a::VWPreBuild, b::VWPreBuild)
c = cmp(a.nonempty, b.nonempty); c != 0 && return c
return cmp(a.w, b.w)
end
<(a::VWPreBuild, b::VWPreBuild) = cmp(a,b) < 0
Base.isless(a::VWPreBuild, b::VWPreBuild) = cmp(a,b) < 0
==(a::VWPreBuild, b::VWPreBuild) = cmp(a,b) == 0

Base.abs(a::VWPreBuild) = VWPreBuild(abs(a.nonempty), abs(a.w))
Expand Down Expand Up @@ -179,7 +179,7 @@ function Base.cmp(a::VersionWeight, b::VersionWeight)
c = cmp(a.build, b.build); c != 0 && return c
return cmp(a.uninstall, b.uninstall)
end
<(a::VersionWeight, b::VersionWeight) = cmp(a,b) < 0
Base.isless(a::VersionWeight, b::VersionWeight) = cmp(a,b) < 0
==(a::VersionWeight, b::VersionWeight) = cmp(a,b) == 0

Base.abs(a::VersionWeight) =
Expand Down
4 changes: 2 additions & 2 deletions base/string.jl
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ function cmp(a::String, b::String)
end

==(a::String, b::String) = cmp(a,b) == 0
< (a::String, b::String) = cmp(a,b) < 0
isless(a::String, b::String) = cmp(a,b) < 0

# begins with and ends with predicates

Expand Down Expand Up @@ -521,7 +521,7 @@ cmp(a::ByteString, b::ByteString) = lexcmp(a.data, b.data)
cmp(a::Symbol, b::Symbol) = int(sign(ccall(:strcmp, Int32, (Ptr{Uint8}, Ptr{Uint8}), a, b)))

==(a::ByteString, b::ByteString) = endof(a) == endof(b) && cmp(a,b) == 0
<(a::Symbol, b::Symbol) = cmp(a,b) < 0
isless(a::Symbol, b::Symbol) = cmp(a,b) < 0

beginswith(a::ByteString, b::ByteString) = beginswith(a.data, b.data)
beginswith(a::Array{Uint8,1}, b::Array{Uint8,1}) =
Expand Down
2 changes: 1 addition & 1 deletion base/version.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ end

issupbuild(v::VersionNumber) = length(v.build)==1 && isempty(v.build[1])

function <(a::VersionNumber, b::VersionNumber)
function isless(a::VersionNumber, b::VersionNumber)
(a.major < b.major) && return true
(a.major > b.major) && return false
(a.minor < b.minor) && return true
Expand Down
8 changes: 4 additions & 4 deletions doc/stdlib/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ All Objects

.. function:: isequal(x, y)

Similar to ``==``, except treats all floating-point ``NaN`` values as equal to each other
and greater than all other real values, and treats ``-0.0`` as unequal to ``0.0``.
Similar to ``==``, except treats all floating-point ``NaN`` values as equal to each other,
and treats ``-0.0`` as unequal to ``0.0``.
For values that are not floating-point, ``isequal`` is the same as ``==``.

``isequal`` is the comparison function used by hash tables (``Dict``).
``isequal(x,y)`` must imply that ``hash(x) == hash(y)``.

Mutable containers typically implement ``isequal`` by calling ``isequal`` recursively on
Collections typically implement ``isequal`` by calling ``isequal`` recursively on
all contents.

Scalar types generally do not need to implement ``isequal``, unless they
Expand Down Expand Up @@ -2282,7 +2282,7 @@ Mathematical Operators

Follows IEEE semantics for floating-point numbers.

Mutable containers should generally implement ``==`` by calling ``==`` recursively on all contents.
Collections should generally implement ``==`` by calling ``==`` recursively on all contents.

New numeric types should implement this function for two arguments of the new type, and handle
comparison to other types via promotion rules where possible.
Expand Down

1 comment on commit 9738dd3

@StefanKarpinski
Copy link
Member

Choose a reason for hiding this comment

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

Thanks. I obviously did not get a chance to do this. Glad to see this merged at long last.

Please sign in to comment.