![]() |
Home | Libraries | People | FAQ | More |
boost::units::static_rational — Compile time rational number.
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 integer_type numerator() ; static integer_type denominator() ; static const integer_type Numerator; static const integer_type Denominator; };
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):
這是編譯時有理數的實現,static_rational<N,D>其中分子是N,分母是D。因為多個static_rational相等的二義性(例如static_rational<6,2>==static_rational<3>),靜態有理數總是應該通過static_rational<N,D>::type訪問。模板特化阻止了分母為0的情況(例如static_rational<N,0>)。以下的編譯時算術運算符只能應用於static_rational變量(沒有long和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_power和static_root都不是為static_rational定義的。因為模板類型不能是浮點數,而有理數的乘方開方都會生成浮點數。