Boost logo

Boost :

Subject: [boost] [math] lcm errors
From: Damian Vicino (damian.vicino_at_[hidden])
Date: 2015-08-28 10:22:29


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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk