Mercurial > octave
changeset 31230:6646f2b5a3d1
lcm.m: Emit warnings when results not exact (Bug #32924)
author | Arun Giridhar <arungiridhar@gmail.com> |
---|---|
date | Sat, 17 Sep 2022 04:22:38 -0400 |
parents | c967e74cc053 |
children | a026fb2be108 |
files | scripts/specfun/lcm.m |
diffstat | 1 files changed, 18 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/specfun/lcm.m Thu Sep 15 16:59:09 2022 -0700 +++ b/scripts/specfun/lcm.m Sat Sep 17 04:22:38 2022 -0400 @@ -53,6 +53,14 @@ l(msk) = 0; endfor + if (isfloat (l) && l > flintmax (l)) + warning ("Octave:lcm:large-output-float", ... + "lcm: possible loss of precision"); + elseif (isinteger (l) && l == intmax (l)) + warning ("Octave:lcm:large-output-integer", ... + "lcm: result may have saturated at intmax"); + endif + endfunction @@ -63,3 +71,13 @@ %!error <Invalid call> lcm (1) %!error <same size or scalar> lcm ([1 2], [1 2 3]) %!error <arguments must be numeric> lcm ([1 2], {1 2}) +%!warning <loss of precision> lcm (num2cell (double (1:47)){:}); +%!warning <loss of precision> lcm (num2cell (single (1:47)){:}); +%!warning <result .* saturated> lcm (num2cell (uint64 (1:47)){:}); +%!warning <result .* saturated> lcm (num2cell (uint32 (1:47)){:}); +%!warning <result .* saturated> lcm (num2cell (uint16 (1:47)){:}); +%!warning <result .* saturated> lcm (num2cell ( uint8 (1:47)){:}); +%!warning <result .* saturated> lcm (num2cell ( int64 (1:47)){:}); +%!warning <result .* saturated> lcm (num2cell ( int32 (1:47)){:}); +%!warning <result .* saturated> lcm (num2cell ( int16 (1:47)){:}); +%!warning <result .* saturated> lcm (num2cell ( int8 (1:47)){:});