| 884 | // Normalisation |
| 885 | template <typename IntType> |
| 886 | BOOST_CXX14_CONSTEXPR void rational<IntType>::normalize() |
| 887 | { |
| 888 | // Avoid repeated construction |
| 889 | IntType zero(0); |
| 890 | |
| 891 | if (den == zero) |
| 892 | BOOST_THROW_EXCEPTION(bad_rational()); |
| 893 | |
| 894 | // Handle the case of zero separately, to avoid division by zero |
| 895 | if (num == zero) { |
| 896 | den = IntType(1); |
| 897 | return; |
| 898 | } |
| 899 | |
| 900 | IntType g = integer::gcd(num, den); |
| 901 | |
| 902 | num /= g; |
| 903 | den /= g; |
| 904 | |
| 905 | if (den < -(std::numeric_limits<IntType>::max)()) { |
| 906 | BOOST_THROW_EXCEPTION(bad_rational("bad rational: non-zero singular denominator")); |
| 907 | } |
| 908 | |
| 909 | // Ensure that the denominator is positive |
| 910 | if (den < zero) { |
| 911 | num = -num; |
| 912 | den = -den; |
| 913 | } |
| 914 | |
| 915 | BOOST_ASSERT( this->test_invariant() ); |
| 916 | } |
| 917 | |
| 918 | #ifndef BOOST_NO_IOSTREAM |
| 919 | namespace detail { |
nothing calls this directly
no test coverage detected