[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/numeric/ratio/ratio_add [Back]  [Original]

std::ratio_add cppreference.com
cppreference.com

std::ratio_add

cppreference.com

<metanoindex/>

 
C++
(C++20)
(C++20)
(C++11)
(C++20)
/
(C++11)
(C++11)
(C++11)
(C++17)
 
(C++11)
(C++14)  
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++14)
(C++11)
(C++11)( C++20*)
(C++11)( C++20)
(C++11)
(C++17)
(C++11)(C++11)(C++11)
(C++11)( C++23)
(C++11)( C++23)
(C++11)
(C++11)
(C++17)

(C++11)( C++20*)(C++17)
 
 
<tbody> </tbody>
template< class R1, class R2 > using ratio_add = /* unspecified */;
std::ratio_add std::ratio R1 R2. std::ratio std::ratio<Num, Denom> Num == R1::num * R2::den + R2::num * R1::den Denom == R1::den * R2::den.
:
The template alias std::ratio_add denotes the result of adding two exact rational fractions represented by the std::ratio instances R1 and R2. The result a std::ratio instance std::ratio<Num, Denom> where Num == R1::num * R2::den + R2::num * R1::den and Denom == R1::den * R2::den.
Google.
. .

-

type std::ratio<num, den>

num
[static]
constexpr std::intmax_t sign(Num) * sign(Denom) * abs(Num) / gcd(Num, Denom)
:
constexpr value of type std::intmax_t equal to sign(Num) * sign(Denom) * abs(Num) / gcd(Num, Denom)
Google.
. .

(public static -)
den
[static]
constexpr std::intmax_t abs(Denom) / gcd(Num, Denom)
:
constexpr value of type std::intmax_t equal to abs(Denom) / gcd(Num, Denom)
Google.
. .

(public static -)

#include <iostream>
#include <ratio>

int main()
{
    typedef std::ratio<2, 3> two_third;
    typedef std::ratio<1, 6> one_sixth;

    typedef std::ratio_add<two_third, one_sixth> sum;
    std::cout << "2/3 + 1/6 = " << sum::num << '/' << sum::den << '\n';
}

:

2/3 + 1/6 = 5/6

Web Proxy Viewer  |  New URL  |  Original Page