<ratio>
Include the standard header <ratio>
to define several templates to store and manipulate rational numbers
at compile time, as well as several useful constants.
atto
· centi
· deca
· deci
· exa
· femto
· giga
· hecto
· kilo
· mega
· micro
· milli
· nano
· peta
· pico
· ratio
· ratio_add
· ratio_divide
· ratio_equal
· ratio_greater
· ratio_greater_equal
· ratio_less
· ratio_less_equal
· ratio_multiply
· ratio_not_equal
· ratio_subtract
· tera
· yocto
· yotta
· zepto
· zetta
namespace std { // TEMPLATE CLASS ratio template <intmax_t N, intmax_t D = 1> struct ratio; // ratio ARITHMETIC template <class R1, class R2> struct ratio_add; template <class R1, class R2> struct ratio_subtract; template <class R1, class R2> struct ratio_multiply; template <class R1, class R2> struct ratio_divide; // ratio COMPARISON template <class R1, class R2> struct ratio_equal; template <class R1, class R2> struct ratio_not_equal; template <class R1, class R2> struct ratio_less; template <class R1, class R2> struct ratio_less_equal; template <class R1, class R2> struct ratio_greater; template <class R1, class R2> struct ratio_greater_equal; // ratio CONSTANTS typedef ratio<1, 1000000000000000000000000> yocto; typedef ratio<1, 1000000000000000000000> zepto; typedef ratio<1, 1000000000000000000> atto; typedef ratio<1, 1000000000000000> femto; typedef ratio<1, 1000000000000> pico; typedef ratio<1, 1000000000> nano; typedef ratio<1, 1000000> micro; typedef ratio<1, 1000> milli; typedef ratio<1, 100> centi; typedef ratio<1, 10> deci; typedef ratio< 10, 1> deca; typedef ratio< 100, 1> hecto; typedef ratio< 1000, 1> kilo; typedef ratio< 1000000, 1> mega; typedef ratio< 1000000000, 1> giga; typedef ratio< 1000000000000, 1> tera; typedef ratio< 1000000000000000, 1> peta; typedef ratio< 1000000000000000000, 1> exa; typedef ratio< 10000000000000000000000, 1> zetta; typedef ratio<10000000000000000000000000, 1> yotta; } // namespace std
constants
typedef ratio<1, 1000000000000000000000000> yocto; [optional] typedef ratio<1, 1000000000000000000000> zepto; [optional] typedef ratio<1, 1000000000000000000> atto; typedef ratio<1, 1000000000000000> femto; typedef ratio<1, 1000000000000> pico; typedef ratio<1, 1000000000> nano; typedef ratio<1, 1000000> micro; typedef ratio<1, 1000> milli; typedef ratio<1, 100> centi; typedef ratio<1, 10> deci; typedef ratio< 10, 1> deca; typedef ratio< 100, 1> hecto; typedef ratio< 1000, 1> kilo; typedef ratio< 1000000, 1> mega; typedef ratio< 1000000000, 1> giga; typedef ratio< 1000000000000, 1> tera; typedef ratio< 1000000000000000, 1> peta; typedef ratio< 1000000000000000000, 1> exa; typedef ratio< 10000000000000000000000, 1> zetta; [optional] typedef ratio<10000000000000000000000000, 1> yotta; [optional]
ratio
template <intmax_t N, intmax_t D = 1> struct ratio { static constexpr intmax_t num; static constexpr intmax_t den; typedef ratio<num, den> type; };
The template class defines the static constants
num
and den
such that
num / den == N / D
and num
and den
have no common factors.
num / den
is the
value represented by
the template class.
Thus, type
designates the instantiation
ratio<N0, D0>
for which num == N0
and den == D0
.
ratio_add
template <class R1, class R2> struct ratio_add { typedef see below type; };
The template class defines type
as a specialization
of ratio
whose value
is the value of R1
plus
the value of R2
.
R1
and R2
must both be specializations
of template class ratio
.
If an implementation supports template aliases,
ratio_add<R1, R2>
is a synonym for
ratio_add<R1, R2>::type
.
ratio_divide
template <class R1, class R2> struct ratio_divide { typedef see below type; };
The template class defines type
as a specialization
of ratio
whose value
is the value of R1
divided by
the value of R2
.
R1
and R2
must both be specializations
of template class ratio
.
If an implementation supports template aliases,
ratio_divide<R1, R2>
is a synonym for
ratio_divide<R1, R2>::type
.
ratio_equal
template <class R1, class R2> struct ratio_equal { typedef bool type; static const bool value = see below; };
The template class defines type
as bool
and value
as true only if
the value of R1
is equal to
the value of R2
.
R1
and R2
must both be specializations
of template class ratio
.
ratio_greater
template <class R1, class R2> struct ratio_greater { typedef bool type; static const bool value = see below; };
The template class defines type
as bool
and value
as true only if
the value of R1
is greater than
the value of R2
.
R1
and R2
must both be specializations
of template class ratio
.
ratio_greater_equal
template <class R1, class R2> struct ratio_greater_equal { typedef bool type; static const bool value = see below; };
The template class defines type
as bool
and value
as true only if
the value of R1
is greater than or equal to
the value of R2
.
R1
and R2
must both be specializations
of template class ratio
.
ratio_less
template <class R1, class R2> struct ratio_less { typedef bool type; static const bool value = see below; };
The template class defines type
as bool
and value
as true only if
the value of R1
is less than
the value of R2
.
R1
and R2
must both be specializations
of template class ratio
.
ratio_less_equal
template <class R1, class R2> struct ratio_less_equal { typedef bool type; static const bool value = see below; };
The template class defines type
as bool
and value
as true only if
the value of R1
is less than or equal to
the value of R2
.
R1
and R2
must both be specializations
of template class ratio
.
ratio_multiply
template <class R1, class R2> struct ratio_multiply { typedef see below type; };
The template class defines type
as a specialization
of ratio
whose value
is the value of R1
times
the value of R2
.
R1
and R2
must both be specializations
of template class ratio
.
If an implementation supports template aliases,
ratio_multiply<R1, R2>
is a synonym for
ratio_multiply<R1, R2>::type
.
ratio_not_equal
template <class R1, class R2> struct ratio_not_equal { typedef bool type; static const bool value = see below; };
The template class defines type
as bool
and value
as true only if
the value of R1
is not equal to
the value of R2
.
R1
and R2
must both be specializations
of template class ratio
.
ratio_subtract
template <class R1, class R2> struct ratio_subtract { typedef see below type; };
The template class defines type
as a specialization
of ratio
whose value
is the value of R1
minus
the value of R2
.
R1
and R2
must both be specializations
of template class ratio
.
If an implementation supports template aliases,
ratio_subtract<R1, R2>
is a synonym for
ratio_subtract<R1, R2>::type
.
See also the Table of Contents and the Index.
Copyright © 1992-2013 by P.J. Plauger. All rights reserved.