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

implement less than or equal to #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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