Skip to content

Commit

Permalink
sign(0)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmkuhn committed May 16, 2020
1 parent fff81f1 commit 0290ea1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/DecFP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ for w in (32,64,128)
Base.zero(::Union{Type{$BID},$BID}) = $(_parse(T, "0"))

Base.signbit(x::$BID) = $(zero(Ti)) != $(Ti(1) << (Ti(w - 1))) & x.x
Base.sign(x::$BID) = ifelse(isnan(x), x, ifelse(signbit(x), $(_parse(T, "-1")), $(_parse(T, "1"))))
Base.sign(x::$BID) = ifelse(isnan(x) || iszero(x), x, ifelse(signbit(x), $(_parse(T, "-1")), $(_parse(T, "1"))))

Base.nextfloat(x::$BID) = nox(_nextfloat(x))
Base.prevfloat(x::$BID) = nox(_prevfloat(x))
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ for T in (Dec32, Dec64, Dec128)
@test zero(T)::T == 0
@test signbit(xd) == signbit(x) && signbit(yd) == signbit(y) && signbit(parse(T,"-Inf"))
@test isnan(sign(T(NaN)))
@test isequal(sign(T(0.0)), T(0.0))
@test isequal(sign(T(-0.0)), T(-0.0))
@test sign(xd)::T == sign(x) && sign(yd)::T == sign(y)

@test nextfloat(xd)::T == xd + eps(T)
Expand Down

1 comment on commit 0290ea1

@jmkuhn
Copy link
Contributor Author

@jmkuhn jmkuhn commented on 0290ea1 May 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intended to do this as a PR, not a direct commit.

Please sign in to comment.