comparison scripts/specfun/lcm.m @ 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 5d3faba0342e
children 597f3ee61a48
comparison
equal deleted inserted replaced
31229:c967e74cc053 31230:6646f2b5a3d1
51 msk = (l == 0 & x == 0); 51 msk = (l == 0 & x == 0);
52 l .*= x ./ gcd (l, x); 52 l .*= x ./ gcd (l, x);
53 l(msk) = 0; 53 l(msk) = 0;
54 endfor 54 endfor
55 55
56 if (isfloat (l) && l > flintmax (l))
57 warning ("Octave:lcm:large-output-float", ...
58 "lcm: possible loss of precision");
59 elseif (isinteger (l) && l == intmax (l))
60 warning ("Octave:lcm:large-output-integer", ...
61 "lcm: result may have saturated at intmax");
62 endif
63
56 endfunction 64 endfunction
57 65
58 66
59 %!assert (lcm (3, 5, 7, 15), 105) 67 %!assert (lcm (3, 5, 7, 15), 105)
60 68
61 ## Test input validation 69 ## Test input validation
62 %!error <Invalid call> lcm () 70 %!error <Invalid call> lcm ()
63 %!error <Invalid call> lcm (1) 71 %!error <Invalid call> lcm (1)
64 %!error <same size or scalar> lcm ([1 2], [1 2 3]) 72 %!error <same size or scalar> lcm ([1 2], [1 2 3])
65 %!error <arguments must be numeric> lcm ([1 2], {1 2}) 73 %!error <arguments must be numeric> lcm ([1 2], {1 2})
74 %!warning <loss of precision> lcm (num2cell (double (1:47)){:});
75 %!warning <loss of precision> lcm (num2cell (single (1:47)){:});
76 %!warning <result .* saturated> lcm (num2cell (uint64 (1:47)){:});
77 %!warning <result .* saturated> lcm (num2cell (uint32 (1:47)){:});
78 %!warning <result .* saturated> lcm (num2cell (uint16 (1:47)){:});
79 %!warning <result .* saturated> lcm (num2cell ( uint8 (1:47)){:});
80 %!warning <result .* saturated> lcm (num2cell ( int64 (1:47)){:});
81 %!warning <result .* saturated> lcm (num2cell ( int32 (1:47)){:});
82 %!warning <result .* saturated> lcm (num2cell ( int16 (1:47)){:});
83 %!warning <result .* saturated> lcm (num2cell ( int8 (1:47)){:});