35 template < prototype_
integral INTEGRAL >
36 constexpr unit_base(INTEGRAL i, ENUM eunit)
43 template < prototype_
floating FLOATING >
44 constexpr unit_base(FLOATING f, ENUM eunit)
51 template < prototype_
floating FLOATING >
52 constexpr unit_base(FLOATING f)
55 m_eunit = rate_unit();
59 constexpr unit_base(
const unit_base & unit):
61 m_eunit(unit.m_eunit),
62 m_bFloating(unit.m_bFloating)
66 constexpr bool is_rate()
const {
return m_eunit == rate_unit(); }
67 constexpr bool is_floating()
const {
return m_bFloating; }
68 constexpr void set_floating() { m_bFloating =
true; }
69 constexpr void clear_floating() { m_bFloating =
false; }
71 constexpr ::i64 as_i64()
const {
return is_floating() ? (::i64)m_f64 : m_hi; }
72 constexpr ::f64 as_f64()
const {
return is_floating() ? m_f64 : (::f64)m_hi; }
73 constexpr ::i32 as_i32()
const {
return (::i32) this->as_i64(); }
74 constexpr ::f32 as_f32()
const {
return (::f32) this->as_f64(); }
75 constexpr ENUM eunit()
const {
return m_eunit; }
77 constexpr bool is_null_or_negative() {
return is_floating() ? m_f64 <= 0.0 : m_hi <= 0; }
78 constexpr bool is_negative() {
return is_floating() ? m_f64 < 0.0 : m_hi < 0; }
79 constexpr bool is_null_or_positive() {
return is_floating() ? m_f64 >= 0.0 : m_hi >= 0; }
80 constexpr bool is_positive() {
return is_floating() ? m_f64 > 0.0 : m_hi > 0; }
90 bool operator ==(
const unit_base & unit)
const
93 return m_hi == unit.m_hi && m_eunit == unit.m_eunit;
97 template < prototype_
floating FLOATING >
98 constexpr unit_base & operator = (FLOATING f)
103 m_eunit = rate_unit();
112 constexpr unit_base & operator = (
const unit_base & unit)
117 m_eunit = unit.m_eunit;
119 m_bFloating = unit.m_bFloating;
130 constexpr static ENUM rate_unit() {
return (ENUM)-1; }
133 constexpr void set_unit(ENUM eunit) { m_eunit = eunit; }
136 template < prototype_
floating FLOATING >
137 unit_base & operator *= (FLOATING f)
140 m_f64 = this->as_f64() * f;
149 template < prototype_
floating FLOATING >
150 unit_base & operator /= (FLOATING f)
153 m_f64 = this->as_f64() / f;
162 template < prototype_
floating FLOATING >
163 unit_base operator * (FLOATING f)
const
166 unit_base < ENUM > unitResult(this->as_f64() * f, this->eunit());
173 template < prototype_
floating FLOATING >
174 unit_base operator / (FLOATING f)
const
177 unit_base < ENUM > unitResult(this->as_f64() / f, this->eunit());
188inline unit_base < ENUM > operator * (FLOATING f,
const unit_base < ENUM > & unit)