-
Notifications
You must be signed in to change notification settings - Fork 1
/
number_main.cc
95 lines (66 loc) · 2.89 KB
/
number_main.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// Created by oyoung on 19-3-1.
//
#include <oyoung/number.hpp>
#include <oyoung/format.hpp>
#include <iostream>
#include <complex>
using namespace oyoung::number;
using namespace oyoung::number::literals;
int main(int, char**)
{
Int age(100);
Double score(10);
std::cout << "age: " << age << std::endl;
age = 66.001;
std::cout << "age: " << age << std::endl;
Int number = age++;
std::cout << "number: " << number << ", age: " << age << std::endl;
score = Int(100) / 4;
std::cout << "score: " << score << std::endl;
std::cout << "score平方: " << score.square() << std::endl;
std::cout << "score立方: " << score.cube() << std::endl;
std::cout << "score平方根: " << score.sqrt() << std::endl;
std::cout << "age + score: " << age + score << std::endl;
std::cout << "age - score: " << age - score << std::endl;
std::cout << "age * score: " << age * score << std::endl;
std::cout << "age / score: " << age / score << std::endl;
std::cout << "8 + age: " << 8 + age << std::endl;
std::cout << "1.0 - age: " << 1.0 - age << std::endl;
std::cout << "1.0 * age: " << 1.0 * age << std::endl;
std::cout << "1000.0 / age: " << 1000.0 / age << std::endl;
score = -0.5;
std::cout << "score: " << score << std::endl;
std::cout << "score's abs: " << score.abs() << std::endl;
score *= 100;
std::cout << "score *= 100, score: " << score << std::endl;
if(score < 120) {
std::cout << "score < 120" << std::endl;
}
if(-100.0 < score) {
std::cout << "score > -100.0" << std::endl;
}
std::cout << &score << std::endl;
complex a;
complex b;
a = {5.0, 0.5};
b = {1.0, 0.1};
auto c = 1 - 0.5_i;
std::cout << "complex a value: " << a << std::endl;
std::cout << "complex b value: " << b << std::endl;
std::cout << "complex c value: " << c << std::endl;
std::cout << "complex a radius: " << a.radius() << std::endl;
std::cout << "complex a theta: " << a.theta() << std::endl;
std::cout << "complex a+b value: " << a+b << std::endl;
std::cout << "complex a-b value: " << a-b << std::endl;
std::cout << "complex a*b value: " << a*b << std::endl;
std::cout << "complex a/b value: " << a/b << std::endl;
std::cout << "complex a conjugate value: " << a.conjugate() << std::endl;
auto now = std::chrono::system_clock::now();
std::cout << oyoung::format("now is [%1]").arg(now, "%Ec").to_string() << std::endl;
std::cout << oyoung::format("after 1000 ms is [%1]").arg(now + 1000_ms, "%Ec").to_string() << std::endl;
std::cout << oyoung::format("after 100 s is [%1]").arg(now + 1_s, "%Ec").to_string() << std::endl;
std::cout << oyoung::format("after 10 min is [%1]").arg(now + 10_min, "%Ec").to_string() << std::endl;
std::cout << oyoung::format("after 1 hour is [%1]").arg(now + 1_h, "%Ec").to_string() << std::endl;
return 0;
}