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

Commit

Permalink
Add methods for zero and one with tests (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
lbenet authored and simonbyrne committed Mar 11, 2017
1 parent 8cd85d6 commit 7c4e979
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/DoubleDouble.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import Base:
convert,
*, +, -, /, sqrt, <,
rem, abs, rand, promote_rule,
show, big
show, big,
zero, one

abstract AbstractDouble{T} <: Real

Expand Down Expand Up @@ -51,6 +52,11 @@ function splitprec(x::AbstractFloat)
end


zero{T<:AbstractFloat}(::Type{Double{T}}) = Double(zero(T))
one{T<:AbstractFloat}(::Type{Double{T}}) = Double(one(T))
zero(a::Double) = Double(zero(a.hi))
one(a::Double) = Double(one(a.hi))

# ones(T::Double, dims...) = fill!(Array(T, dims...), (one)(T))
# zeros(T::Double, dims...) = fill!(Array(T, dims...), (zero)(T))

Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ dy = Double(y)
@test x == sx == dx
@test y == sy == dy

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

dxy = dx*dy
bxy = bx*by
@test sx*sy == dxy
Expand Down

0 comments on commit 7c4e979

Please sign in to comment.