Skip to content

Commit 19f0633

Browse files
committed
Fix floor(::FD) at the input limits
1 parent 4856c57 commit 19f0633

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/FixedPointDecimals.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ end
162162

163163
# integerification
164164
trunc{T, f}(x::FD{T, f}) = FD{T, f}(div(x.i, coefficient(FD{T, f})))
165-
floor{T, f}(x::FD{T, f}) = FD{T, f}(fld(x.i, T(10)^f))
165+
floor{T, f}(x::FD{T, f}) = FD{T, f}(fld(x.i, coefficient(FD{T, f})))
166+
166167
# TODO: round with number of digits; should be easy
167168
function round{T, f}(x::FD{T, f}, ::RoundingMode{:Nearest}=RoundNearest)
168169
powt = T(10)^f

test/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,14 @@ epsi{T}(::Type{T}) = eps(T)
581581

582582
@test value(ceil(FD{$T,$f}, max_dec)) in [max_int, signed(widen(max_int)) + 1]
583583
@test value(ceil(FD{$T,$f}, min_dec)) in [min_int, min_int + 1]
584+
585+
# Note: all values `x` in FD{T,f} are -1 < x < 1
586+
@test floor(reinterpret(FD{$T,$f}, typemax($T))) == zero(FD{$T,$f})
587+
if $T <: Unsigned
588+
@test floor(reinterpret(FD{$T,$f}, typemin($T))) == zero(FD{$T,$f})
589+
else
590+
@test_throws InexactError floor(reinterpret(FD{$T,$f}, typemin($T)))
591+
end
584592
end
585593
end
586594
end

0 commit comments

Comments
 (0)