41# pragma push_macro("pascal")
44# define _ALLOW_KEYWORD_MACROS
46# pragma warning(disable : 4520)
47# pragma push_macro("constexpr")
49# pragma push_macro("noexcept")
50# define noexcept throw()
54#if !defined(_MSC_VER) || _MSC_VER > 1800
55# define UNIT_HAS_LITERAL_SUPPORT
56# define UNIT_HAS_VARIADIC_TEMPLATE_SUPPORT
59#ifndef UNIT_LIB_DEFAULT_TYPE
60# define UNIT_LIB_DEFAULT_TYPE double
74#if defined(UNIT_LIB_ENABLE_IOSTREAM)
79#if !defined(UNIT_LIB_DISABLE_FMT)
93 template <
typename T> std::string
to_string(
const T& t)
101 char decimalPoint = *lc->decimal_point;
102 if (str.find_last_not_of(
'0') == str.find(decimalPoint)) { offset = 0; }
103 str.erase(str.find_last_not_of(
'0') + offset, std::string::npos);
111 template<
typename T>
inline constexpr const char*
name(
const T&);
112 template<
typename T>
inline constexpr const char*
abbreviation(
const T&);
135#define UNIT_ADD_UNIT_TAGS(namespaceName,nameSingular, namePlural, abbreviation, ...)\
136 namespace namespaceName\
138 typedef __VA_ARGS__ namePlural; \
139 typedef namePlural nameSingular; \
140 typedef namePlural abbreviation; \
150#define UNIT_ADD_UNIT_DEFINITION(namespaceName,nameSingular)\
151 namespace namespaceName\
153 typedef unit_t<nameSingular> nameSingular ## _t; \
164#define UNIT_ADD_CUSTOM_TYPE_UNIT_DEFINITION(namespaceName,nameSingular, underlyingType)\
165 namespace namespaceName\
167 typedef unit_t<nameSingular,underlyingType> nameSingular ## _t; \
179#if !defined(UNIT_LIB_DISABLE_FMT)
180 #define UNIT_ADD_IO(namespaceName, nameSingular, abbrev)\
183 struct fmt::formatter<units::namespaceName::nameSingular ## _t> \
184 : fmt::formatter<double> \
186 template <typename FormatContext>\
187 auto format(const units::namespaceName::nameSingular ## _t& obj,\
188 FormatContext& ctx) -> decltype(ctx.out()) \
190 auto out = ctx.out();\
191 out = fmt::formatter<double>::format(obj(), ctx);\
192 return fmt::format_to(out, " " #abbrev);\
197 namespace namespaceName\
199 inline std::string to_string(const nameSingular ## _t& obj)\
201 return units::detail::to_string(obj()) + std::string(" "#abbrev);\
205#if defined(UNIT_LIB_ENABLE_IOSTREAM)
206 #define UNIT_ADD_IO(namespaceName, nameSingular, abbrev)\
207 namespace namespaceName\
209 inline std::ostream& operator<<(std::ostream& os, const nameSingular ## _t& obj) \
211 os << obj() << " "#abbrev; return os; \
213 inline std::string to_string(const nameSingular ## _t& obj)\
215 return units::detail::to_string(obj()) + std::string(" "#abbrev);\
230#define UNIT_ADD_NAME(namespaceName, nameSingular, abbrev)\
231template<> inline constexpr const char* name(const namespaceName::nameSingular ## _t&)\
233 return #nameSingular;\
235template<> inline constexpr const char* abbreviation(const namespaceName::nameSingular ## _t&)\
251#if defined(UNIT_HAS_LITERAL_SUPPORT)
252 #define UNIT_ADD_LITERALS(namespaceName, nameSingular, abbreviation)\
255 inline constexpr namespaceName::nameSingular ## _t operator""_ ## abbreviation(long double d)\
257 return namespaceName::nameSingular ## _t(static_cast<namespaceName::nameSingular ## _t::underlying_type>(d));\
259 inline constexpr namespaceName::nameSingular ## _t operator""_ ## abbreviation (unsigned long long d)\
261 return namespaceName::nameSingular ## _t(static_cast<namespaceName::nameSingular ## _t::underlying_type>(d));\
265 #define UNIT_ADD_LITERALS(namespaceName, nameSingular, abbreviation)
287#define UNIT_ADD(namespaceName, nameSingular, namePlural, abbreviation, ...)\
288 UNIT_ADD_UNIT_TAGS(namespaceName,nameSingular, namePlural, abbreviation, __VA_ARGS__)\
289 UNIT_ADD_UNIT_DEFINITION(namespaceName,nameSingular)\
290 UNIT_ADD_NAME(namespaceName,nameSingular, abbreviation)\
291 UNIT_ADD_IO(namespaceName,nameSingular, abbreviation)\
292 UNIT_ADD_LITERALS(namespaceName,nameSingular, abbreviation)
314#define UNIT_ADD_WITH_CUSTOM_TYPE(namespaceName, nameSingular, namePlural, abbreviation, underlyingType, ...)\
315 UNIT_ADD_UNIT_TAGS(namespaceName,nameSingular, namePlural, abbreviation, __VA_ARGS__)\
316 UNIT_ADD_CUSTOM_TYPE_UNIT_DEFINITION(namespaceName,nameSingular,underlyingType)\
317 UNIT_ADD_IO(namespaceName,nameSingular, abbreviation)\
318 UNIT_ADD_LITERALS(namespaceName,nameSingular, abbreviation)
329#define UNIT_ADD_DECIBEL(namespaceName, nameSingular, abbreviation)\
330 namespace namespaceName\
332 typedef unit_t<nameSingular, UNIT_LIB_DEFAULT_TYPE, units::decibel_scale> abbreviation ## _t; \
334 UNIT_ADD_IO(namespaceName, abbreviation, abbreviation)\
335 UNIT_ADD_LITERALS(namespaceName, abbreviation, abbreviation)
346#define UNIT_ADD_CATEGORY_TRAIT_DETAIL(unitCategory)\
352 template<typename T> struct is_ ## unitCategory ## _unit_impl : std::false_type {};\
353 template<typename C, typename U, typename P, typename T>\
354 struct is_ ## unitCategory ## _unit_impl<units::unit<C, U, P, T>> : std::is_same<units::traits::base_unit_of<typename units::traits::unit_traits<units::unit<C, U, P, T>>::base_unit_type>, units::category::unitCategory ## _unit>::type {};\
355 template<typename U, typename S, template<typename> class N>\
356 struct is_ ## unitCategory ## _unit_impl<units::unit_t<U, S, N>> : std::is_same<units::traits::base_unit_of<typename units::traits::unit_t_traits<units::unit_t<U, S, N>>::unit_type>, units::category::unitCategory ## _unit>::type {};\
361#if defined(UNIT_HAS_VARIADIC_TEMPLATE_SUPPORT)
362#define UNIT_ADD_IS_UNIT_CATEGORY_TRAIT(unitCategory)\
365 template<typename... T> struct is_ ## unitCategory ## _unit : std::integral_constant<bool, units::all_true<units::traits::detail::is_ ## unitCategory ## _unit_impl<std::decay_t<T>>::value...>::value> {};\
366 template<typename... T> inline constexpr bool is_ ## unitCategory ## _unit_v = is_ ## unitCategory ## _unit<T...>::value;\
369#define UNIT_ADD_IS_UNIT_CATEGORY_TRAIT(unitCategory)\
372 template<typename T1, typename T2 = T1, typename T3 = T1>\
373 struct is_ ## unitCategory ## _unit : std::integral_constant<bool, units::traits::detail::is_ ## unitCategory ## _unit_impl<typename std::decay<T1>::type>::value &&\
374 units::traits::detail::is_ ## unitCategory ## _unit_impl<typename std::decay<T2>::type>::value &&\
375 units::traits::detail::is_ ## unitCategory ## _unit_impl<typename std::decay<T3>::type>::value>{};\
376 template<typename T1, typename T2 = T1, typename T3 = T1>\
377 inline constexpr bool is_ ## unitCategory ## _unit_v = is_ ## unitCategory ## _unit<T1, T2, T3>::value;\
381#define UNIT_ADD_CATEGORY_TRAIT(unitCategory)\
382 UNIT_ADD_CATEGORY_TRAIT_DETAIL(unitCategory)\
387 UNIT_ADD_IS_UNIT_CATEGORY_TRAIT(unitCategory)
407#define UNIT_ADD_WITH_METRIC_PREFIXES(namespaceName, nameSingular, namePlural, abbreviation, ...)\
408 UNIT_ADD(namespaceName, nameSingular, namePlural, abbreviation, __VA_ARGS__)\
409 UNIT_ADD(namespaceName, femto ## nameSingular, femto ## namePlural, f ## abbreviation, femto<namePlural>)\
410 UNIT_ADD(namespaceName, pico ## nameSingular, pico ## namePlural, p ## abbreviation, pico<namePlural>)\
411 UNIT_ADD(namespaceName, nano ## nameSingular, nano ## namePlural, n ## abbreviation, nano<namePlural>)\
412 UNIT_ADD(namespaceName, micro ## nameSingular, micro ## namePlural, u ## abbreviation, micro<namePlural>)\
413 UNIT_ADD(namespaceName, milli ## nameSingular, milli ## namePlural, m ## abbreviation, milli<namePlural>)\
414 UNIT_ADD(namespaceName, centi ## nameSingular, centi ## namePlural, c ## abbreviation, centi<namePlural>)\
415 UNIT_ADD(namespaceName, deci ## nameSingular, deci ## namePlural, d ## abbreviation, deci<namePlural>)\
416 UNIT_ADD(namespaceName, deca ## nameSingular, deca ## namePlural, da ## abbreviation, deca<namePlural>)\
417 UNIT_ADD(namespaceName, hecto ## nameSingular, hecto ## namePlural, h ## abbreviation, hecto<namePlural>)\
418 UNIT_ADD(namespaceName, kilo ## nameSingular, kilo ## namePlural, k ## abbreviation, kilo<namePlural>)\
419 UNIT_ADD(namespaceName, mega ## nameSingular, mega ## namePlural, M ## abbreviation, mega<namePlural>)\
420 UNIT_ADD(namespaceName, giga ## nameSingular, giga ## namePlural, G ## abbreviation, giga<namePlural>)\
421 UNIT_ADD(namespaceName, tera ## nameSingular, tera ## namePlural, T ## abbreviation, tera<namePlural>)\
422 UNIT_ADD(namespaceName, peta ## nameSingular, peta ## namePlural, P ## abbreviation, peta<namePlural>)\
442#define UNIT_ADD_WITH_METRIC_AND_BINARY_PREFIXES(namespaceName, nameSingular, namePlural, abbreviation, ...)\
443 UNIT_ADD_WITH_METRIC_PREFIXES(namespaceName, nameSingular, namePlural, abbreviation, __VA_ARGS__)\
444 UNIT_ADD(namespaceName, kibi ## nameSingular, kibi ## namePlural, Ki ## abbreviation, kibi<namePlural>)\
445 UNIT_ADD(namespaceName, mebi ## nameSingular, mebi ## namePlural, Mi ## abbreviation, mebi<namePlural>)\
446 UNIT_ADD(namespaceName, gibi ## nameSingular, gibi ## namePlural, Gi ## abbreviation, gibi<namePlural>)\
447 UNIT_ADD(namespaceName, tebi ## nameSingular, tebi ## namePlural, Ti ## abbreviation, tebi<namePlural>)\
448 UNIT_ADD(namespaceName, pebi ## nameSingular, pebi ## namePlural, Pi ## abbreviation, pebi<namePlural>)\
449 UNIT_ADD(namespaceName, exbi ## nameSingular, exbi ## namePlural, Ei ## abbreviation, exbi<namePlural>)
517 static constexpr const UNIT_LIB_DEFAULT_TYPE PI_VAL = 3.14159265358979323846264338327950288419716939937510;
539 static constexpr auto test(U*)->std::is_integral<
decltype(U::num)> {
return std::is_integral<
decltype(U::num)>{}; }
541 static constexpr std::false_type test(...) {
return std::false_type{}; }
543 using type =
decltype(test<T>(0));
553 struct has_num : units::detail::has_num_impl<T>
::type {};
562 static constexpr auto test(U*)->std::is_integral<
decltype(U::den)> {
return std::is_integral<
decltype(U::den)>{}; }
564 static constexpr std::false_type test(...) {
return std::false_type{}; }
566 using type =
decltype(test<T>(0));
576 struct has_den : units::detail::has_den_impl<T>
::type {};
611 template<
bool...>
struct bool_pack {};
616 template<
bool... Args>
617 struct all_true : std::is_same<units::bool_pack<true, Args...>, units::bool_pack<Args..., true>> {};
618 template<
bool... Args>
619 inline constexpr bool all_true_t_v = all_true<Args...>::type::value;
627#ifdef FOR_DOXYGEN_PURPOSES_ONLY
638 typedef typename T::base_unit_type base_unit_type;
639 typedef typename T::conversion_ratio conversion_ratio;
640 typedef typename T::pi_exponent_ratio pi_exponent_ratio;
641 typedef typename T::translation_ratio translation_ratio;
648 template<
class T,
typename =
void>
651 typedef void base_unit_type;
652 typedef void conversion_ratio;
653 typedef void pi_exponent_ratio;
654 typedef void translation_ratio;
660 typename T::base_unit_type,
661 typename T::conversion_ratio,
662 typename T::pi_exponent_ratio,
663 typename T::translation_ratio>
::type>
665 typedef typename T::base_unit_type base_unit_type;
666 typedef typename T::conversion_ratio conversion_ratio;
667 typedef typename T::pi_exponent_ratio pi_exponent_ratio;
668 typedef typename T::translation_ratio translation_ratio;
680 struct _base_unit_t {};
693 struct is_base_unit : std::is_base_of<units::detail::_base_unit_t, T> {};
705 template<std::
intmax_t Num, std::
intmax_t Den = 1>
706 using meter_ratio = std::ratio<Num, Den>;
748 template<
class Meter = detail::meter_ratio<0>,
749 class Kilogram = std::ratio<0>,
750 class Second = std::ratio<0>,
751 class Radian = std::ratio<0>,
752 class Ampere = std::ratio<0>,
753 class Kelvin = std::ratio<0>,
754 class Mole = std::ratio<0>,
755 class Candela = std::ratio<0>,
756 class Byte = std::ratio<0>>
759 static_assert(
traits::is_ratio<Meter>::value,
"Template parameter `Meter` must be a `std::ratio` representing the exponent of meters the unit has");
761 static_assert(
traits::is_ratio<Second>::value,
"Template parameter `Second` must be a `std::ratio` representing the exponent of seconds the unit has");
762 static_assert(
traits::is_ratio<Ampere>::value,
"Template parameter `Ampere` must be a `std::ratio` representing the exponent of amperes the unit has");
765 static_assert(
traits::is_ratio<Mole>::value,
"Template parameter `Mole` must be a `std::ratio` representing the exponent of moles the unit has");
766 static_assert(
traits::is_ratio<Radian>::value,
"Template parameter `Radian` must be a `std::ratio` representing the exponent of radians the unit has");
767 static_assert(
traits::is_ratio<Byte>::value,
"Template parameter `Byte` must be a `std::ratio` representing the exponent of bytes the unit has");
826 typedef base_unit<detail::meter_ratio<-2>, std::ratio<0>, std::ratio<0>, std::ratio<2>, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<1>>
illuminance_unit;
848 template <
class,
class,
class,
class>
struct unit;
849 template<
class Conversion,
class... Exponents,
class PiExponent,
class Translation>
850 struct unit<Conversion,
base_unit<Exponents...>, PiExponent, Translation> : units::detail::_unit
854 static_assert(
traits::is_ratio<Translation>::value,
"Template parameter `Translation` must be a `std::ratio` representing an additive translation required by the unit conversion.");
882 template<
class Conversion,
class BaseUnit,
class PiExponent = std::ratio<0>,
class Translation = std::ratio<0>>
883 struct unit : units::detail::_unit
889 typedef typename units::traits::unit_traits<BaseUnit>::base_unit_type
base_unit_type;
890 typedef typename std::ratio_multiply<typename BaseUnit::conversion_ratio, Conversion>
conversion_ratio;
891 typedef typename std::ratio_add<typename BaseUnit::pi_exponent_ratio, PiExponent>
pi_exponent_ratio;
892 typedef typename std::ratio_add<std::ratio_multiply<typename BaseUnit::conversion_ratio, Translation>,
typename BaseUnit::translation_ratio>
translation_ratio;
907 template<
class>
struct base_unit_of_impl;
908 template<
class Conversion,
class BaseUnit,
class PiExponent,
class Translation>
909 struct base_unit_of_impl<
unit<Conversion, BaseUnit, PiExponent, Translation>> : base_unit_of_impl<BaseUnit> {};
910 template<
class... Exponents>
911 struct base_unit_of_impl<base_unit<Exponents...>>
913 typedef base_unit<Exponents...>
type;
916 struct base_unit_of_impl<void>
943 template<
class,
class>
struct base_unit_multiply_impl;
944 template<
class... Exponents1,
class... Exponents2>
952 template<
class U1,
class U2>
960 template<
class,
class>
struct base_unit_divide_impl;
961 template<
class... Exponents1,
class... Exponents2>
962 struct base_unit_divide_impl<base_unit<Exponents1...>, base_unit<Exponents2...>> {
963 using type = base_unit<std::ratio_subtract<Exponents1, Exponents2>...>;
969 template<
class U1,
class U2>
977 template<
class>
struct inverse_base_impl;
979 template<
class... Exponents>
980 struct inverse_base_impl<base_unit<Exponents...>> {
981 using type = base_unit<std::ratio_multiply<Exponents, std::ratio<-1>>...>;
995 template<
class U>
struct squared_base_impl;
996 template<
class... Exponents>
997 struct squared_base_impl<base_unit<Exponents...>> {
998 using type = base_unit<std::ratio_multiply<Exponents, std::ratio<2>>...>;
1012 template<
class U>
struct cubed_base_impl;
1013 template<
class... Exponents>
1014 struct cubed_base_impl<base_unit<Exponents...>> {
1015 using type = base_unit<std::ratio_multiply<Exponents, std::ratio<3>>...>;
1029 template<
class U>
struct sqrt_base_impl;
1030 template<
class... Exponents>
1031 struct sqrt_base_impl<base_unit<Exponents...>> {
1032 using type = base_unit<std::ratio_divide<Exponents, std::ratio<2>>...>;
1046 template<
class U>
struct cbrt_base_impl;
1047 template<
class... Exponents>
1048 struct cbrt_base_impl<base_unit<Exponents...>> {
1049 using type = base_unit<std::ratio_divide<Exponents, std::ratio<3>>...>;
1073 template<
class Unit1,
class Unit2>
1074 struct unit_multiply_impl
1076 using type = unit < std::ratio_multiply<typename Unit1::conversion_ratio, typename Unit2::conversion_ratio>,
1077 base_unit_multiply <traits::base_unit_of<typename Unit1::base_unit_type>, traits::base_unit_of<typename Unit2::base_unit_type>>,
1078 std::ratio_add<typename Unit1::pi_exponent_ratio, typename Unit2::pi_exponent_ratio>,
1086 template<
class U1,
class U2>
1095 template<
class Unit1,
class Unit2>
1096 struct unit_divide_impl
1098 using type = unit < std::ratio_divide<typename Unit1::conversion_ratio, typename Unit2::conversion_ratio>,
1099 base_unit_divide<traits::base_unit_of<typename Unit1::base_unit_type>, traits::base_unit_of<typename Unit2::base_unit_type>>,
1100 std::ratio_subtract<typename Unit1::pi_exponent_ratio, typename Unit2::pi_exponent_ratio>,
1108 template<
class U1,
class U2>
1117 template<
class Unit>
1120 using type = unit < std::ratio<Unit::conversion_ratio::den, Unit::conversion_ratio::num>,
1121 inverse_base<traits::base_unit_of<typename units::traits::unit_traits<Unit>::base_unit_type>>,
1122 std::ratio_multiply<typename units::traits::unit_traits<Unit>::pi_exponent_ratio, std::ratio<-1>>,
1144 template<
class Unit>
1148 using Conversion =
typename Unit::conversion_ratio;
1150 squared_base<traits::base_unit_of<typename Unit::base_unit_type>>,
1151 std::ratio_multiply<typename Unit::pi_exponent_ratio, std::ratio<2>>,
1152 typename Unit::translation_ratio
1175 template<
class Unit>
1179 using Conversion =
typename Unit::conversion_ratio;
1181 cubed_base<traits::base_unit_of<typename Unit::base_unit_type>>,
1182 std::ratio_multiply<typename Unit::pi_exponent_ratio, std::ratio<3>>,
1183 typename Unit::translation_ratio> ;
1204 using Zero = std::ratio<0>;
1205 using One = std::ratio<1>;
1206 template <
typename R>
using Square = std::ratio_multiply<R, R>;
1209 template <
template <std::
intmax_t N>
class Predicate,
typename enabled =
void>
1210 struct BinarySearch {
1211 template <std::
intmax_t N>
1212 struct SafeDouble_ {
1213 static constexpr const std::intmax_t
value = 2 * N;
1214 static_assert(
value > 0,
"Overflows when computing 2 * N");
1217 template <
intmax_t Lower,
intmax_t Upper,
typename Condition1 =
void,
typename Condition2 =
void>
1218 struct DoubleSidedSearch_ : DoubleSidedSearch_<Lower, Upper,
1219 std::integral_constant<bool, (Upper - Lower == 1)>,
1220 std::integral_constant<bool, ((Upper - Lower>1 && Predicate<Lower + (Upper - Lower) / 2>::value))>> {};
1222 template <
intmax_t Lower,
intmax_t Upper>
1223 struct DoubleSidedSearch_<
Lower,
Upper,
std::false_type, std::false_type> : DoubleSidedSearch_<Lower, Lower + (Upper - Lower) / 2> {};
1225 template <
intmax_t Lower,
intmax_t Upper,
typename Condition2>
1226 struct DoubleSidedSearch_<
Lower,
Upper,
std::true_type, Condition2> : std::integral_constant<intmax_t, Lower>{};
1228 template <
intmax_t Lower,
intmax_t Upper,
typename Condition1>
1229 struct DoubleSidedSearch_<
Lower,
Upper, Condition1,
std::true_type> : DoubleSidedSearch_<Lower + (Upper - Lower) / 2, Upper>{};
1231 template <std::
intmax_t Lower,
class enabled1 =
void>
1232 struct SingleSidedSearch_ : SingleSidedSearch_<Lower, std::integral_constant<bool, Predicate<SafeDouble_<Lower>::value>::value>>{};
1234 template <std::
intmax_t Lower>
1235 struct SingleSidedSearch_<
Lower,
std::false_type> : DoubleSidedSearch_<Lower, SafeDouble_<Lower>::value> {};
1237 template <std::
intmax_t Lower>
1238 struct SingleSidedSearch_<
Lower,
std::true_type> : SingleSidedSearch_<SafeDouble_<Lower>::value>{};
1240 static constexpr const std::intmax_t
value = SingleSidedSearch_<1>::value;
1243 template <
template <std::
intmax_t N>
class Predicate>
1244 struct BinarySearch<Predicate,
std::
enable_if_t<!Predicate<1>::value>> : std::integral_constant<std::intmax_t, 0>{};
1247 template <
typename R>
1249 template <std::
intmax_t N>
using Predicate_ = std::ratio_less_equal<std::ratio<N>, std::ratio_divide<R, std::ratio<N>>>;
1250 static constexpr const std::intmax_t
value = BinarySearch<Predicate_>::value;
1253 template <
typename R>
1254 struct IsPerfectSquare {
1255 static constexpr const std::intmax_t DenSqrt_ = Integer<std::ratio<R::den>>
::value;
1256 static constexpr const std::intmax_t NumSqrt_ = Integer<std::ratio<R::num>>
::value;
1257 static constexpr const bool value =( DenSqrt_ * DenSqrt_ == R::den && NumSqrt_ * NumSqrt_ == R::num);
1258 using Sqrt = std::ratio<NumSqrt_, DenSqrt_>;
1262 template <
typename Tp,
typename Tq>
1269 template <
typename R>
1271 using P_ =
typename R::P;
1272 using Q_ =
typename R::Q;
1273 using Den_ = std::ratio_subtract<P_, Square<Q_>>;
1274 using A_ = std::ratio_divide<Q_, Den_>;
1275 using B_ = std::ratio_divide<P_, Square<Den_>>;
1276 static constexpr const std::intmax_t I_ = (A_::num + Integer<std::ratio_multiply<B_, Square<std::ratio<A_::den>>>>
::value) / A_::den;
1277 using I = std::ratio<I_>;
1278 using Rem = Remainder<B_, std::ratio_subtract<I, A_>>;
1285 template <
typename Tr, std::
intmax_t N>
1286 struct ContinuedFraction {
1287 template <
typename T>
1288 using Abs_ = std::conditional_t<std::ratio_less<T, Zero>::value, std::ratio_subtract<Zero, T>, T>;
1291 using Last_ = ContinuedFraction<
R, N - 1>;
1292 using Reciprocal_ = Reciprocal<typename Last_::Rem>;
1293 using Rem =
typename Reciprocal_::Rem;
1294 using I_ =
typename Reciprocal_::I;
1295 using Den_ = std::ratio_add<typename Last_::W, I_>;
1296 using U = std::ratio_divide<typename Last_::V, Den_>;
1297 using V = std::ratio_divide<std::ratio_add<typename Last_::U, std::ratio_multiply<typename Last_::V, I_>>, Den_>;
1298 using W = std::ratio_divide<One, Den_>;
1299 using Error = Abs_<std::ratio_divide<std::ratio_subtract<U, std::ratio_multiply<V, W>>,
typename Reciprocal<Rem>::I>>;
1302 template <
typename Tr>
1303 struct ContinuedFraction<Tr, 1> {
1306 using V = std::ratio<Integer<R>::value>;
1308 using Rem = Remainder<R, V>;
1309 using Error = std::ratio_divide<One, typename Reciprocal<Rem>::I>;
1312 template <
typename R,
typename Eps, std::
intmax_t N = 1,
typename enabled =
void>
1313 struct Sqrt_ : Sqrt_<R, Eps, N + 1> {};
1315 template <
typename R,
typename Eps, std::
intmax_t N>
1316 struct Sqrt_<
R, Eps, N,
std::
enable_if_t<std::ratio_less_equal<typename ContinuedFraction<R, N>::Error, Eps>::value>> {
1317 using type =
typename ContinuedFraction<R, N>::V;
1320 template <
typename R,
typename Eps,
typename enabled =
void>
1322 static_assert(std::ratio_greater_equal<R, Zero>::value,
"R can't be negative");
1325 template <
typename R,
typename Eps>
1326 struct Sqrt<
R, Eps,
std::
enable_if_t<std::ratio_greater_equal<R, Zero>::value && IsPerfectSquare<R>::value>> {
1327 using type =
typename IsPerfectSquare<R>::Sqrt;
1330 template <
typename R,
typename Eps>
1331 struct Sqrt<
R, Eps,
std::
enable_if_t<(std::ratio_greater_equal<R, Zero>::value && !IsPerfectSquare<R>::value)>> : Sqrt_<R, Eps>{};
1355 template<
typename Ratio, std::
intmax_t Eps = 10000000000>
1366 template<
class Unit, std::
intmax_t Eps>
1370 using Conversion =
typename Unit::conversion_ratio;
1372 sqrt_base<traits::base_unit_of<typename Unit::base_unit_type>>,
1373 std::ratio_divide<typename Unit::pi_exponent_ratio, std::ratio<2>>,
1374 typename Unit::translation_ratio>;
1400 template<
class U, std::
intmax_t Eps = 10000000000>
1415 template<
class U,
class... Us>
struct compound_impl;
1416 template<
class U>
struct compound_impl<U> {
using type = U; };
1417 template<
class U1,
class U2,
class...Us>
1418 struct compound_impl<U1, U2, Us...>
1419 : compound_impl<unit_multiply<U1, U2>, Us...> {};
1433 template<
class U,
class... Us>
1447 template<
class Ratio,
class Unit>
1456 template <
int N,
class U>
1457 struct power_of_ratio
1459 typedef std::ratio_multiply<U,
typename power_of_ratio<N - 1, U>
::type>
type;
1464 struct power_of_ratio<1, U>
1501 template<
class U>
using kibi =
typename units::detail::prefix<std::ratio<1024>, U>
::type;
1502 template<
class U>
using mebi =
typename units::detail::prefix<std::ratio<1048576>, U>
::type;
1503 template<
class U>
using gibi =
typename units::detail::prefix<std::ratio<1073741824>, U>
::type;
1504 template<
class U>
using tebi =
typename units::detail::prefix<std::ratio<1099511627776>, U>
::type;
1505 template<
class U>
using pebi =
typename units::detail::prefix<std::ratio<1125899906842624>, U>
::type;
1506 template<
class U>
using exbi =
typename units::detail::prefix<std::ratio<1152921504606846976>, U>
::type;
1527 template<
class U1,
class U2>
1528 struct is_convertible_unit : std::is_same <traits::base_unit_of<typename units::traits::unit_traits<U1>::base_unit_type>,
1529 base_unit_of<typename units::traits::unit_traits<U2>::base_unit_type >> {};
1530 template<
class U1,
class U2>
1543 return y == 0 ? 1.0 : x *
pow(x,
y - 1);
1548 return x < 0 ? -x : x;
1552 template<
class UnitFrom,
class UnitTo,
class Ratio,
class PiRatio,
class Translation,
typename T>
1553 static inline constexpr T
convert(
const T&
value, std::true_type, std::false_type, std::false_type)
noexcept
1559 template<
class UnitFrom,
class UnitTo,
class Ratio,
class PiRatio,
class Translation,
typename T>
1560 static inline constexpr T
convert(
const T&
value, std::true_type, std::false_type, std::true_type)
noexcept
1566 template<
class UnitFrom,
class UnitTo,
class Ratio,
class PiRatio,
class Translation,
typename T>
1567 static inline constexpr T
convert(
const T&
value, std::true_type, std::true_type, std::false_type)
noexcept
1573 template<
class UnitFrom,
class UnitTo,
class Ratio,
class PiRatio,
class Translation,
typename T>
1574 static inline constexpr T
convert(
const T&
value, std::true_type, std::true_type, std::true_type)
noexcept
1580 template<
class UnitFrom,
class UnitTo,
class Ratio,
class PiRatio,
class Translation,
typename T>
1581 static inline constexpr T
convert(
const T&
value, std::false_type, std::false_type, std::false_type)
noexcept
1583 return ((
value * Ratio::num) / Ratio::den);
1588 template<
class UnitFrom,
class UnitTo,
class Ratio,
class PiRatio,
class Translation,
typename T>
1589 static inline constexpr
1590 std::enable_if_t<(PiRatio::num / PiRatio::den >= 1 && PiRatio::num % PiRatio::den == 0), T>
1591 convert(
const T&
value, std::false_type, std::true_type, std::false_type)
noexcept
1593 return ((
value *
pow(constants::detail::PI_VAL, PiRatio::num / PiRatio::den) * Ratio::num) / Ratio::den);
1598 template<
class UnitFrom,
class UnitTo,
class Ratio,
class PiRatio,
class Translation,
typename T>
1599 static inline constexpr
1600 std::enable_if_t<(PiRatio::num / PiRatio::den <= -1 && PiRatio::num % PiRatio::den == 0), T>
1601 convert(
const T&
value, std::false_type, std::true_type, std::false_type)
noexcept
1603 return (
value * Ratio::num) / (Ratio::den *
pow(constants::detail::PI_VAL, -PiRatio::num / PiRatio::den));
1608 template<
class UnitFrom,
class UnitTo,
class Ratio,
class PiRatio,
class Translation,
typename T>
1610 std::enable_if_t<(PiRatio::num / PiRatio::den < 1 && PiRatio::num / PiRatio::den > -1), T>
1611 convert(
const T&
value, std::false_type, std::true_type, std::false_type)
noexcept
1613 return ((
value *
std::pow(constants::detail::PI_VAL, PiRatio::num / PiRatio::den) * Ratio::num) / Ratio::den);
1617 template<
class UnitFrom,
class UnitTo,
class Ratio,
class PiRatio,
class Translation,
typename T>
1618 static inline constexpr T
convert(
const T&
value, std::false_type, std::false_type, std::true_type)
noexcept
1624 template<
class UnitFrom,
class UnitTo,
class Ratio,
class PiRatio,
class Translation,
typename T>
1625 static inline constexpr T
convert(
const T&
value,
const std::false_type,
const std::true_type,
const std::true_type)
noexcept
1627 return ((
value *
std::pow(constants::detail::PI_VAL, PiRatio::num / PiRatio::den) * Ratio::num) / Ratio::den) + (
static_cast<UNIT_LIB_DEFAULT_TYPE>(Translation::num) / Translation::den);
1647 template<
class UnitFrom,
class UnitTo,
typename T = UNIT_LIB_DEFAULT_TYPE>
1654 using Ratio = std::ratio_divide<typename UnitFrom::conversion_ratio, typename UnitTo::conversion_ratio>;
1655 using PiRatio = std::ratio_subtract<typename UnitFrom::pi_exponent_ratio, typename UnitTo::pi_exponent_ratio>;
1656 using Translation = std::ratio_divide<std::ratio_subtract<typename UnitFrom::translation_ratio, typename UnitTo::translation_ratio>,
typename UnitTo::conversion_ratio>;
1658 using isSame =
typename std::is_same<std::decay_t<UnitFrom>, std::decay_t<UnitTo>>
::type;
1659 using piRequired = std::integral_constant<bool, !(std::is_same<std::ratio<0>, PiRatio>
::value)>;
1660 using translationRequired = std::integral_constant<bool, !(std::is_same<std::ratio<0>, Translation>
::value)>;
1662 return units::detail::convert<UnitFrom, UnitTo, Ratio, PiRatio, Translation, T>
1663 (
value, isSame{}, piRequired{}, translationRequired{});
1679 template<
class T,
class Ret>
1680 struct has_operator_parenthesis_impl
1683 static constexpr auto test(U*) ->
decltype(std::declval<U>()()) {
return decltype(std::declval<U>()()){}; }
1685 static constexpr std::false_type test(...) {
return std::false_type{}; }
1687 using type =
typename std::is_same<Ret, decltype(test<T>(0))>
::type;
1695 template<
class T,
class Ret>
1696 struct has_operator_parenthesis : traits::detail::has_operator_parenthesis_impl<T, Ret>
::type {};
1707 template<
class T,
class Ret>
1708 struct has_value_member_impl
1711 static constexpr auto test(U* p) ->
decltype(p->m_value) {
return p->m_value; }
1713 static constexpr auto test(...)->std::false_type {
return std::false_type{}; }
1715 using type =
typename std::is_same<std::decay_t<Ret>, std::decay_t<decltype(test<T>(0))>>
::type;
1723 template<
class T,
class Ret>
1724 struct has_value_member : traits::detail::has_value_member_impl<T, Ret>
::type {};
1725 template<
class T,
class Ret>
1726 inline constexpr bool has_value_member_v = has_value_member<T, Ret>::value;
1743 template<
class T,
class Ret>
1745 std::is_default_constructible<T>::value &&
1746 has_operator_parenthesis<T, Ret>::value &&
1747 has_value_member<T, Ret>::value &&
1748 std::is_trivial<T>::value>
1758#ifdef FOR_DOXYGEN_PURPOSOES_ONLY
1765 template<
typename T>
1766 struct unit_t_traits
1768 typedef typename T::non_linear_scale_type non_linear_scale_type;
1769 typedef typename T::underlying_type underlying_type;
1770 typedef typename T::value_type value_type;
1771 typedef typename T::unit_type unit_type;
1780 template<
typename T,
typename =
void>
1781 struct unit_t_traits
1783 typedef void non_linear_scale_type;
1784 typedef void underlying_type;
1785 typedef void value_type;
1786 typedef void unit_type;
1794 template<
typename T>
1795 struct unit_t_traits <T, typename
void_t<
1796 typename T::non_linear_scale_type,
1797 typename T::underlying_type,
1798 typename T::value_type,
1799 typename T::unit_type>
::type>
1801 typedef typename T::non_linear_scale_type non_linear_scale_type;
1802 typedef typename T::underlying_type underlying_type;
1803 typedef typename T::value_type value_type;
1804 typedef typename T::unit_type unit_type;
1823 template<
class U1,
class U2>
1825 is_convertible_unit<typename units::traits::unit_t_traits<U1>::unit_type, typename units::traits::unit_t_traits<U2>::unit_type>::value>
1851 #if !defined(_MSC_VER) || _MSC_VER > 1800
1924 template<
class Units,
typename T = UNIT_LIB_DEFAULT_TYPE,
template<
typename>
class NonLinearScale =
linear_scale>
1925 class unit_t :
public NonLinearScale<T>, units::detail::_unit_t
1927 static_assert(
traits::is_unit<Units>::value,
"Template parameter `Units` must be a unit tag. Check that you aren't using a unit type (_t).");
1932 using nls = NonLinearScale<T>;
1956 template<
class... Args>
1967 template<class Ty, class = typename std::enable_if<traits::is_dimensionless_unit<Units>::value && std::is_arithmetic<Ty>::value>
::type>
1979 inline constexpr unit_t(
const std::chrono::duration<Rep, Period>&
value) noexcept :
1990 template<
class UnitsRhs,
typename Ty,
template<
typename>
class NlsRhs>
1992 nls(units::convert<UnitsRhs, Units, T>(rhs.m_value), std::true_type() )
2002 template<
class UnitsRhs,
typename Ty,
template<
typename>
class NlsRhs>
2005 nls::m_value = units::convert<UnitsRhs, Units, T>(rhs.m_value);
2014 template<class Ty, class = std::enable_if_t<traits::is_dimensionless_unit<Units>::value && std::is_arithmetic<Ty>::value>>
2027 template<
class UnitsRhs,
typename Ty,
template<
typename>
class NlsRhs>
2030 return (nls::m_value < units::convert<UnitsRhs, Units>(rhs.m_value));
2039 template<
class UnitsRhs,
typename Ty,
template<
typename>
class NlsRhs>
2042 return (nls::m_value <= units::convert<UnitsRhs, Units>(rhs.m_value));
2051 template<
class UnitsRhs,
typename Ty,
template<
typename>
class NlsRhs>
2054 return (nls::m_value > units::convert<UnitsRhs, Units>(rhs.m_value));
2063 template<
class UnitsRhs,
typename Ty,
template<
typename>
class NlsRhs>
2066 return (nls::m_value >= units::convert<UnitsRhs, Units>(rhs.m_value));
2076 template<
class UnitsRhs,
typename Ty,
template<
typename>
class NlsRhs, std::enable_if_t<std::is_floating_point<T>::value || std::is_floating_point<Ty>::value,
int> = 0>
2079 return detail::abs(nls::m_value - units::convert<UnitsRhs, Units>(rhs.m_value)) < std::numeric_limits<T>::epsilon() *
2080 detail::abs(nls::m_value + units::convert<UnitsRhs, Units>(rhs.m_value)) ||
2084 template<
class UnitsRhs,
typename Ty,
template<
typename>
class NlsRhs, std::enable_if_t<std::is_integral<T>::value && std::is_integral<Ty>::value,
int> = 0>
2087 return nls::m_value == units::convert<UnitsRhs, Units>(rhs.m_value);
2097 template<
class UnitsRhs,
typename Ty,
template<
typename>
class NlsRhs>
2100 return !(*
this == rhs);
2116 template<typename Ty, class = std::enable_if_t<std::is_arithmetic<Ty>::value>>
2117 inline constexpr Ty
to() const noexcept
2119 return static_cast<Ty
>(*this);
2127 template<typename Ty, class = std::enable_if_t<std::is_arithmetic<Ty>::value>>
2130 return static_cast<Ty
>(
m_value);
2153 template<class Ty, std::enable_if_t<traits::is_dimensionless_unit<Units>::value && std::is_arithmetic<Ty>::value,
int> = 0>
2154 inline constexpr operator Ty() const noexcept
2164 template<class Ty, std::enable_if_t<!traits::is_dimensionless_unit<Units>::value && std::is_arithmetic<Ty>::value,
int> = 0>
2165 inline constexpr explicit operator Ty() const noexcept
2167 return static_cast<Ty
>((*this)());
2174 template<
typename U = Units, std::enable_if_t<units::traits::is_convertible_unit<U, unit<std::ratio<1>, category::time_unit>>::value,
int> = 0>
2175 inline constexpr operator std::chrono::nanoseconds() const noexcept
2177 return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::duration<double, std::nano>(
units::convert<Units,
unit<std::ratio<1,1000000000>,
category::time_unit>>((*
this)())));
2183 inline constexpr const char*
name() const noexcept
2198 template<
class U,
typename Ty,
template<
typename>
class Nlt>
2216 template<class UnitType, typename T, class = std::enable_if_t<std::is_arithmetic<T>::value>>
2221 return UnitType(
value);
2224#if defined(UNIT_LIB_ENABLE_IOSTREAM)
2225 template<
class Units,
typename T,
template<
typename>
class NonLinearScale>
2226 inline std::ostream&
operator<<(std::ostream& os,
const unit_t<Units, T, NonLinearScale>& obj)
noexcept
2228 using BaseUnits = unit<std::ratio<1>,
typename traits::unit_traits<Units>::base_unit_type>;
2229 os << convert<Units, BaseUnits>(obj());
2231 if (traits::unit_traits<Units>::base_unit_type::meter_ratio::num != 0) { os <<
" m"; }
2232 if (traits::unit_traits<Units>::base_unit_type::meter_ratio::num != 0 &&
2233 traits::unit_traits<Units>::base_unit_type::meter_ratio::num != 1) { os <<
"^" << traits::unit_traits<Units>::base_unit_type::meter_ratio::num; }
2234 if (traits::unit_traits<Units>::base_unit_type::meter_ratio::den != 1) { os <<
"/" << traits::unit_traits<Units>::base_unit_type::meter_ratio::den; }
2236 if (traits::unit_traits<Units>::base_unit_type::kilogram_ratio::num != 0) { os <<
" kg"; }
2237 if (traits::unit_traits<Units>::base_unit_type::kilogram_ratio::num != 0 &&
2238 traits::unit_traits<Units>::base_unit_type::kilogram_ratio::num != 1) { os <<
"^" << traits::unit_traits<Units>::base_unit_type::kilogram_ratio::num; }
2239 if (traits::unit_traits<Units>::base_unit_type::kilogram_ratio::den != 1) { os <<
"/" << traits::unit_traits<Units>::base_unit_type::kilogram_ratio::den; }
2241 if (traits::unit_traits<Units>::base_unit_type::second_ratio::num != 0) { os <<
" s"; }
2242 if (traits::unit_traits<Units>::base_unit_type::second_ratio::num != 0 &&
2243 traits::unit_traits<Units>::base_unit_type::second_ratio::num != 1) { os <<
"^" << traits::unit_traits<Units>::base_unit_type::second_ratio::num; }
2244 if (traits::unit_traits<Units>::base_unit_type::second_ratio::den != 1) { os <<
"/" << traits::unit_traits<Units>::base_unit_type::second_ratio::den; }
2246 if (traits::unit_traits<Units>::base_unit_type::ampere_ratio::num != 0) { os <<
" A"; }
2247 if (traits::unit_traits<Units>::base_unit_type::ampere_ratio::num != 0 &&
2248 traits::unit_traits<Units>::base_unit_type::ampere_ratio::num != 1) { os <<
"^" << traits::unit_traits<Units>::base_unit_type::ampere_ratio::num; }
2249 if (traits::unit_traits<Units>::base_unit_type::ampere_ratio::den != 1) { os <<
"/" << traits::unit_traits<Units>::base_unit_type::ampere_ratio::den; }
2251 if (traits::unit_traits<Units>::base_unit_type::kelvin_ratio::num != 0) { os <<
" K"; }
2252 if (traits::unit_traits<Units>::base_unit_type::kelvin_ratio::num != 0 &&
2253 traits::unit_traits<Units>::base_unit_type::kelvin_ratio::num != 1) { os <<
"^" << traits::unit_traits<Units>::base_unit_type::kelvin_ratio::num; }
2254 if (traits::unit_traits<Units>::base_unit_type::kelvin_ratio::den != 1) { os <<
"/" << traits::unit_traits<Units>::base_unit_type::kelvin_ratio::den; }
2256 if (traits::unit_traits<Units>::base_unit_type::mole_ratio::num != 0) { os <<
" mol"; }
2257 if (traits::unit_traits<Units>::base_unit_type::mole_ratio::num != 0 &&
2258 traits::unit_traits<Units>::base_unit_type::mole_ratio::num != 1) { os <<
"^" << traits::unit_traits<Units>::base_unit_type::mole_ratio::num; }
2259 if (traits::unit_traits<Units>::base_unit_type::mole_ratio::den != 1) { os <<
"/" << traits::unit_traits<Units>::base_unit_type::mole_ratio::den; }
2261 if (traits::unit_traits<Units>::base_unit_type::candela_ratio::num != 0) { os <<
" cd"; }
2262 if (traits::unit_traits<Units>::base_unit_type::candela_ratio::num != 0 &&
2263 traits::unit_traits<Units>::base_unit_type::candela_ratio::num != 1) { os <<
"^" << traits::unit_traits<Units>::base_unit_type::candela_ratio::num; }
2264 if (traits::unit_traits<Units>::base_unit_type::candela_ratio::den != 1) { os <<
"/" << traits::unit_traits<Units>::base_unit_type::candela_ratio::den; }
2266 if (traits::unit_traits<Units>::base_unit_type::radian_ratio::num != 0) { os <<
" rad"; }
2267 if (traits::unit_traits<Units>::base_unit_type::radian_ratio::num != 0 &&
2268 traits::unit_traits<Units>::base_unit_type::radian_ratio::num != 1) { os <<
"^" << traits::unit_traits<Units>::base_unit_type::radian_ratio::num; }
2269 if (traits::unit_traits<Units>::base_unit_type::radian_ratio::den != 1) { os <<
"/" << traits::unit_traits<Units>::base_unit_type::radian_ratio::den; }
2271 if (traits::unit_traits<Units>::base_unit_type::byte_ratio::num != 0) { os <<
" b"; }
2272 if (traits::unit_traits<Units>::base_unit_type::byte_ratio::num != 0 &&
2273 traits::unit_traits<Units>::base_unit_type::byte_ratio::num != 1) { os <<
"^" << traits::unit_traits<Units>::base_unit_type::byte_ratio::num; }
2274 if (traits::unit_traits<Units>::base_unit_type::byte_ratio::den != 1) { os <<
"/" << traits::unit_traits<Units>::base_unit_type::byte_ratio::den; }
2280 template<
class Units,
typename T,
template<
typename>
class NonLinearScale,
typename RhsType>
2285 "parameters are not compatible units.");
2291 template<
class Units,
typename T,
template<
typename>
class NonLinearScale,
typename RhsType>
2296 "parameters are not compatible units.");
2302 template<
class Units,
typename T,
template<
typename>
class NonLinearScale,
typename RhsType>
2306 "right-hand side parameter must be dimensionless.");
2312 template<
class Units,
typename T,
template<
typename>
class NonLinearScale,
typename RhsType>
2316 "right-hand side parameter must be dimensionless.");
2327 template<
class Units,
typename T,
template<
typename>
class NonLinearScale>
2334 template<
class Units,
typename T,
template<
typename>
class NonLinearScale>
2342 template<
class Units,
typename T,
template<
typename>
class NonLinearScale>
2351 template<
class Units,
typename T,
template<
typename>
class NonLinearScale>
2358 template<
class Units,
typename T,
template<
typename>
class NonLinearScale>
2366 template<
class Units,
typename T,
template<
typename>
class NonLinearScale>
2391 template<typename T, typename Units, class = std::enable_if_t<std::is_arithmetic<T>::value && traits::is_unit_t<Units>::value>>
2394 return static_cast<T
>(
value);
2402 template<
typename T>
struct decibel_scale;
2413#if !defined(_MSC_VER) || _MSC_VER > 1800
2414 template<
typename... T>
2415 struct has_linear_scale : std::integral_constant<bool, units::all_true<std::is_base_of<units::linear_scale<typename units::traits::unit_t_traits<T>::underlying_type>, T>::value...>::value > {};
2416 template<
typename... T>
2419 template<
typename T1,
typename T2 = T1,
typename T3 = T1>
2421 std::is_base_of<units::linear_scale<typename units::traits::unit_t_traits<T1>::underlying_type>, T1>::value &&
2422 std::is_base_of<units::linear_scale<typename units::traits::unit_t_traits<T2>::underlying_type>, T2>::value &&
2423 std::is_base_of<units::linear_scale<typename units::traits::unit_t_traits<T3>::underlying_type>, T3>::value> {};
2424 template<
typename T1,
typename T2 = T1,
typename T3 = T1>
2435#if !defined(_MSC_VER) || _MSC_VER > 1800
2436 template<
typename... T>
2437 struct has_decibel_scale : std::integral_constant<bool, units::all_true<std::is_base_of<units::decibel_scale<typename units::traits::unit_t_traits<T>::underlying_type>, T>::value...>::value> {};
2438 template<
typename... T>
2441 template<
typename T1,
typename T2 = T1,
typename T3 = T1>
2443 std::is_base_of<units::decibel_scale<typename units::traits::unit_t_traits<T1>::underlying_type>, T1>::value &&
2444 std::is_base_of<units::decibel_scale<typename units::traits::unit_t_traits<T2>::underlying_type>, T2>::value &&
2445 std::is_base_of<units::decibel_scale<typename units::traits::unit_t_traits<T2>::underlying_type>, T3>::value> {};
2446 template<
typename T1,
typename T2 = T1,
typename T3 = T1>
2458 template<
typename T1,
typename T2>
2460 std::is_same<typename units::traits::unit_t_traits<T1>::non_linear_scale_type, typename units::traits::unit_t_traits<T2>::non_linear_scale_type>::value>
2462 template<
typename T1,
typename T2>
2485 template<
typename T>
2492#if defined(_MSC_VER) && (_MSC_VER > 1800)
2496 template<
class... Args>
2518#if defined(_MSC_VER)
2519# pragma warning(push)
2520# pragma warning(disable : 4348)
2524#if defined(_MSC_VER)
2525# pragma warning(pop)
2532 template<class UnitTypeLhs, class UnitTypeRhs, std::enable_if_t<!traits::is_same_scale<UnitTypeLhs, UnitTypeRhs>::value,
int> = 0>
2533 constexpr inline int operator+(
const UnitTypeLhs& ,
const UnitTypeRhs& )
noexcept
2540 template<class UnitTypeLhs, class UnitTypeRhs, std::enable_if_t<traits::has_linear_scale<UnitTypeLhs, UnitTypeRhs>::value,
int> = 0>
2541 inline constexpr UnitTypeLhs
operator+(
const UnitTypeLhs& lhs,
const UnitTypeRhs& rhs)
noexcept
2543 using UnitsLhs =
typename units::traits::unit_t_traits<UnitTypeLhs>::unit_type;
2544 using UnitsRhs =
typename units::traits::unit_t_traits<UnitTypeRhs>::unit_type;
2545 return UnitTypeLhs(lhs() + convert<UnitsRhs, UnitsLhs>(rhs()));
2549 template<typename T, std::enable_if_t<std::is_arithmetic<T>::value,
int> = 0>
2556 template<typename T, std::enable_if_t<std::is_arithmetic<T>::value,
int> = 0>
2563 template<class UnitTypeLhs, class UnitTypeRhs, std::enable_if_t<traits::has_linear_scale<UnitTypeLhs, UnitTypeRhs>::value,
int> = 0>
2564 inline constexpr UnitTypeLhs
operator-(
const UnitTypeLhs& lhs,
const UnitTypeRhs& rhs)
noexcept
2566 using UnitsLhs =
typename units::traits::unit_t_traits<UnitTypeLhs>::unit_type;
2567 using UnitsRhs =
typename units::traits::unit_t_traits<UnitTypeRhs>::unit_type;
2568 return UnitTypeLhs(lhs() - convert<UnitsRhs, UnitsLhs>(rhs()));
2572 template<typename T, std::enable_if_t<std::is_arithmetic<T>::value,
int> = 0>
2579 template<typename T, std::enable_if_t<std::is_arithmetic<T>::value,
int> = 0>
2586 template<
class UnitTypeLhs,
class UnitTypeRhs,
2587 std::enable_if_t<traits::is_convertible_unit_t<UnitTypeLhs, UnitTypeRhs>::value && traits::has_linear_scale<UnitTypeLhs, UnitTypeRhs>::value,
int> = 0>
2590 using UnitsLhs =
typename units::traits::unit_t_traits<UnitTypeLhs>::unit_type;
2591 using UnitsRhs =
typename units::traits::unit_t_traits<UnitTypeRhs>::unit_type;
2593 (lhs() * convert<UnitsRhs, UnitsLhs>(rhs()));
2597 template<
class UnitTypeLhs,
class UnitTypeRhs,
2598 std::enable_if_t<!traits::is_convertible_unit_t<UnitTypeLhs, UnitTypeRhs>::value && traits::has_linear_scale<UnitTypeLhs, UnitTypeRhs>::value && !traits::is_dimensionless_unit<UnitTypeLhs>::value && !traits::is_dimensionless_unit<UnitTypeRhs>::value,
int> = 0>
2601 using UnitsLhs =
typename units::traits::unit_t_traits<UnitTypeLhs>::unit_type;
2602 using UnitsRhs =
typename units::traits::unit_t_traits<UnitTypeRhs>::unit_type;
2603 return unit_t<compound_unit<UnitsLhs, UnitsRhs>>
2608 template<
class UnitTypeLhs,
typename UnitTypeRhs,
2609 std::enable_if_t<traits::has_linear_scale<UnitTypeLhs, UnitTypeRhs>::value && !traits::is_dimensionless_unit<UnitTypeLhs>::value && traits::is_dimensionless_unit<UnitTypeRhs>::value,
int> = 0>
2610 inline constexpr UnitTypeLhs
operator*(
const UnitTypeLhs& lhs,
const UnitTypeRhs& rhs)
noexcept
2617 template<
class UnitTypeLhs,
typename UnitTypeRhs,
2618 std::enable_if_t<traits::has_linear_scale<UnitTypeLhs, UnitTypeRhs>::value && traits::is_dimensionless_unit<UnitTypeLhs>::value && !traits::is_dimensionless_unit<UnitTypeRhs>::value,
int> = 0>
2619 inline constexpr UnitTypeRhs
operator*(
const UnitTypeLhs& lhs,
const UnitTypeRhs& rhs)
noexcept
2626 template<
class UnitTypeLhs,
typename T,
2627 std::enable_if_t<std::is_arithmetic<T>::value && traits::has_linear_scale<UnitTypeLhs>::value,
int> = 0>
2628 inline constexpr UnitTypeLhs
operator*(
const UnitTypeLhs& lhs, T rhs)
noexcept
2630 return UnitTypeLhs(lhs() * rhs);
2634 template<
class UnitTypeRhs,
typename T,
2635 std::enable_if_t<std::is_arithmetic<T>::value && traits::has_linear_scale<UnitTypeRhs>::value,
int> = 0>
2636 inline constexpr UnitTypeRhs
operator*(T lhs,
const UnitTypeRhs& rhs)
noexcept
2638 return UnitTypeRhs(lhs * rhs());
2642 template<
class UnitTypeLhs,
class UnitTypeRhs,
2643 std::enable_if_t<traits::is_convertible_unit_t<UnitTypeLhs, UnitTypeRhs>::value && traits::has_linear_scale<UnitTypeLhs, UnitTypeRhs>::value,
int> = 0>
2646 using UnitsLhs =
typename units::traits::unit_t_traits<UnitTypeLhs>::unit_type;
2647 using UnitsRhs =
typename units::traits::unit_t_traits<UnitTypeRhs>::unit_type;
2652 template<
class UnitTypeLhs,
class UnitTypeRhs,
2653 std::enable_if_t<!traits::is_convertible_unit_t<UnitTypeLhs, UnitTypeRhs>::value && traits::has_linear_scale<UnitTypeLhs, UnitTypeRhs>::value && !traits::is_dimensionless_unit<UnitTypeLhs>::value && !traits::is_dimensionless_unit<UnitTypeRhs>::value,
int> = 0>
2656 using UnitsLhs =
typename units::traits::unit_t_traits<UnitTypeLhs>::unit_type;
2657 using UnitsRhs =
typename units::traits::unit_t_traits<UnitTypeRhs>::unit_type;
2663 template<
class UnitTypeLhs,
class UnitTypeRhs,
2664 std::enable_if_t<traits::has_linear_scale<UnitTypeLhs, UnitTypeRhs>::value && !traits::is_dimensionless_unit<UnitTypeLhs>::value && traits::is_dimensionless_unit<UnitTypeRhs>::value,
int> = 0>
2665 inline constexpr UnitTypeLhs
operator/(
const UnitTypeLhs& lhs,
const UnitTypeRhs& rhs)
noexcept
2671 template<
class UnitTypeLhs,
class UnitTypeRhs,
2672 std::enable_if_t<traits::has_linear_scale<UnitTypeLhs, UnitTypeRhs>::value && traits::is_dimensionless_unit<UnitTypeLhs>::value && !traits::is_dimensionless_unit<UnitTypeRhs>::value,
int> = 0>
2680 template<
class UnitTypeLhs,
typename T,
2681 std::enable_if_t<std::is_arithmetic<T>::value && traits::has_linear_scale<UnitTypeLhs>::value,
int> = 0>
2682 inline constexpr UnitTypeLhs
operator/(
const UnitTypeLhs& lhs, T rhs)
noexcept
2684 return UnitTypeLhs(lhs() / rhs);
2688 template<
class UnitTypeRhs,
typename T,
2689 std::enable_if_t<std::is_arithmetic<T>::value && traits::has_linear_scale<UnitTypeRhs>::value,
int> = 0>
2692 using UnitsRhs =
typename units::traits::unit_t_traits<UnitTypeRhs>::unit_type;
2701 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2708 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2715 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2721 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2727 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2733 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2739 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2745 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2751 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2757 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2763 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2766 return lhs < static_cast<UNIT_LIB_DEFAULT_TYPE>(rhs);
2769 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2783 template <
int N,
class U>
struct power_of_unit
2785 typedef typename units::detail::unit_multiply<U,
typename power_of_unit<N - 1, U>
::type>
type;
2789 template <
class U>
struct power_of_unit<1, U>
2805 template<int power, class UnitType, class = typename std::enable_if<traits::has_linear_scale<UnitType>::value,
int>>
2820 template<int power, class UnitType, class = typename std::enable_if<traits::has_linear_scale<UnitType>::value,
int>>
2823 static_assert(power >= 0,
"cpow cannot accept negative numbers. Try units::math::pow instead.");
2839 template<
typename T>
2846#if defined(_MSC_VER) && (_MSC_VER > 1800)
2851 template<
class... Args>
2871#if defined(UNIT_LIB_ENABLE_IOSTREAM)
2874 inline std::ostream&
operator<<(std::ostream& os,
const dB_t& obj) { os << obj() <<
" dB";
return os; }
2878#if !defined(UNIT_LIB_DISABLE_FMT)
2882 template <
typename FormatContext>
2884 FormatContext& ctx) ->
decltype(ctx.out())
2886 auto out = ctx.out();
2899 template<
class UnitTypeLhs,
class UnitTypeRhs,
2900 std::enable_if_t<traits::has_decibel_scale<UnitTypeLhs, UnitTypeRhs>::value,
int> = 0>
2903 using LhsUnits =
typename units::traits::unit_t_traits<UnitTypeLhs>::unit_type;
2904 using RhsUnits =
typename units::traits::unit_t_traits<UnitTypeRhs>::unit_type;
2905 using underlying_type =
typename units::traits::unit_t_traits<UnitTypeLhs>::underlying_type;
2908 (lhs.template toLinearized<underlying_type>() * convert<RhsUnits, LhsUnits>(rhs.template toLinearized<underlying_type>()), std::true_type());
2912 template<class UnitTypeLhs, std::enable_if_t<traits::has_decibel_scale<UnitTypeLhs>::value && !traits::is_dimensionless_unit<UnitTypeLhs>::value,
int> = 0>
2915 using underlying_type =
typename units::traits::unit_t_traits<UnitTypeLhs>::underlying_type;
2916 return UnitTypeLhs(lhs.template toLinearized<underlying_type>() * rhs.template toLinearized<underlying_type>(), std::true_type());
2920 template<class UnitTypeRhs, std::enable_if_t<traits::has_decibel_scale<UnitTypeRhs>::value && !traits::is_dimensionless_unit<UnitTypeRhs>::value,
int> = 0>
2923 using underlying_type =
typename units::traits::unit_t_traits<UnitTypeRhs>::underlying_type;
2924 return UnitTypeRhs(lhs.template toLinearized<underlying_type>() * rhs.template toLinearized<underlying_type>(), std::true_type());
2928 template<class UnitTypeLhs, class UnitTypeRhs, std::enable_if_t<traits::has_decibel_scale<UnitTypeLhs, UnitTypeRhs>::value,
int> = 0>
2931 using LhsUnits =
typename units::traits::unit_t_traits<UnitTypeLhs>::unit_type;
2932 using RhsUnits =
typename units::traits::unit_t_traits<UnitTypeRhs>::unit_type;
2933 using underlying_type =
typename units::traits::unit_t_traits<UnitTypeLhs>::underlying_type;
2936 (lhs.template toLinearized<underlying_type>() / convert<RhsUnits, LhsUnits>(rhs.template toLinearized<underlying_type>()), std::true_type());
2940 template<class UnitTypeLhs, std::enable_if_t<traits::has_decibel_scale<UnitTypeLhs>::value && !traits::is_dimensionless_unit<UnitTypeLhs>::value,
int> = 0>
2943 using underlying_type =
typename units::traits::unit_t_traits<UnitTypeLhs>::underlying_type;
2944 return UnitTypeLhs(lhs.template toLinearized<underlying_type>() / rhs.template toLinearized<underlying_type>(), std::true_type());
2948 template<class UnitTypeRhs, std::enable_if_t<traits::has_decibel_scale<UnitTypeRhs>::value && !traits::is_dimensionless_unit<UnitTypeRhs>::value,
int> = 0>
2951 using RhsUnits =
typename units::traits::unit_t_traits<UnitTypeRhs>::unit_type;
2952 using underlying_type =
typename units::traits::unit_t_traits<RhsUnits>::underlying_type;
2955 (lhs.template toLinearized<underlying_type>() / rhs.template toLinearized<underlying_type>(), std::true_type());
2965 template<
class Units>
2966 struct _unit_value_t {};
2972#ifdef FOR_DOXYGEN_PURPOSES_ONLY
2980 template<
typename T>
2981 struct unit_value_t_traits
2983 typedef typename T::unit_type unit_type;
2984 typedef typename T::ratio ratio;
2993 template<
typename T,
typename =
void>
2994 struct unit_value_t_traits
2996 typedef void unit_type;
3005 template<
typename T>
3006 struct unit_value_t_traits <T, typename
void_t<
3007 typename T::unit_type,
3008 typename T::ratio>
::type>
3010 typedef typename T::unit_type unit_type;
3011 typedef typename T::ratio ratio;
3033 template<
typename Units, std::u
intmax_t Num, std::u
intmax_t Denom = 1>
3053 template<typename T, typename Units = typename traits::unit_value_t_traits<T>::unit_type>
3055 std::is_base_of<units::detail::_unit_value_t<Units>, T>::value>
3057 template<typename T, typename Units = typename traits::unit_value_t_traits<T>::unit_type>
3065 template<
typename Category,
typename T>
3067 std::is_same<units::traits::base_unit_of<typename traits::unit_value_t_traits<T>::unit_type>, Category>::value>
3071 template<
typename Category,
typename T>
3079 template<
class U1,
class U2>
3080 struct unit_value_arithmetic
3085 using _UNIT1 =
typename traits::unit_value_t_traits<U1>::unit_type;
3086 using _UNIT2 =
typename traits::unit_value_t_traits<U2>::unit_type;
3087 using _CONV1 =
typename units::traits::unit_traits<_UNIT1>::conversion_ratio;
3088 using _CONV2 =
typename units::traits::unit_traits<_UNIT2>::conversion_ratio;
3089 using _RATIO1 =
typename traits::unit_value_t_traits<U1>::ratio;
3090 using _RATIO2 =
typename traits::unit_value_t_traits<U2>::ratio;
3091 using _RATIO2CONV =
typename std::ratio_divide<std::ratio_multiply<_RATIO2, _CONV2>, _CONV1>;
3092 using _PI_EXP = std::ratio_subtract<typename units::traits::unit_traits<_UNIT2>::pi_exponent_ratio,
typename units::traits::unit_traits<_UNIT1>::pi_exponent_ratio>;
3107 template<
class U1,
class U2>
3108 struct unit_value_add : units::detail::unit_value_arithmetic<U1, U2>, units::detail::_unit_value_t<typename traits::unit_value_t_traits<U1>::unit_type>
3111 using Base = units::detail::unit_value_arithmetic<U1, U2>;
3112 typedef typename Base::_UNIT1 unit_type;
3113 using ratio = std::ratio_add<typename Base::_RATIO1, typename Base::_RATIO2CONV>;
3126 using UsePi = std::integral_constant<bool, Base::_PI_EXP::num != 0>;
3127 return value(UsePi());
3138 static constexpr const unit_t<unit_type>
value(std::true_type)
noexcept
3156 template<
class U1,
class U2>
3157 struct unit_value_subtract : units::detail::unit_value_arithmetic<U1, U2>, units::detail::_unit_value_t<typename traits::unit_value_t_traits<U1>::unit_type>
3160 using Base = units::detail::unit_value_arithmetic<U1, U2>;
3162 typedef typename Base::_UNIT1 unit_type;
3163 using ratio = std::ratio_subtract<typename Base::_RATIO1, typename Base::_RATIO2CONV>;
3176 using UsePi = std::integral_constant<bool, Base::_PI_EXP::num != 0>;
3177 return value(UsePi());
3188 static constexpr const unit_t<unit_type>
value(std::true_type)
noexcept
3206 template<
class U1,
class U2>
3208 units::detail::_unit_value_t<typename std::conditional<traits::is_convertible_unit<typename traits::unit_value_t_traits<U1>::unit_type,
3209 typename traits::unit_value_t_traits<U2>::unit_type>::value, compound_unit<squared<typename traits::unit_value_t_traits<U1>::unit_type>>,
3210 compound_unit<typename traits::unit_value_t_traits<U1>::unit_type, typename traits::unit_value_t_traits<U2>::unit_type>>::type>
3213 using Base = units::detail::unit_value_arithmetic<U1, U2>;
3216 using ratio = std::conditional_t<traits::is_convertible_unit<typename Base::_UNIT1, typename Base::_UNIT2>::value, std::ratio_multiply<typename Base::_RATIO1, typename Base::_RATIO2CONV>, std::ratio_multiply<typename Base::_RATIO1, typename Base::_RATIO2>>;
3227 using UsePi = std::integral_constant<bool, Base::_PI_EXP::num != 0>;
3228 return value(UsePi());
3239 static constexpr const unit_t<unit_type>
value(std::true_type)
noexcept
3256 template<
class U1,
class U2>
3258 units::detail::_unit_value_t<typename std::conditional<traits::is_convertible_unit<typename traits::unit_value_t_traits<U1>::unit_type,
3259 typename traits::unit_value_t_traits<U2>::unit_type>::value, dimensionless::scalar, compound_unit<typename traits::unit_value_t_traits<U1>::unit_type,
3260 inverse<typename traits::unit_value_t_traits<U2>::unit_type>>>::type>
3263 using Base = units::detail::unit_value_arithmetic<U1, U2>;
3266 using ratio = std::conditional_t<traits::is_convertible_unit<typename Base::_UNIT1, typename Base::_UNIT2>::value, std::ratio_divide<typename Base::_RATIO1, typename Base::_RATIO2CONV>, std::ratio_divide<typename Base::_RATIO1, typename Base::_RATIO2>>;
3277 using UsePi = std::integral_constant<bool, Base::_PI_EXP::num != 0>;
3278 return value(UsePi());
3289 static constexpr const unit_t<unit_type>
value(std::true_type)
noexcept
3305 template<
class U1,
int power>
3306 struct unit_value_power : units::detail::unit_value_arithmetic<U1, U1>, units::detail::_unit_value_t<typename units::detail::power_of_unit<power, typename traits::unit_value_t_traits<U1>::unit_type>::type>
3309 using Base = units::detail::unit_value_arithmetic<U1, U1>;
3313 using pi_exponent = std::ratio_multiply<std::ratio<power>,
typename Base::_UNIT1::pi_exponent_ratio>;
3324 using UsePi = std::integral_constant<bool, Base::_PI_EXP::num != 0>;
3325 return value(UsePi());
3336 static constexpr const unit_t<unit_type>
value(std::true_type)
noexcept
3352 template<
class U1, std::
intmax_t Eps = 10000000000>
3353 struct unit_value_sqrt : units::detail::unit_value_arithmetic<U1, U1>, units::detail::_unit_value_t<square_root<typename traits::unit_value_t_traits<U1>::unit_type, Eps>>
3356 using Base = units::detail::unit_value_arithmetic<U1, U1>;
3371 using UsePi = std::integral_constant<bool, Base::_PI_EXP::num != 0>;
3372 return value(UsePi());
3383 static constexpr const unit_t<unit_type>
value(std::true_type)
noexcept
3408 template<
class UnitTypeLhs,
class UnitTypeRhs>
3409 UnitTypeLhs (
min)(
const UnitTypeLhs& lhs,
const UnitTypeRhs& rhs)
3413 return (lhs < r ? lhs : r);
3416 template<
class UnitTypeLhs,
class UnitTypeRhs>
3417 UnitTypeLhs (
max)(
const UnitTypeLhs& lhs,
const UnitTypeRhs& rhs)
3421 return (lhs > r ? lhs : r);
3427# if _MSC_VER <= 1800
3428# pragma warning(pop)
3430# pragma pop_macro("constexpr")
3432# pragma pop_macro("noexcept")
3433# undef _ALLOW_KEYWORD_MACROS
3435# pragma pop_macro("pascal")
3438#if defined(UNIT_HAS_LITERAL_SUPPORT)
3443#if !defined(UNIT_LIB_DISABLE_FMT)
Complete implementation of units - a compile-time, header-only, unit conversion library built on c++1...
#define UNIT_LIB_DEFAULT_TYPE
Definition: base.h:60
#define UNIT_ADD_CATEGORY_TRAIT(unitCategory)
Macro to create the is_category_unit type trait.
Definition: base.h:381
Container for values which represent quantities of a given unit.
Definition: base.h:1926
constexpr bool operator<(const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) const noexcept
less-than
Definition: base.h:2028
constexpr bool operator<=(const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) const noexcept
less-than or equal
Definition: base.h:2040
constexpr unit_t< U > convert() const noexcept
conversion
Definition: base.h:2143
unit_t & operator=(const Ty &rhs) noexcept
assignment
Definition: base.h:2015
constexpr unit_t(const std::chrono::duration< Rep, Period > &value) noexcept
chrono constructor
Definition: base.h:1979
constexpr underlying_type value() const noexcept
unit value
Definition: base.h:2107
constexpr unit_t(const Ty value) noexcept
constructor
Definition: base.h:1968
constexpr unit_t(const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) noexcept
copy constructor (converting)
Definition: base.h:1991
constexpr const char * name() const noexcept
returns the unit name
Definition: base.h:2183
constexpr Ty toLinearized() const noexcept
linearized unit value
Definition: base.h:2128
constexpr Ty to() const noexcept
unit value
Definition: base.h:2117
constexpr bool operator!=(const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) const noexcept
inequality
Definition: base.h:2098
Units unit_type
Type of unit the unit_t represents (e.g. meters)
Definition: base.h:1940
constexpr bool operator>(const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) const noexcept
greater-than
Definition: base.h:2052
T value_type
Synonym for underlying type. May be removed in future versions. Prefer underlying_type.
Definition: base.h:1939
constexpr bool operator==(const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) const noexcept
equality
Definition: base.h:2077
constexpr unit_t(const T value, const Args &... args) noexcept
constructor
Definition: base.h:1957
constexpr const char * abbreviation() const noexcept
returns the unit abbreviation
Definition: base.h:2191
NonLinearScale< T > non_linear_scale_type
Type of the non-linear scale of the unit_t (e.g. linear_scale)
Definition: base.h:1937
NonLinearScale< T > nls
Definition: base.h:1932
constexpr bool operator>=(const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) const noexcept
greater-than or equal
Definition: base.h:2064
constexpr unit_t()=default
default constructor.
unit_t & operator=(const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) noexcept
assignment
Definition: base.h:2003
T underlying_type
Type of the underlying storage of the unit_t (e.g. double)
Definition: base.h:1938
typename std::enable_if< B, T >::type enable_if_t
Definition: core.h:298
constexpr auto count() -> size_t
Definition: core.h:1204
type
Definition: core.h:575
void void_t
Definition: core.h:1682
constexpr T unit_cast(const Units &value) noexcept
Casts a unit container to an arithmetic type.
Definition: base.h:2392
static constexpr T convert(const T &value) noexcept
converts a value from one type to another.
Definition: base.h:1648
typename units::detail::Sqrt< Ratio, std::ratio< 1, Eps > >::type ratio_sqrt
Calculate square root of a ratio at compile-time.
Definition: base.h:1356
constexpr UnitType make_unit(const T value) noexcept
Constructs a unit container from an arithmetic type.
Definition: base.h:2217
typename units::detail::prefix< std::peta, U >::type peta
Represents the type of class U with the metric 'peta' prefix appended.
Definition: base.h:1491
typename units::detail::prefix< std::ratio< 1099511627776 >, U >::type tebi
Represents the type of class U with the binary 'tebi' prefix appended.
Definition: base.h:1504
typename units::detail::prefix< std::milli, U >::type milli
Represents the type of class U with the metric 'milli' prefix appended.
Definition: base.h:1482
typename units::detail::inverse_impl< U >::type inverse
represents the inverse unit type of class U.
Definition: base.h:1134
typename units::detail::prefix< std::micro, U >::type micro
Represents the type of class U with the metric 'micro' prefix appended.
Definition: base.h:1481
typename units::detail::prefix< std::ratio< 1048576 >, U >::type mebi
Represents the type of class U with the binary 'mibi' prefix appended.
Definition: base.h:1502
typename units::detail::prefix< std::ratio< 1152921504606846976 >, U >::type exbi
Represents the type of class U with the binary 'exbi' prefix appended.
Definition: base.h:1506
typename units::detail::prefix< std::giga, U >::type giga
Represents the type of class U with the metric 'giga' prefix appended.
Definition: base.h:1489
typename units::detail::squared_impl< U >::type squared
represents the unit type of class U squared
Definition: base.h:1165
typename units::detail::prefix< std::deca, U >::type deca
Represents the type of class U with the metric 'deca' prefix appended.
Definition: base.h:1485
typename units::detail::prefix< std::deci, U >::type deci
Represents the type of class U with the metric 'deci' prefix appended.
Definition: base.h:1484
typename units::detail::cubed_impl< U >::type cubed
represents the type of class U cubed.
Definition: base.h:1195
typename units::detail::prefix< std::femto, U >::type femto
Represents the type of class U with the metric 'femto' prefix appended.
Definition: base.h:1478
typename units::detail::prefix< std::pico, U >::type pico
Represents the type of class U with the metric 'pico' prefix appended.
Definition: base.h:1479
typename units::detail::prefix< std::tera, U >::type tera
Represents the type of class U with the metric 'tera' prefix appended.
Definition: base.h:1490
typename units::detail::prefix< std::hecto, U >::type hecto
Represents the type of class U with the metric 'hecto' prefix appended.
Definition: base.h:1486
typename units::detail::prefix< std::atto, U >::type atto
Represents the type of class U with the metric 'atto' prefix appended.
Definition: base.h:1477
typename units::detail::prefix< std::ratio< 1073741824 >, U >::type gibi
Represents the type of class U with the binary 'gibi' prefix appended.
Definition: base.h:1503
typename units::detail::prefix< std::exa, U >::type exa
Represents the type of class U with the metric 'exa' prefix appended.
Definition: base.h:1492
typename units::detail::sqrt_impl< U, Eps >::type square_root
represents the square root of type class U.
Definition: base.h:1401
typename units::detail::prefix< std::ratio< 1125899906842624 >, U >::type pebi
Represents the type of class U with the binary 'pebi' prefix appended.
Definition: base.h:1505
typename units::detail::prefix< std::ratio< 1024 >, U >::type kibi
Represents the type of class U with the binary 'kibi' prefix appended.
Definition: base.h:1501
typename units::detail::prefix< std::centi, U >::type centi
Represents the type of class U with the metric 'centi' prefix appended.
Definition: base.h:1483
typename units::detail::prefix< std::nano, U >::type nano
Represents the type of class U with the metric 'nano' prefix appended.
Definition: base.h:1480
typename units::detail::prefix< std::mega, U >::type mega
Represents the type of class U with the metric 'mega' prefix appended.
Definition: base.h:1488
typename units::detail::prefix< std::kilo, U >::type kilo
Represents the type of class U with the metric 'kilo' prefix appended.
Definition: base.h:1487
UnitType abs(const UnitType x) noexcept
Compute absolute value.
Definition: math.h:721
dimensionless::scalar_t log10(const ScalarUnit x) noexcept
Compute common logarithm.
Definition: math.h:365
typename units::detail::compound_impl< U, Us... >::type compound_unit
Represents a unit type made up from other units.
Definition: base.h:1434
@ Lower
View matrix as a lower triangular matrix.
Definition: Constants.h:209
@ Upper
View matrix as an upper triangular matrix.
Definition: Constants.h:211
constexpr common_t< T1, T2 > min(const T1 x, const T2 y) noexcept
Compile-time pairwise minimum function.
Definition: min.hpp:35
EIGEN_ALWAYS_INLINE std::ostream & operator<<(std::ostream &os, const half &v)
Definition: Half.h:761
const Scalar & y
Definition: MathFunctions.h:821
Definition: StdDeque.h:50
base_unit< detail::meter_ratio< 0 >, std::ratio< 0 >, std::ratio< 1 > > time_unit
Represents an SI base unit of time.
Definition: base.h:798
base_unit< detail::meter_ratio< 0 >, std::ratio< 1 > > mass_unit
Represents an SI base unit of mass.
Definition: base.h:797
base_unit< detail::meter_ratio<-3 >, std::ratio< 1 > > density_unit
Represents an SI derived unit of density.
Definition: base.h:834
base_unit< detail::meter_ratio< 2 >, std::ratio< 1 >, std::ratio<-2 >, std::ratio< 0 >, std::ratio<-1 > > magnetic_flux_unit
Represents an SI derived unit of magnetic flux.
Definition: base.h:822
base_unit< detail::meter_ratio< 0 >, std::ratio< 0 >, std::ratio<-1 >, std::ratio< 1 > > angular_velocity_unit
Represents an SI derived unit of angular velocity.
Definition: base.h:810
base_unit< detail::meter_ratio< 2 >, std::ratio< 1 >, std::ratio<-3 >, std::ratio< 0 >, std::ratio<-2 > > impedance_unit
Represents an SI derived unit of impedance.
Definition: base.h:820
base_unit< detail::meter_ratio< 1 > > length_unit
Represents an SI base unit of length.
Definition: base.h:796
base_unit< detail::meter_ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 1 > > luminous_intensity_unit
Represents an SI base unit of luminous intensity.
Definition: base.h:803
base_unit concentration_unit
Represents a unit of concentration.
Definition: base.h:835
base_unit< detail::meter_ratio< 2 >, std::ratio< 1 >, std::ratio<-2 > > energy_unit
Represents an SI derived unit of energy.
Definition: base.h:816
base_unit< detail::meter_ratio< 3 > > volume_unit
Represents an SI derived unit of volume.
Definition: base.h:833
base_unit< detail::meter_ratio<-2 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 2 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 1 > > illuminance_unit
Represents an SI derived unit of illuminance.
Definition: base.h:826
base_unit dimensionless_unit
Represents a quantity with no dimension.
Definition: base.h:792
base_unit< detail::meter_ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 1 > > data_unit
Represents a unit of data size.
Definition: base.h:836
base_unit< detail::meter_ratio<-1 >, std::ratio< 1 >, std::ratio<-2 > > pressure_unit
Represents an SI derived unit of pressure.
Definition: base.h:814
base_unit< detail::meter_ratio< 1 >, std::ratio< 0 >, std::ratio<-2 > > acceleration_unit
Represents an SI derived unit of acceleration.
Definition: base.h:811
base_unit scalar_unit
Represents a quantity with no dimension.
Definition: base.h:791
base_unit< detail::meter_ratio< 2 >, std::ratio< 1 >, std::ratio<-3 > > power_unit
Represents an SI derived unit of power.
Definition: base.h:817
base_unit< detail::meter_ratio< 0 >, std::ratio< 0 >, std::ratio<-1 > > frequency_unit
Represents an SI derived unit of frequency.
Definition: base.h:808
base_unit< detail::meter_ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 1 > > angle_unit
Represents an SI base unit of angle.
Definition: base.h:799
base_unit< detail::meter_ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 1 > > current_unit
Represents an SI base unit of current.
Definition: base.h:800
base_unit< detail::meter_ratio< 0 >, std::ratio< 0 >, std::ratio< 1 >, std::ratio< 0 >, std::ratio< 1 > > charge_unit
Represents an SI derived unit of charge.
Definition: base.h:815
base_unit< detail::meter_ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 2 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 > > solid_angle_unit
Represents an SI derived unit of solid angle.
Definition: base.h:807
base_unit< detail::meter_ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 1 > > substance_unit
Represents an SI base unit of amount of substance.
Definition: base.h:802
base_unit< detail::meter_ratio< 2 >, std::ratio< 1 >, std::ratio<-3 >, std::ratio< 0 >, std::ratio<-1 > > voltage_unit
Represents an SI derived unit of voltage.
Definition: base.h:818
base_unit< detail::meter_ratio< 0 >, std::ratio< 0 >, std::ratio<-1 > > radioactivity_unit
Represents an SI derived unit of radioactivity.
Definition: base.h:827
base_unit< detail::meter_ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 2 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 1 > > luminous_flux_unit
Represents an SI derived unit of luminous flux.
Definition: base.h:825
base_unit< detail::meter_ratio< 2 >, std::ratio< 1 >, std::ratio<-2 > > torque_unit
Represents an SI derived unit of torque.
Definition: base.h:831
base_unit< detail::meter_ratio< 2 >, std::ratio< 1 >, std::ratio<-2 >, std::ratio< 0 >, std::ratio<-2 > > inductance_unit
Represents an SI derived unit of inductance.
Definition: base.h:824
base_unit< detail::meter_ratio< 1 >, std::ratio< 0 >, std::ratio<-1 > > velocity_unit
Represents an SI derived unit of velocity.
Definition: base.h:809
base_unit< detail::meter_ratio< 1 >, std::ratio< 1 >, std::ratio<-2 > > force_unit
Represents an SI derived unit of force.
Definition: base.h:813
base_unit< detail::meter_ratio< 0 >, std::ratio< 0 >, std::ratio<-2 >, std::ratio< 1 > > angular_acceleration_unit
Represents an SI derived unit of angular acceleration.
Definition: base.h:812
base_unit< detail::meter_ratio< 0 >, std::ratio< 0 >, std::ratio<-1 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 1 > > data_transfer_rate_unit
Represents a unit of data transfer rate.
Definition: base.h:837
base_unit< detail::meter_ratio<-2 >, std::ratio<-1 >, std::ratio< 4 >, std::ratio< 0 >, std::ratio< 2 > > capacitance_unit
Represents an SI derived unit of capacitance.
Definition: base.h:819
base_unit< detail::meter_ratio<-2 >, std::ratio<-1 >, std::ratio< 3 >, std::ratio< 0 >, std::ratio< 2 > > conductance_unit
Represents an SI derived unit of conductance.
Definition: base.h:821
base_unit< detail::meter_ratio< 0 >, std::ratio< 1 >, std::ratio<-2 >, std::ratio< 0 >, std::ratio<-1 > > magnetic_field_strength_unit
Represents an SI derived unit of magnetic field strength.
Definition: base.h:823
base_unit< detail::meter_ratio< 2 > > area_unit
Represents an SI derived unit of area.
Definition: base.h:832
base_unit< detail::meter_ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 1 > > temperature_unit
Represents an SI base unit of temperature.
Definition: base.h:801
static constexpr const unit_t< compound_unit< energy::joules, inverse< temperature::kelvin >, inverse< substance::moles > > > R(8.3144598)
Gas constant.
std::string to_string(const T &t)
Definition: base.h:93
unit_t< scalar, UNIT_LIB_DEFAULT_TYPE, decibel_scale > dB_t
Definition: base.h:2868
unit< std::ratio< 1 >, units::category::dimensionless_unit > dimensionless
Definition: base.h:2511
dB_t dBi_t
Definition: base.h:2869
scalar_t dimensionless_t
Definition: base.h:2514
unit_t< scalar > scalar_t
Definition: base.h:2513
unit< std::ratio< 1 >, units::category::scalar_unit > scalar
Definition: base.h:2510
UnitTypeLhs() max(const UnitTypeLhs &lhs, const UnitTypeRhs &rhs)
Definition: base.h:3417
constexpr auto cpow(const UnitType &value) noexcept -> unit_t< typename units::detail::power_of_unit< power, typename units::traits::unit_t_traits< UnitType >::unit_type >::type, typename units::traits::unit_t_traits< UnitType >::underlying_type, linear_scale >
computes the value of value raised to the power as a constexpr
Definition: base.h:2821
auto pow(const UnitType &value) noexcept -> unit_t< typename units::detail::power_of_unit< power, typename units::traits::unit_t_traits< UnitType >::unit_type >::type, typename units::traits::unit_t_traits< UnitType >::underlying_type, linear_scale >
computes the value of value raised to the power
Definition: base.h:2806
UnitTypeLhs() min(const UnitTypeLhs &lhs, const UnitTypeRhs &rhs)
Definition: base.h:3409
constexpr bool has_decibel_scale_v
Definition: base.h:2439
constexpr bool is_convertible_unit_v
Definition: base.h:1531
constexpr bool has_linear_scale_v
Definition: base.h:2417
constexpr bool is_unit_value_t_category_v
Definition: base.h:3072
constexpr bool is_same_scale_v
Definition: base.h:2463
constexpr bool is_unit_v
Definition: base.h:721
constexpr bool is_unit_t_v
Definition: base.h:1866
typename units::detail::base_unit_of_impl< U >::type base_unit_of
Trait which returns the base_unit type that a unit is originally derived from.
Definition: base.h:932
constexpr bool is_ratio_v
Definition: base.h:593
constexpr bool is_unit_value_t_v
Definition: base.h:3058
Unit Conversion Library namespace.
Definition: current.h:31
unit_t< Units, T, NonLinearScale > & operator*=(unit_t< Units, T, NonLinearScale > &lhs, const RhsType &rhs) noexcept
Definition: base.h:2303
unit_t< Units, T, NonLinearScale > & operator/=(unit_t< Units, T, NonLinearScale > &lhs, const RhsType &rhs) noexcept
Definition: base.h:2313
constexpr bool operator!=(const UNIT_LIB_DEFAULT_TYPE lhs, const Units &rhs) noexcept
Definition: base.h:2716
unit_t< Units, T, NonLinearScale > & operator+=(unit_t< Units, T, NonLinearScale > &lhs, const RhsType &rhs) noexcept
Definition: base.h:2281
constexpr const char * abbreviation(const T &)
constexpr bool operator==(const UNIT_LIB_DEFAULT_TYPE lhs, const Units &rhs) noexcept
Definition: base.h:2702
constexpr dimensionless::scalar_t operator/(const UnitTypeLhs &lhs, const UnitTypeRhs &rhs) noexcept
Division for convertible unit_t types with a linear scale.
Definition: base.h:2644
constexpr const char * name(const T &)
constexpr bool operator<(const UNIT_LIB_DEFAULT_TYPE lhs, const Units &rhs) noexcept
Definition: base.h:2764
unit_t< Units, T, NonLinearScale > & operator++(unit_t< Units, T, NonLinearScale > &u) noexcept
Definition: base.h:2335
unit_t< Units, T, NonLinearScale > & operator-=(unit_t< Units, T, NonLinearScale > &lhs, const RhsType &rhs) noexcept
Definition: base.h:2292
constexpr bool operator<=(const UNIT_LIB_DEFAULT_TYPE lhs, const Units &rhs) noexcept
Definition: base.h:2752
unit_t< Units, T, NonLinearScale > & operator--(unit_t< Units, T, NonLinearScale > &u) noexcept
Definition: base.h:2359
constexpr bool operator>=(const UNIT_LIB_DEFAULT_TYPE lhs, const Units &rhs) noexcept
Definition: base.h:2728
constexpr bool operator>(const UNIT_LIB_DEFAULT_TYPE lhs, const Units &rhs) noexcept
Definition: base.h:2740
constexpr unit_t< Units, T, NonLinearScale > operator-(const unit_t< Units, T, NonLinearScale > &u) noexcept
Definition: base.h:2352
constexpr unit_t< Units, T, NonLinearScale > operator+(const unit_t< Units, T, NonLinearScale > &u) noexcept
Definition: base.h:2328
constexpr auto operator*(const UnitTypeLhs &lhs, const UnitTypeRhs &rhs) noexcept -> unit_t< compound_unit< squared< typename units::traits::unit_t_traits< UnitTypeLhs >::unit_type > > >
Multiplication type for convertible unit_t types with a linear scale.
Definition: base.h:2588
constexpr common_t< T1, T2 > pow(const T1 base, const T2 exp_term) noexcept
Compile-time power function.
Definition: pow.hpp:76
Class representing SI base unit types.
Definition: base.h:758
Kilogram kilogram_ratio
Definition: base.h:770
Radian radian_ratio
Definition: base.h:772
Kelvin kelvin_ratio
Definition: base.h:774
Ampere ampere_ratio
Definition: base.h:773
Byte byte_ratio
Definition: base.h:777
Candela candela_ratio
Definition: base.h:776
Second second_ratio
Definition: base.h:771
Meter meter_ratio
Definition: base.h:769
Mole mole_ratio
Definition: base.h:775
unit_t scale for representing decibel values.
Definition: base.h:2841
decibel_scale & operator=(const decibel_scale &)=default
constexpr decibel_scale(const T value) noexcept
Definition: base.h:2850
constexpr decibel_scale(const T value, std::true_type, Args &&...) noexcept
Definition: base.h:2852
constexpr decibel_scale()=default
T m_value
linearized value
Definition: base.h:2855
constexpr T operator()() const noexcept
Definition: base.h:2853
constexpr decibel_scale(const decibel_scale &)=default
unit_t scale which is linear
Definition: base.h:2487
constexpr T operator()() const noexcept
returns value.
Definition: base.h:2498
UNIT_LIB_DEFAULT_TYPE m_value
linearized value.
Definition: base.h:2500
constexpr linear_scale(const linear_scale &)=default
linear_scale & operator=(const linear_scale &)=default
constexpr linear_scale()=default
default constructor.
constexpr linear_scale(const T &value, Args &&...) noexcept
constructor.
Definition: base.h:2497
Trait which tests whether a type is inherited from a decibel scale.
Definition: base.h:2437
Trait which tests whether a type is inherited from a linear scale.
Definition: base.h:2415
Trait which tests if a class is a base_unit type.
Definition: base.h:693
Trait which tests whether two container types derived from unit_t are convertible to each other.
Definition: base.h:1826
Trait which checks whether two units can be converted to each other.
Definition: base.h:1529
Trait which tests that class T meets the requirements for a non-linear scale.
Definition: base.h:1749
Trait that tests whether a type represents a std::ratio.
Definition: base.h:591
Trait which tests whether two types has the same non-linear scale.
Definition: base.h:2461
Traits which tests if a class is a unit
Definition: base.h:1864
Trait which tests whether type T is a unit_value_t with a unit type in the given category.
Definition: base.h:3068
Trait which tests whether a type is a unit_value_t representing the given unit type.
Definition: base.h:3056
Traits which tests if a class is a unit
Definition: base.h:719
adds two unit_value_t types at compile-time
Definition: base.h:3109
static constexpr const unit_t< unit_type > value() noexcept
Value of sum.
Definition: base.h:3124
divides two unit_value_t types at compile-time
Definition: base.h:3261
static constexpr const unit_t< unit_type > value() noexcept
Value of quotient.
Definition: base.h:3275
multiplies two unit_value_t types at compile-time
Definition: base.h:3211
static constexpr const unit_t< unit_type > value() noexcept
Value of product.
Definition: base.h:3225
raises unit_value_to a power at compile-time
Definition: base.h:3307
static constexpr const unit_t< unit_type > value() noexcept
Value of exponentiation.
Definition: base.h:3322
calculates square root of unit_value_t at compile-time
Definition: base.h:3354
static constexpr const unit_t< unit_type > value() noexcept
Value of square root.
Definition: base.h:3369
subtracts two unit_value_t types at compile-time
Definition: base.h:3158
static constexpr const unit_t< unit_type > value() noexcept
Value of difference.
Definition: base.h:3174
Stores a rational unit value as a compile-time constant.
Definition: base.h:3035
Units unit_type
Definition: base.h:3036
std::ratio< Num, Denom > ratio
Definition: base.h:3037
static constexpr const unit_t< Units > value()
Definition: base.h:3040
Type representing an arbitrary unit.
Definition: base.h:884
std::ratio_add< std::ratio_multiply< typename BaseUnit::conversion_ratio, Translation >, typename BaseUnit::translation_ratio > translation_ratio
Definition: base.h:892
std::ratio_multiply< typename BaseUnit::conversion_ratio, Conversion > conversion_ratio
Definition: base.h:890
units::traits::unit_traits< BaseUnit >::base_unit_type base_unit_type
Definition: base.h:889
std::ratio_add< typename BaseUnit::pi_exponent_ratio, PiExponent > pi_exponent_ratio
Definition: base.h:891
auto format(wformat_string< T... > fmt, T &&... args) -> std::wstring
Definition: xchar.h:87
auto format_to(OutputIt out, const S &fmt, Args &&... args) -> OutputIt
Definition: xchar.h:136