Mercurial > octave
changeset 30414:391b35ef8b24 stable
nchoosek: Improve warning messages about large outputs (bug #61565).
* scripts/specfun/nchoosek.m: Improve warning messages about large outputs.
author | Arun Giridhar <arungiridhar@gmail.com> |
---|---|
date | Thu, 02 Dec 2021 08:03:39 -0500 |
parents | 181c44079f6c |
children | e22183b892c6 4736bc8e9804 |
files | scripts/specfun/nchoosek.m |
diffstat | 1 files changed, 7 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/specfun/nchoosek.m Wed Dec 01 22:16:33 2021 +0100 +++ b/scripts/specfun/nchoosek.m Thu Dec 02 08:03:39 2021 -0500 @@ -141,8 +141,12 @@ until (isempty (denom)) C = prod (numer, "native"); - if (C > flintmax) - warning ("nchoosek: possible loss of precision"); + if (isfloat (C) && C > flintmax (C)) + warning ("Octave:nchoosek:large-output-float", ... + "nchoosek: possible loss of precision"); + elseif (isinteger (C) && C == intmax (C)) + warning ("Octave:nchoosek:large-output-integer", ... + "nchoosek: result may have saturated at intmax"); endif elseif (k == 0) C = v(zeros (1, 0)); # Return 1x0 object for Matlab compatibility @@ -287,3 +291,4 @@ %!error <N must be a non-negative integer .= K> nchoosek (-100, 45) %!error <N must be a non-negative integer .= K> nchoosek (100.5, 45) %!warning <possible loss of precision> nchoosek (100, 45); +%!warning <result .* saturated> nchoosek (uint64 (80), uint64 (40));