当前位置:网站首页>Ratio of learning_ add,ratio_ subtract,ratio_ multiply,ratio_ Use of divide
Ratio of learning_ add,ratio_ subtract,ratio_ multiply,ratio_ Use of divide
2022-07-25 23:32:00 【I washed my feet in Bangong Lake】
ratio It's proportional std::ratio Represents a proportion , Is to divide a given two integers to get a fraction ( Numerator and denominator ), for example 3/6, After that, it's 1/2. It is mainly used for very small units , such as , millisecond , Microsecond , mm , micron , Nano, etc . Here is ratio_add,ratio_subtract,ratio_multiply,ratio_divide Use .
class | |
| Represents the exact rational fraction ( Class template ) | |
The arithmetic | |
(C++11) | Add two at compile time ratio object ( Alias template ) |
(C++11) | Subtract two at compile time ratio object ( Alias template ) |
(C++11) | Multiply two at compile time ratio object ( Alias template ) |
(C++11) | Divide two at compile time ratio object ( Alias template ) |
#include <iostream>
#include <ratio>
using namespace std;
int main()
{
ratio<2, 6> two_six;
ratio<3, 6> three_six;
cout << "two_six======" << two_six.num << "/" << two_six.den << endl;
cout << "two_six======" << three_six.num << "/" << three_six.den << endl;
cout << "Hello World!" << endl;
return 0;
}
ratio_add Two ratio Add objects
#include <iostream>
#include <ratio>
using namespace std;
int main()
{
ratio<2, 6> two_six;
ratio<3, 6> three_six;
cout << "two_six======" << two_six.num << "/" << two_six.den << endl;
cout << "two_six======" << three_six.num << "/" << three_six.den << endl;
ratio_add<decltype(two_six), decltype(three_six)> ratioAdd;
cout << "ratio_add======" << ratioAdd.num << "/" << ratioAdd.den << endl;
cout << "Hello World!" << endl;
return 0;
}
ratio_subtract Two ratio Object subtraction
#include <iostream>
#include <ratio>
using namespace std;
int main()
{
ratio<2, 6> two_six;
ratio<3, 6> three_six;
cout << "two_six======" << two_six.num << "/" << two_six.den << endl;
cout << "two_six======" << three_six.num << "/" << three_six.den << endl;
ratio_subtract<decltype(two_six), decltype(three_six)> ratioSubtract;
cout << "ratio_subtract======" << ratioSubtract.num << "/" << ratioSubtract.den << endl;
cout << "Hello World!" << endl;
return 0;
}

ratio_multiply Two ratio Multiply objects
#include <iostream>
#include <ratio>
using namespace std;
int main()
{
ratio<2, 6> two_six;
ratio<3, 6> three_six;
cout << "two_six======" << two_six.num << "/" << two_six.den << endl;
cout << "two_six======" << three_six.num << "/" << three_six.den << endl;
ratio_multiply<decltype(two_six), decltype(three_six)> ratioMultiply;
cout << "ratio_multiply======" << ratioMultiply.num << "/" << ratioMultiply.den << endl;
cout << "Hello World!" << endl;
return 0;
}
ratio_divide Two ratio Object division
#include <iostream>
#include <ratio>
using namespace std;
int main()
{
ratio<2, 6> two_six;
ratio<3, 6> three_six;
cout << "two_six======" << two_six.num << "/" << two_six.den << endl;
cout << "two_six======" << three_six.num << "/" << three_six.den << endl;
ratio_divide<decltype(two_six), decltype(three_six)> ratioDivide;
cout << "ratio_divide======" << ratioDivide.num << "/" << ratioDivide.den << endl;
cout << "Hello World!" << endl;
return 0;
}

Reference resources :
Standard library header file <ratio> - cppreference.com
C++11 std::chrono Time bank _ Changle Village head's blog -CSDN Blog _std::chrono
边栏推荐
猜你喜欢

ABAP 代码中读取会计科目的字段状态(隐藏、可选、必输)

E-commerce RPA, a magic weapon to promote easy entry

LeetCode 0919. 完全二叉树插入器:完全二叉树的数组表示

XXE&XML-外部实体注入-利用和绕过

Take away applet with main version of traffic / repair to add main access function of traffic

Node Foundation

数组中重复的数字

How to set pseudo static for WordPress fixed links

Discuz atmosphere game style template / imitation lol hero League game DZ game template GBK

Graph traversal DFS, BFS (code explanation)
随机推荐
What is a physical firewall? What's the effect?
Idea sets get and set templates to solve the naming problem of boolean type fields
ES6 syntax (difference between let, const, VaR, deconstruction assignment, arrow function, residual parameters, extension method of array)
Recommended system - an embedded learning framework for numerical features in CTR prediction
EasyExcel实用技巧
Data broker understanding
JS get the current date and time
[QNX Hypervisor 2.2用户手册]9.8 load
How does PHP remove an element from an array based on the key value
What is the difference between hot deployment and hot loading?
chown: changing ownership of ‘/var/lib/mysql/‘: Operation not permitted
S4/HANA ME21N创建PO 输出控制消息按钮丢失解决方法(切换EDI 输出模式BRF+至NAST模式)
Three board axe! Help you become an excellent software engineer
Wrote a little webapi knowledge points from 0 to 1
多模态——Deep Multi-Modal Sets
策略模式_
物理防火墙是什么?有什么作用?
Moment.js
Family relationship calculator wechat applet source code
Duplicate numbers in array