Namespaces
Variants

std:: ratio_divide

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
Definido en el encabezado <ratio>
template < class R1, class R2 >
using ratio_divide = /* ver más abajo */ ;
(desde C++11)

La plantilla de alias std::ratio_divide denota el resultado de dividir dos fracciones racionales exactas representadas por las especializaciones std::ratio R1 y R2 .

El resultado es una std::ratio especialización std:: ratio < U, V > , tal que dado Num == R1 :: num * R2 :: den y Denom == R1 :: den * R2 :: num (calculado sin desbordamiento aritmético), U es std:: ratio < Num, Denom > :: num y V es std:: ratio < Num, Denom > :: den .

Notas

Si U o V no son representables en std::intmax_t , el programa está mal formado. Si Num o Denom no son representables en std::intmax_t , el programa está mal formado a menos que la implementación produzca valores correctos para U y V .

La definición anterior requiere que el resultado de std :: ratio_divide < R1, R2 > ya esté reducido a su mínima expresión; por ejemplo, std :: ratio_divide < std:: ratio < 1 , 12 > , std:: ratio < 1 , 6 >> es el mismo tipo que std:: ratio < 1 , 2 > .

Ejemplo

#include <iostream>
#include <ratio>
int main()
{
    using two_third = std::ratio<2, 3>;
    using one_sixth = std::ratio<1, 6>;
    using quotient = std::ratio_divide<two_third, one_sixth>;
    static_assert(std::ratio_equal_v<quotient, std::ratio<0B100, 0X001>>);
    std::cout << "(2/3) / (1/6) = " << quotient::num << '/' << quotient::den << '\n';
}

Salida:

(2/3) / (1/6) = 4/1

Véase también

multiplica dos objetos ratio en tiempo de compilación
(plantilla de alias)