Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class template static_rational

boost::units::static_rational

Synopsis

// In header: <boost/units/static_rational.hpp>

template<integer_type N, integer_type D = 1> 
class static_rational {
public:
  // types
  typedef unspecified                               tag; 
  typedef static_rational< Numerator, Denominator > type;  // static_rational<N,D> reduced by GCD 

  // construct/copy/destruct
  static_rational();

  // public static functions
  static BOOST_CONSTEXPR integer_type numerator();
  static BOOST_CONSTEXPR integer_type denominator();

  // public data members
  BOOST_STATIC_CONSTEXPR integer_type Numerator;
  BOOST_STATIC_CONSTEXPR integer_type Denominator;
};

Description

This is an implementation of a compile time rational number, where static_rational<N,D> represents a rational number with numerator N and denominator D. Because of the potential for ambiguity arising from multiple equivalent values of static_rational (e.g. static_rational<6,2>==static_rational<3>), static rationals should always be accessed through static_rational<N,D>::type. Template specialization prevents instantiation of zero denominators (i.e. static_rational<N,0>). The following compile-time arithmetic operators are provided for static_rational variables only (no operators are defined between long and static_rational):

  • mpl::negate

  • mpl::plus

  • mpl::minus

  • mpl::times

  • mpl::divides

Neither static_power nor static_root are defined for static_rational. This is because template types may not be floating point values, while powers and roots of rational numbers can produce floating point values.

static_rational public construct/copy/destruct

  1. static_rational();

static_rational public static functions

  1. static BOOST_CONSTEXPR integer_type numerator();
  2. static BOOST_CONSTEXPR integer_type denominator();

PrevUpHomeNext