Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demonstrate interoperability with Boost.Rational #34

Closed
akrzemi1 opened this issue Mar 11, 2017 · 3 comments
Closed

Demonstrate interoperability with Boost.Rational #34

akrzemi1 opened this issue Mar 11, 2017 · 3 comments

Comments

@akrzemi1
Copy link
Member

The following example, which tests usage of rational<safe<int>> works fine. I would recommend adding a test like this in the library, and the examples list.

#include <safe_integer.hpp>
#include <iostream>
#include <limits>
#include <boost/rational.hpp>

int main(int argc, const char * argv[])
{
        using SafeRatio = boost::rational<boost::numeric::safe<int>>;
        SafeRatio r {1, 2};
        SafeRatio q {-2, 4};
        std::cout << (r * q) << std::endl;
        auto a = r * q;
        assert ((a == SafeRatio{-1, 4}));
        SafeRatio x {1, INT_MAX};
        SafeRatio y {1, 2};
        try {
                x * y;
                assert (false);
        }
        catch (std::exception const& e) {
                assert (true);
                std::cout << e.what() << std::endl;
        }
        x *= 2;
        x /= 2;

        assert ((x == SafeRatio{1, INT_MAX}));
        return 0;
}
@robertramey
Copy link
Member

robertramey commented Mar 11, 2017 via email

@robertramey
Copy link
Member

I had remembered to add test/example for using with rational but had forgotten that you included a working demo right here. Now when I try this test, it doesn't work on my current version of the library. I've made many, many corrections to the library in accordance with the review conditions and it seems that something has gotten lost in the shuffle. I'm still looking into this.

@robertramey
Copy link
Member

fixed - see example 15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants