Skip to content
This repository has been archived by the owner on Dec 10, 2023. It is now read-only.

Commit

Permalink
implement less than or equal to
Browse files Browse the repository at this point in the history
fixes #27
  • Loading branch information
dpo committed Aug 11, 2017
1 parent 67683c7 commit 1667885
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/DoubleDouble.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module DoubleDouble
export Double, Single
import Base:
convert,
*, +, -, /, sqrt, <,
*, +, -, /, sqrt, <, ,
rem, abs, rand, promote_rule,
show, big

Expand Down Expand Up @@ -103,10 +103,18 @@ Double(x::Irrational) = convert(Double{Float64}, x)

# <

function <{T}(x::Single{T}, y::Single{T})
x.hi < y.hi
end

{T}(x::Single{T}, y::Single{T}) = !(x > y)

function <{T}(x::Double{T}, y::Double{T})
x.hi + x.lo < y.hi + y.lo
end

{T}(x::Double{T}, y::Double{T}) = !(x > y)

# add12
function +{T}(x::Single{T},y::Single{T})
abs(x.hi) > abs(y.hi) ? Double(x.hi, y.hi) : Double(y.hi, x.hi)
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ dy = Double(y)

@test x == sx == dx
@test y == sy == dy
@test sy sx
@test dy dx

@test zero(Double{Float64}) == Double(0.0, 0.0)
@test one(Double{Float64}) == Double(1.0, 0.0)
Expand Down

0 comments on commit 1667885

Please sign in to comment.