Skip to content

Commit 21843e8

Browse files
committed
Fix ceil(::FD) at the input limits
1 parent 19f0633 commit 21843e8

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/FixedPointDecimals.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function round{T, f}(x::FD{T, f}, ::RoundingMode{:Nearest}=RoundNearest)
171171
FD{T, f}(_round_to_even(quotient, remainder, powt))
172172
end
173173
function ceil{T, f}(x::FD{T, f})
174-
powt = T(10)^f
174+
powt = coefficient(FD{T, f})
175175
quotient, remainder = fldmod(x.i, powt)
176176
if remainder > 0
177177
FD{T, f}(quotient + one(quotient))

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,9 @@ epsi{T}(::Type{T}) = eps(T)
589589
else
590590
@test_throws InexactError floor(reinterpret(FD{$T,$f}, typemin($T)))
591591
end
592+
593+
@test_throws InexactError ceil(reinterpret(FD{$T,$f}, typemax($T)))
594+
@test ceil(reinterpret(FD{$T,$f}, typemin($T))) == zero(FD{$T,$f})
592595
end
593596
end
594597
end

0 commit comments

Comments
 (0)