Skip to content

Commit

Permalink
allow min and max on anything. fixes issue #238.
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Oct 27, 2011
1 parent c9f77c8 commit bb04adc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
5 changes: 4 additions & 1 deletion j/abstractarray.j
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ strides{T}(a::AbstractArray{T,2}) = (1, size(a,1))
strides{T}(a::AbstractArray{T,3}) = (1, size(a,1), size(a,1)*size(a,2))
strides (a::AbstractArray) = ntuple(ndims(a), i->stride(a,i))

iscomplex{T<:Complex}(x::AbstractArray{T}) = true
isreal{T<:Real}(::AbstractArray{T}) = true
isreal(::AbstractArray) = false
iscomplex{T<:Complex}(::AbstractArray{T}) = true
iscomplex(::AbstractArray) = false

## Constructors ##

Expand Down
2 changes: 1 addition & 1 deletion j/complex.j
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
abstract Complex{T<:Real} <: Number

iscomplex(x::Complex) = true
iscomplex(x) = false
iscomplex(x::Number) = false

real_valued(z::Complex) = (imag(z) == 0)
integer_valued(z::Complex) = (real_valued(z) && integer_valued(real(z)))
Expand Down
3 changes: 0 additions & 3 deletions j/number.j
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ transpose(x::Number) = x
ctranspose(x::Number) = conj(transpose(x))
inv(x::Number) = one(x)/x

max(x::Real, y::Real) = x > y ? x : y
min(x::Real, y::Real) = x < y ? x : y

# TODO: should we really treat numbers as iterable?
start(a::Real) = a
next(a::Real, i) = (a, a+1)
Expand Down
5 changes: 3 additions & 2 deletions j/operators.j
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ isequal(x::Number, y::Number) = (x==y)
<=(x,y) = x < y || x == y
>=(x,y) = y <= x

max(x, y) = x > y ? x : y
min(x, y) = x < y ? x : y

## definitions providing basic traits of arithmetic operators ##

+() = 0
*() = 1
&() = error("zero-argument & is ambiguous")
|() = error("zero-argument | is ambiguous")
($)() = error("zero-argument \$ is ambiguous")
max() = -Inf
min() = +Inf

+(x::Number) = x
*(x::Number) = x
Expand Down

0 comments on commit bb04adc

Please sign in to comment.