
Hi, I found out, lcm (RT) is silent about errors. (the bad way) Is there any way to activate them? For example, the following code: #include<iostream> #include <boost/math/common_factor.hpp> int main () { int a = 1<<30; int b = 3; int c = boost::math::lcm(a, b); std::cout << "lcm of :" << a << " & " << b << " is " << c << std::endl; return 0; } Obtains the following result: lcm of :1073741824 & 3 is 1073741824 Which is not the right answer (because it is not divisible by 3), but neither it raised an exception or returned some special value. Is there any way I can make it raise an exception? I guess I could check everywhere it as: if (c%a != 0 || c%b != 1) throw std::exception(); But probably there is something implemented that I couldn’t find in the documentation. Best regards, Damian

Hi,
I found out, lcm (RT) is silent about errors. (the bad way) Is there any way to activate them?
From the docs: If the least common multiple is beyond the range of the integer type, the results are undefined.
For example, the following code: [...]
Obtains the following result:
lcm of :1073741824 & 3 is 1073741824
Which is not the right answer (because it is not divisible by 3), but neither it raised an exception or returned some special value.
To further define undefined: Currently, if the result is negative (i.e. signed integer overflow) the absolute value of the result is taken, which happens to also be 2^30. Best regards, Stefan
participants (2)
-
Damian Vicino
-
Stefan Floeren