summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '3rdParty/Boost/src/boost/rational.hpp')
-rw-r--r--3rdParty/Boost/src/boost/rational.hpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/3rdParty/Boost/src/boost/rational.hpp b/3rdParty/Boost/src/boost/rational.hpp
index 468db79..fd04b6b 100644
--- a/3rdParty/Boost/src/boost/rational.hpp
+++ b/3rdParty/Boost/src/boost/rational.hpp
@@ -1,68 +1,68 @@
// Boost rational.hpp header file ------------------------------------------//
// (C) Copyright Paul Moore 1999. Permission to copy, use, modify, sell and
// distribute this software is granted provided this copyright notice appears
// in all copies. This software is provided "as is" without express or
// implied warranty, and with no claim as to its suitability for any purpose.
// boostinspect:nolicense (don't complain about the lack of a Boost license)
// (Paul Moore hasn't been in contact for years, so there's no way to change the
// license.)
// See http://www.boost.org/libs/rational for documentation.
// Credits:
// Thanks to the boost mailing list in general for useful comments.
// Particular contributions included:
// Andrew D Jewell, for reminding me to take care to avoid overflow
// Ed Brey, for many comments, including picking up on some dreadful typos
// Stephen Silver contributed the test suite and comments on user-defined
// IntType
// Nickolay Mladenov, for the implementation of operator+=
// Revision History
// 05 Nov 06 Change rational_cast to not depend on division between different
// types (Daryle Walker)
// 04 Nov 06 Off-load GCD and LCM to Boost.Math; add some invariant checks;
// add std::numeric_limits<> requirement to help GCD (Daryle Walker)
// 31 Oct 06 Recoded both operator< to use round-to-negative-infinity
// divisions; the rational-value version now uses continued fraction
// expansion to avoid overflows, for bug #798357 (Daryle Walker)
-// 20 Oct 06 Fix operator bool_type for CW 8.3 (Joaquín M López Muñoz)
+// 20 Oct 06 Fix operator bool_type for CW 8.3 (Joaquín M López Muñoz)
// 18 Oct 06 Use EXPLICIT_TEMPLATE_TYPE helper macros from Boost.Config
-// (Joaquín M López Muñoz)
+// (Joaquín M López Muñoz)
// 27 Dec 05 Add Boolean conversion operator (Daryle Walker)
// 28 Sep 02 Use _left versions of operators from operators.hpp
// 05 Jul 01 Recode gcd(), avoiding std::swap (Helmut Zeisel)
// 03 Mar 01 Workarounds for Intel C++ 5.0 (David Abrahams)
// 05 Feb 01 Update operator>> to tighten up input syntax
// 05 Feb 01 Final tidy up of gcd code prior to the new release
// 27 Jan 01 Recode abs() without relying on abs(IntType)
// 21 Jan 01 Include Nickolay Mladenov's operator+= algorithm,
// tidy up a number of areas, use newer features of operators.hpp
// (reduces space overhead to zero), add operator!,
// introduce explicit mixed-mode arithmetic operations
// 12 Jan 01 Include fixes to handle a user-defined IntType better
// 19 Nov 00 Throw on divide by zero in operator /= (John (EBo) David)
// 23 Jun 00 Incorporate changes from Mark Rodgers for Borland C++
// 22 Jun 00 Change _MSC_VER to BOOST_MSVC so other compilers are not
// affected (Beman Dawes)
// 6 Mar 00 Fix operator-= normalization, #include <string> (Jens Maurer)
// 14 Dec 99 Modifications based on comments from the boost list
// 09 Dec 99 Initial Version (Paul Moore)
#ifndef BOOST_RATIONAL_HPP
#define BOOST_RATIONAL_HPP
#include <iostream> // for std::istream and std::ostream
#include <ios> // for std::noskipws
#include <stdexcept> // for std::domain_error
#include <string> // for std::string implicit constructor
#include <boost/operators.hpp> // for boost::addable etc
#include <cstdlib> // for std::abs
#include <boost/call_traits.hpp> // for boost::call_traits
#include <boost/config.hpp> // for BOOST_NO_STDC_NAMESPACE, BOOST_MSVC
#include <boost/detail/workaround.hpp> // for BOOST_WORKAROUND
#include <boost/assert.hpp> // for BOOST_ASSERT
#include <boost/math/common_factor_rt.hpp> // for boost::math::gcd, lcm
#include <limits> // for std::numeric_limits
@@ -357,73 +357,75 @@ rational<IntType>::operator/= (param_type i)
}
// Increment and decrement
template <typename IntType>
inline const rational<IntType>& rational<IntType>::operator++()
{
// This can never denormalise the fraction
num += den;
return *this;
}
template <typename IntType>
inline const rational<IntType>& rational<IntType>::operator--()
{
// This can never denormalise the fraction
num -= den;
return *this;
}
// Comparison operators
template <typename IntType>
bool rational<IntType>::operator< (const rational<IntType>& r) const
{
// Avoid repeated construction
int_type const zero( 0 );
// This should really be a class-wide invariant. The reason for these
// checks is that for 2's complement systems, INT_MIN has no corresponding
// positive, so negating it during normalization keeps it INT_MIN, which
// is bad for later calculations that assume a positive denominator.
BOOST_ASSERT( this->den > zero );
BOOST_ASSERT( r.den > zero );
// Determine relative order by expanding each value to its simple continued
// fraction representation using the Euclidian GCD algorithm.
- struct { int_type n, d, q, r; } ts = { this->num, this->den, this->num /
- this->den, this->num % this->den }, rs = { r.num, r.den, r.num / r.den,
- r.num % r.den };
+ struct { int_type n, d, q, r; }
+ ts = { this->num, this->den, static_cast<int_type>(this->num / this->den),
+ static_cast<int_type>(this->num % this->den) },
+ rs = { r.num, r.den, static_cast<int_type>(r.num / r.den),
+ static_cast<int_type>(r.num % r.den) };
unsigned reverse = 0u;
// Normalize negative moduli by repeatedly adding the (positive) denominator
// and decrementing the quotient. Later cycles should have all positive
// values, so this only has to be done for the first cycle. (The rules of
// C++ require a nonnegative quotient & remainder for a nonnegative dividend
// & positive divisor.)
while ( ts.r < zero ) { ts.r += ts.d; --ts.q; }
while ( rs.r < zero ) { rs.r += rs.d; --rs.q; }
// Loop through and compare each variable's continued-fraction components
while ( true )
{
// The quotients of the current cycle are the continued-fraction
// components. Comparing two c.f. is comparing their sequences,
// stopping at the first difference.
if ( ts.q != rs.q )
{
// Since reciprocation changes the relative order of two variables,
// and c.f. use reciprocals, the less/greater-than test reverses
// after each index. (Start w/ non-reversed @ whole-number place.)
return reverse ? ts.q > rs.q : ts.q < rs.q;
}
// Prepare the next cycle
reverse ^= 1u;
if ( (ts.r == zero) || (rs.r == zero) )
{
// At least one variable's c.f. expansion has ended
break;
}
ts.n = ts.d; ts.d = ts.r;
ts.q = ts.n / ts.d; ts.r = ts.n % ts.d;