<ratio>

컴파일 시간에 합리적인 숫자를 저장하고 조작하는 데 사용되는 상수 및 템플릿을 정의하는 표준 헤더 <비율을> 포함합니다.

구문

#include <ratio>

비율 템플릿

template<std::intmax_t Numerator, std::intmax_t Denominator = 1>
struct ratio // holds the ratio of Numerator to Denominator
{
   static constexpr std::intmax_t num;
   static constexpr std::intmax_t den;
   typedef ratio<num, den> type;
}

템플릿 ratio 은 정적 상수 num 및 / numdenden == Numerator/분모를 정의하며 numden 공통 요소가 없습니다. num / den 는 클래스 템플릿으로 표현되는 값입니다. 따라서 type 인스턴스화를 지정합니다.ratio<num, den>

특수화

<비율> 은 다음 형식의 ratio 특수화도 정의합니다.

template <class R1, class R2> struct ratio_specialization

각 특수화에서는 템플릿 매개 변수 두 개를 사용하는데, 이 두 매개 변수 역시 ratio의 특수화여야 합니다. type의 값은 관련 논리 연산을 통해 결정됩니다.

이름 type
ratio_add R1 + R2
ratio_divide R1 / R2
ratio_equal R1 == R2
ratio_greater R1 > R2
ratio_greater_equal R1 >= R2
ratio_less R1 < R2
ratio_less_equal R1 <= R2
ratio_multiply R1 * R2
ratio_not_equal !(R1 == R2)
ratio_subtract R1 - R2

형식 정의

편의를 위해 헤더는 표준 SI 접두사에 대한 비율을 정의합니다.

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;

참고 항목

헤더 파일 참조