当前位置:网站首页>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
边栏推荐
- 利用用户脚本优化 Yandere/Konachan 站点浏览体验
- chown: changing ownership of ‘/var/lib/mysql/‘: Operation not permitted
- What is a physical firewall? What's the effect?
- Ffmpeg first learning (only for coding)
- [Muduo] EventLoop event cycle
- 行云管家V6.5.1/2/3系列版本发布:数据库OpenAPI能力持续强化
- About priority queues
- [testing technology automated testing pytest] basic summary of pytest
- Implementation of date class
- SAP Message No. VG202 IDoc E1EDK18 中付款条款已经转移:检查数据
猜你喜欢

idea设置get、set模板解决boolean类型字段的命名问题

Docker installation redis-5.0.12 (remote access)

Anti shake and throttling

POI special effects Market Research

chown: changing ownership of ‘/var/lib/mysql/‘: Operation not permitted

BI 系统中为什么会有很多快照表?

Several commonly used traversal methods

npm+模块加载机制

Learning exploration - waves

Duplicate numbers in array
随机推荐
TS basic data type
MVVM model
三板斧!助你成为优秀软件工程师
TS union type
Which securities company should a novice choose to open an account? Is it safe?
Recommended system - an embedded learning framework for numerical features in CTR prediction
utility实用组件学习之swap,move,forward,exchange
JS regular expression content:
【MUDUO】EventLoopThreadPool
TS function
BI 系统中为什么会有很多快照表?
【MUDUO】EventLoopThreadPool
How does Navicat modify the language (Chinese or English)?
策略模式_
日期类的实现
动态内存管理
电商RPA,大促轻松上阵的法宝
Docker installation redis-5.0.12 (remote access)
WordPress removes the website publishing time
About the foundation of fetch