Skip to content

Commit

Permalink
Clarifying two situations of overflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
shizejin committed Jan 7, 2018
1 parent 1e44060 commit a645c2d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,10 @@ the descending sequences of the elements, following
# Notes
`InexactError` exception will be thrown if overflow occurs during
the computation. It is the user's responsibility to ensure
that the rank of the input array fits within the range of `T`;
a sufficient condition for it is
`InexactError` exception will be thrown, or an incorrect value will be
returned without warning if overflow occurs during the computation.
It is the user's responsibility to ensure that the rank of the input
array fits within the range of `T`; a sufficient condition for it is
`binomial(BigInt(a[end]), BigInt(length(a))) <= typemax(T)`.
# Arguments
Expand Down
6 changes: 6 additions & 0 deletions test/test_util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,16 @@

@test k_arrays_computed == k_arrays

# test InexactError when ranking is out of range
n, k = 100, 50
@test k_array_rank(BigInt, collect(n-k+1:n)) == binomial(BigInt(n), BigInt(k))
@test_throws InexactError k_array_rank(collect(n-k+1:n))

# test returning wrong value when ranking is out of range
n, k = 68, 29
@test k_array_rank(BigInt, collect(n-k+1:n)) == binomial(BigInt(n), BigInt(k))
@test k_array_rank(collect(n-k+1:n)) != binomial(BigInt(n), BigInt(k))

end

end

0 comments on commit a645c2d

Please sign in to comment.