Skip to content

Commit 18be9a7

Browse files
committed
Fix trunc of FD at the input limits
1 parent 3690d95 commit 18be9a7

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/FixedPointDecimals.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ function /{T, f}(x::FD{T, f}, y::Integer)
161161
end
162162

163163
# integerification
164-
trunc{T, f}(x::FD{T, f}) = FD{T, f}(div(x.i, T(10)^f))
164+
trunc{T, f}(x::FD{T, f}) = FD{T, f}(div(x.i, coefficient(FD{T, f})))
165165
floor{T, f}(x::FD{T, f}) = FD{T, f}(fld(x.i, T(10)^f))
166166
# TODO: round with number of digits; should be easy
167167
function round{T, f}(x::FD{T, f}, ::RoundingMode{:Nearest}=RoundNearest)

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,10 @@ end
481481
# we can have the expected result be a little flexible.
482482
@test value(trunc(FD{$T,$f}, max_int / powt)) in [max_int, max_int - 1]
483483
@test value(trunc(FD{$T,$f}, min_int / powt)) in [min_int, min_int + 1]
484+
485+
# Note: all values `x` in FD{T,f} are -1 < x < 1
486+
@test trunc(reinterpret(FD{$T,$f}, typemax($T))) == zero(FD{$T,$f})
487+
@test trunc(reinterpret(FD{$T,$f}, typemin($T))) == zero(FD{$T,$f})
484488
end
485489
end
486490
end

0 commit comments

Comments
 (0)