Namespaces
Variants

std:: ratio_multiply

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
헤더 파일에 정의됨 <ratio>
template < class R1, class R2 >
using ratio_multiply = /* see below */ ;
(C++11부터)

별칭 템플릿 std::ratio_multiply std::ratio 특수화 R1 R2 로 표현된 두 개의 정확한 유리수 분수를 곱한 결과를 나타냅니다.

결과는 std::ratio 특수화 std:: ratio < U, V > 입니다. 여기서 주어진 조건은 Num == R1 :: num * R2 :: num 이고 Denom == R1 :: den * R2 :: den (산술 오버플로 없이 계산됨)일 때, U std:: ratio < Num, Denom > :: num 이고 V std:: ratio < Num, Denom > :: den 입니다.

참고 사항

만약 U 또는 V std::intmax_t 로 표현 불가능한 경우, 프로그램은 ill-formed입니다. 만약 Num 또는 Denom std::intmax_t 로 표현 불가능한 경우, 구현이 U V 에 대해 올바른 값을 제공하지 않는 한 프로그램은 ill-formed입니다.

위 정의는 std :: ratio_multiply < R1, R2 > 의 결과가 이미 기약분수로 축소되어 있어야 함을 요구합니다; 예를 들어, std :: ratio_multiply < std:: ratio < 1 , 6 > , std:: ratio < 4 , 5 >> std:: ratio < 2 , 15 > 와 동일한 타입입니다.

예제

#include <iostream>
#include <ratio>
int main()
{
    using two_third = std::ratio<2, 3>;
    using one_sixth = std::ratio<1, 6>;
    using product = std::ratio_multiply<two_third, one_sixth>;
    static_assert(std::ratio_equal_v<product, std::ratio<13, 117>>);
    std::cout << "2/3 * 1/6 = " << product::num << '/' << product::den << '\n';
}

출력:

2/3 * 1/6 = 1/9

참고 항목

컴파일 타임에 두 개의 ratio 객체를 나눔
(alias template)