Skip to content

Commit

Permalink
Compatibility with 0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
perrutquist committed Jul 3, 2018
1 parent d30ca25 commit d66ff95
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ os:
- linux
- osx
julia:
- 0.6
- 0.7
- nightly
notifications:
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
julia 0.7
julia 0.6
14 changes: 13 additions & 1 deletion src/Zeros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export Zero, testzero, zero!
struct Zero <: Integer
end

Zero(x::Number) = iszero(x) ? Zero() : throw(InexactError(:Zero, Zero, x))

promote_rule(::Type{Zero}, ::Type{T}) where {T<:Number} = T
promote_rule(::Type{Zero}, ::Type{Zero}) = Float64
Expand All @@ -21,6 +20,19 @@ convert(::Type{Zero}, ::Zero) = Zero()
convert(::Type{T}, ::Zero) where {T<:Number} = zero(T)
convert(::Type{Zero}, x::T) where {T<:Number} = Zero(x)

if VERSION < v"0.7-"
Zero(x::Number) = iszero(x) ? Zero() : throw(InexactError())

# Disambiguation needed for Julia 0.6
convert(::Type{T}, ::Zero) where {T<:Real} = zero(T)
convert(::Type{BigInt}, ::Zero) = zero(BigInt)
convert(::Type{BigFloat}, ::Zero) = zero(BigFloat)
convert(::Type{Float16}, ::Zero) = zero(Float16)
convert(::Type{Complex{T}}, ::Zero) where {T<:Real} = zero(Complex{T})
else
Zero(x::Number) = iszero(x) ? Zero() : throw(InexactError(:Zero, Zero, x))
end

AbstractFloat(::Zero) = 0.0

Complex(x::Real, ::Zero) = x
Expand Down
6 changes: 5 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using Zeros
using Test
if VERSION < v"0.7-"
using Base.Test
else
using Test
end

# Real
Z = Zero()
Expand Down

0 comments on commit d66ff95

Please sign in to comment.