MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / normalize

Method normalize

extern/boost/boost/rational.hpp:886–916  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

884// Normalisation
885template <typename IntType>
886BOOST_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
919namespace detail {

Callers

nothing calls this directly

Calls 3

test_invariantMethod · 0.95
bad_rationalClass · 0.85
gcdFunction · 0.70

Tested by

no test coverage detected