-
Notifications
You must be signed in to change notification settings - Fork 1
/
conversion_factor_def.hpp
114 lines (99 loc) · 2.89 KB
/
conversion_factor_def.hpp
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef PQS_CONVERSION_FACTOR_DEF_HPP_INCLUDED
#define PQS_CONVERSION_FACTOR_DEF_HPP_INCLUDED
#include <pqs/concepts/associated/get_exponent.hpp>
#include <pqs/bits/conversion_factor_ops.hpp>
#include <pqs/bits/conversion_factor_fwd.hpp>
namespace pqs{
template <typename Multiplier, typename Exponent>
requires
pqs::is_ratio<Multiplier> &&
pqs::is_exponent10<Exponent>
struct conversion_factor{
using multiplier = typename Multiplier::type;
using exponent = typename Exponent::type;
static_assert(Multiplier::num != 0,
"conversion_factor : only non-zero ratios values allowed");
using type = conversion_factor<multiplier,exponent>;
template <
intmax_t N1, intmax_t D1
>
constexpr
friend
auto operator * ( conversion_factor, std::ratio<N1,D1>)
{
return pqs::normalise<
pqs::conversion_factor<
std::ratio_multiply<multiplier,std::ratio<N1,D1> >,
Exponent
>
>{};
}
template <
intmax_t N1, intmax_t D1
>
constexpr
friend
auto operator * ( std::ratio<N1,D1>, conversion_factor)
{
return pqs::normalise<
pqs::conversion_factor<
std::ratio_multiply<multiplier,std::ratio<N1,D1> >,
Exponent
>
>{};
}
template <
intmax_t N1, intmax_t D1
>
constexpr
friend
auto operator / ( conversion_factor, std::ratio<N1,D1> )
{
return pqs::normalise<
pqs::conversion_factor<
std::ratio_divide<multiplier,std::ratio<N1,D1> >,
Exponent
>
>{};
}
template <
intmax_t N1, intmax_t D1
>
constexpr
friend
auto operator / ( std::ratio<N1,D1>,conversion_factor )
{
return pqs::normalise<
pqs::conversion_factor<
std::ratio_divide<std::ratio<N1,D1>,multiplier>,
exponent10<
-exponent::ratio::num,
exponent::ratio::den
>
>
>{};
}
}; // conversion_factor
namespace impl{
template <intmax_t MuxNum, intmax_t MuxDenom, typename UnitExp>
struct is_conversion_factor_impl<
pqs::conversion_factor<
std::ratio<MuxNum,MuxDenom>,
UnitExp
>
> : std::true_type{};
template <intmax_t MuxNum, intmax_t MuxDenom, typename UnitExp>
struct get_exponent_impl<
pqs::conversion_factor<
std::ratio<MuxNum,MuxDenom>,
UnitExp
>
> {
typedef typename pqs::conversion_factor<
std::ratio<MuxNum,MuxDenom>,
UnitExp
>::exponent type;
};
} //impl
} // pqs
#endif // PQS_CONVERSION_FACTOR_DEF_HPP_INCLUDED