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 __has_include(<fmt/format.h>) && !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 __has_include(<fmt/format.h>) && !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>)
528 static constexpr const UNIT_LIB_DEFAULT_TYPE PI_VAL = 3.14159265358979323846264338327950288419716939937510;
550 static constexpr auto test(U*)->std::is_integral<
decltype(U::num)> {
return std::is_integral<
decltype(U::num)>{}; }
552 static constexpr std::false_type test(...) {
return std::false_type{}; }
554 using type =
decltype(test<T>(0));
564 struct has_num : units::detail::has_num_impl<T>
::type {};
573 static constexpr auto test(U*)->std::is_integral<
decltype(U::den)> {
return std::is_integral<
decltype(U::den)>{}; }
575 static constexpr std::false_type test(...) {
return std::false_type{}; }
577 using type =
decltype(test<T>(0));
587 struct has_den : units::detail::has_den_impl<T>
::type {};
622 template<
bool...>
struct bool_pack {};
627 template<
bool... Args>
628 struct all_true : std::is_same<units::bool_pack<true, Args...>, units::bool_pack<Args..., true>> {};
629 template<
bool... Args>
630 inline constexpr bool all_true_t_v = all_true<Args...>::type::value;
638#ifdef FOR_DOXYGEN_PURPOSES_ONLY
649 typedef typename T::base_unit_type base_unit_type;
650 typedef typename T::conversion_ratio conversion_ratio;
651 typedef typename T::pi_exponent_ratio pi_exponent_ratio;
652 typedef typename T::translation_ratio translation_ratio;
659 template<
class T,
typename =
void>
662 typedef void base_unit_type;
663 typedef void conversion_ratio;
664 typedef void pi_exponent_ratio;
665 typedef void translation_ratio;
671 typename T::base_unit_type,
672 typename T::conversion_ratio,
673 typename T::pi_exponent_ratio,
674 typename T::translation_ratio>
::type>
676 typedef typename T::base_unit_type base_unit_type;
677 typedef typename T::conversion_ratio conversion_ratio;
678 typedef typename T::pi_exponent_ratio pi_exponent_ratio;
679 typedef typename T::translation_ratio translation_ratio;
691 struct _base_unit_t {};
704 struct is_base_unit : std::is_base_of<units::detail::_base_unit_t, T> {};
716 template<std::
intmax_t Num, std::
intmax_t Den = 1>
717 using meter_ratio = std::ratio<Num, Den>;
759 template<
class Meter = detail::meter_ratio<0>,
760 class Kilogram = std::ratio<0>,
761 class Second = std::ratio<0>,
762 class Radian = std::ratio<0>,
763 class Ampere = std::ratio<0>,
764 class Kelvin = std::ratio<0>,
765 class Mole = std::ratio<0>,
766 class Candela = std::ratio<0>,
767 class Byte = std::ratio<0>>
770 static_assert(
traits::is_ratio<Meter>::value,
"Template parameter `Meter` must be a `std::ratio` representing the exponent of meters the unit has");
772 static_assert(
traits::is_ratio<Second>::value,
"Template parameter `Second` must be a `std::ratio` representing the exponent of seconds the unit has");
773 static_assert(
traits::is_ratio<Ampere>::value,
"Template parameter `Ampere` must be a `std::ratio` representing the exponent of amperes the unit has");
776 static_assert(
traits::is_ratio<Mole>::value,
"Template parameter `Mole` must be a `std::ratio` representing the exponent of moles the unit has");
777 static_assert(
traits::is_ratio<Radian>::value,
"Template parameter `Radian` must be a `std::ratio` representing the exponent of radians the unit has");
778 static_assert(
traits::is_ratio<Byte>::value,
"Template parameter `Byte` must be a `std::ratio` representing the exponent of bytes the unit has");
837 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;
859 template <
class,
class,
class,
class>
struct unit;
860 template<
class Conversion,
class... Exponents,
class PiExponent,
class Translation>
861 struct unit<Conversion,
base_unit<Exponents...>, PiExponent, Translation> : units::detail::_unit
865 static_assert(
traits::is_ratio<Translation>::value,
"Template parameter `Translation` must be a `std::ratio` representing an additive translation required by the unit conversion.");
893 template<
class Conversion,
class BaseUnit,
class PiExponent = std::ratio<0>,
class Translation = std::ratio<0>>
894 struct unit : units::detail::_unit
900 typedef typename units::traits::unit_traits<BaseUnit>::base_unit_type
base_unit_type;
901 typedef typename std::ratio_multiply<typename BaseUnit::conversion_ratio, Conversion>
conversion_ratio;
902 typedef typename std::ratio_add<typename BaseUnit::pi_exponent_ratio, PiExponent>
pi_exponent_ratio;
903 typedef typename std::ratio_add<std::ratio_multiply<typename BaseUnit::conversion_ratio, Translation>,
typename BaseUnit::translation_ratio>
translation_ratio;
918 template<
class>
struct base_unit_of_impl;
919 template<
class Conversion,
class BaseUnit,
class PiExponent,
class Translation>
920 struct base_unit_of_impl<
unit<Conversion, BaseUnit, PiExponent, Translation>> : base_unit_of_impl<BaseUnit> {};
921 template<
class... Exponents>
922 struct base_unit_of_impl<base_unit<Exponents...>>
924 typedef base_unit<Exponents...>
type;
927 struct base_unit_of_impl<void>
954 template<
class,
class>
struct base_unit_multiply_impl;
955 template<
class... Exponents1,
class... Exponents2>
963 template<
class U1,
class U2>
971 template<
class,
class>
struct base_unit_divide_impl;
972 template<
class... Exponents1,
class... Exponents2>
973 struct base_unit_divide_impl<base_unit<Exponents1...>, base_unit<Exponents2...>> {
974 using type = base_unit<std::ratio_subtract<Exponents1, Exponents2>...>;
980 template<
class U1,
class U2>
988 template<
class>
struct inverse_base_impl;
990 template<
class... Exponents>
991 struct inverse_base_impl<base_unit<Exponents...>> {
992 using type = base_unit<std::ratio_multiply<Exponents, std::ratio<-1>>...>;
1006 template<
class U>
struct squared_base_impl;
1007 template<
class... Exponents>
1008 struct squared_base_impl<base_unit<Exponents...>> {
1009 using type = base_unit<std::ratio_multiply<Exponents, std::ratio<2>>...>;
1023 template<
class U>
struct cubed_base_impl;
1024 template<
class... Exponents>
1025 struct cubed_base_impl<base_unit<Exponents...>> {
1026 using type = base_unit<std::ratio_multiply<Exponents, std::ratio<3>>...>;
1040 template<
class U>
struct sqrt_base_impl;
1041 template<
class... Exponents>
1042 struct sqrt_base_impl<base_unit<Exponents...>> {
1043 using type = base_unit<std::ratio_divide<Exponents, std::ratio<2>>...>;
1057 template<
class U>
struct cbrt_base_impl;
1058 template<
class... Exponents>
1059 struct cbrt_base_impl<base_unit<Exponents...>> {
1060 using type = base_unit<std::ratio_divide<Exponents, std::ratio<3>>...>;
1084 template<
class Unit1,
class Unit2>
1085 struct unit_multiply_impl
1087 using type = unit < std::ratio_multiply<typename Unit1::conversion_ratio, typename Unit2::conversion_ratio>,
1088 base_unit_multiply <traits::base_unit_of<typename Unit1::base_unit_type>, traits::base_unit_of<typename Unit2::base_unit_type>>,
1089 std::ratio_add<typename Unit1::pi_exponent_ratio, typename Unit2::pi_exponent_ratio>,
1097 template<
class U1,
class U2>
1106 template<
class Unit1,
class Unit2>
1107 struct unit_divide_impl
1109 using type = unit < std::ratio_divide<typename Unit1::conversion_ratio, typename Unit2::conversion_ratio>,
1110 base_unit_divide<traits::base_unit_of<typename Unit1::base_unit_type>, traits::base_unit_of<typename Unit2::base_unit_type>>,
1111 std::ratio_subtract<typename Unit1::pi_exponent_ratio, typename Unit2::pi_exponent_ratio>,
1119 template<
class U1,
class U2>
1128 template<
class Unit>
1131 using type = unit < std::ratio<Unit::conversion_ratio::den, Unit::conversion_ratio::num>,
1132 inverse_base<traits::base_unit_of<typename units::traits::unit_traits<Unit>::base_unit_type>>,
1133 std::ratio_multiply<typename units::traits::unit_traits<Unit>::pi_exponent_ratio, std::ratio<-1>>,
1155 template<
class Unit>
1159 using Conversion =
typename Unit::conversion_ratio;
1161 squared_base<traits::base_unit_of<typename Unit::base_unit_type>>,
1162 std::ratio_multiply<typename Unit::pi_exponent_ratio, std::ratio<2>>,
1163 typename Unit::translation_ratio
1186 template<
class Unit>
1190 using Conversion =
typename Unit::conversion_ratio;
1192 cubed_base<traits::base_unit_of<typename Unit::base_unit_type>>,
1193 std::ratio_multiply<typename Unit::pi_exponent_ratio, std::ratio<3>>,
1194 typename Unit::translation_ratio> ;
1215 using Zero = std::ratio<0>;
1216 using One = std::ratio<1>;
1217 template <
typename R>
using Square = std::ratio_multiply<R, R>;
1220 template <
template <std::
intmax_t N>
class Predicate,
typename enabled =
void>
1221 struct BinarySearch {
1222 template <std::
intmax_t N>
1223 struct SafeDouble_ {
1224 static constexpr const std::intmax_t
value = 2 * N;
1225 static_assert(
value > 0,
"Overflows when computing 2 * N");
1228 template <
intmax_t Lower,
intmax_t Upper,
typename Condition1 =
void,
typename Condition2 =
void>
1229 struct DoubleSidedSearch_ : DoubleSidedSearch_<Lower, Upper,
1230 std::integral_constant<bool, (Upper - Lower == 1)>,
1231 std::integral_constant<bool, ((Upper - Lower>1 && Predicate<Lower + (Upper - Lower) / 2>::value))>> {};
1233 template <
intmax_t Lower,
intmax_t Upper>
1234 struct DoubleSidedSearch_<
Lower,
Upper,
std::false_type, std::false_type> : DoubleSidedSearch_<Lower, Lower + (Upper - Lower) / 2> {};
1236 template <
intmax_t Lower,
intmax_t Upper,
typename Condition2>
1237 struct DoubleSidedSearch_<
Lower,
Upper,
std::true_type, Condition2> : std::integral_constant<intmax_t, Lower>{};
1239 template <
intmax_t Lower,
intmax_t Upper,
typename Condition1>
1240 struct DoubleSidedSearch_<
Lower,
Upper, Condition1,
std::true_type> : DoubleSidedSearch_<Lower + (Upper - Lower) / 2, Upper>{};
1242 template <std::
intmax_t Lower,
class enabled1 =
void>
1243 struct SingleSidedSearch_ : SingleSidedSearch_<Lower, std::integral_constant<bool, Predicate<SafeDouble_<Lower>::value>::value>>{};
1245 template <std::
intmax_t Lower>
1246 struct SingleSidedSearch_<
Lower,
std::false_type> : DoubleSidedSearch_<Lower, SafeDouble_<Lower>::value> {};
1248 template <std::
intmax_t Lower>
1249 struct SingleSidedSearch_<
Lower,
std::true_type> : SingleSidedSearch_<SafeDouble_<Lower>::value>{};
1251 static constexpr const std::intmax_t
value = SingleSidedSearch_<1>::value;
1254 template <
template <std::
intmax_t N>
class Predicate>
1255 struct BinarySearch<Predicate,
std::
enable_if_t<!Predicate<1>::value>> : std::integral_constant<std::intmax_t, 0>{};
1258 template <
typename R>
1260 template <std::
intmax_t N>
using Predicate_ = std::ratio_less_equal<std::ratio<N>, std::ratio_divide<R, std::ratio<N>>>;
1261 static constexpr const std::intmax_t
value = BinarySearch<Predicate_>::value;
1264 template <
typename R>
1265 struct IsPerfectSquare {
1266 static constexpr const std::intmax_t DenSqrt_ = Integer<std::ratio<R::den>>
::value;
1267 static constexpr const std::intmax_t NumSqrt_ = Integer<std::ratio<R::num>>
::value;
1268 static constexpr const bool value =( DenSqrt_ * DenSqrt_ == R::den && NumSqrt_ * NumSqrt_ == R::num);
1269 using Sqrt = std::ratio<NumSqrt_, DenSqrt_>;
1273 template <
typename Tp,
typename Tq>
1280 template <
typename R>
1282 using P_ =
typename R::P;
1283 using Q_ =
typename R::Q;
1284 using Den_ = std::ratio_subtract<P_, Square<Q_>>;
1285 using A_ = std::ratio_divide<Q_, Den_>;
1286 using B_ = std::ratio_divide<P_, Square<Den_>>;
1287 static constexpr const std::intmax_t I_ = (A_::num + Integer<std::ratio_multiply<B_, Square<std::ratio<A_::den>>>>
::value) / A_::den;
1288 using I = std::ratio<I_>;
1289 using Rem = Remainder<B_, std::ratio_subtract<I, A_>>;
1296 template <
typename Tr, std::
intmax_t N>
1297 struct ContinuedFraction {
1298 template <
typename T>
1299 using Abs_ = std::conditional_t<std::ratio_less<T, Zero>::value, std::ratio_subtract<Zero, T>, T>;
1302 using Last_ = ContinuedFraction<
R, N - 1>;
1303 using Reciprocal_ = Reciprocal<typename Last_::Rem>;
1304 using Rem =
typename Reciprocal_::Rem;
1305 using I_ =
typename Reciprocal_::I;
1306 using Den_ = std::ratio_add<typename Last_::W, I_>;
1307 using U = std::ratio_divide<typename Last_::V, Den_>;
1308 using V = std::ratio_divide<std::ratio_add<typename Last_::U, std::ratio_multiply<typename Last_::V, I_>>, Den_>;
1309 using W = std::ratio_divide<One, Den_>;
1310 using Error = Abs_<std::ratio_divide<std::ratio_subtract<U, std::ratio_multiply<V, W>>,
typename Reciprocal<Rem>::I>>;
1313 template <
typename Tr>
1314 struct ContinuedFraction<Tr, 1> {
1317 using V = std::ratio<Integer<R>::value>;
1319 using Rem = Remainder<R, V>;
1320 using Error = std::ratio_divide<One, typename Reciprocal<Rem>::I>;
1323 template <
typename R,
typename Eps, std::
intmax_t N = 1,
typename enabled =
void>
1324 struct Sqrt_ : Sqrt_<R, Eps, N + 1> {};
1326 template <
typename R,
typename Eps, std::
intmax_t N>
1327 struct Sqrt_<
R, Eps, N,
std::
enable_if_t<std::ratio_less_equal<typename ContinuedFraction<R, N>::Error, Eps>::value>> {
1328 using type =
typename ContinuedFraction<R, N>::V;
1331 template <
typename R,
typename Eps,
typename enabled =
void>
1333 static_assert(std::ratio_greater_equal<R, Zero>::value,
"R can't be negative");
1336 template <
typename R,
typename Eps>
1337 struct Sqrt<
R, Eps,
std::
enable_if_t<std::ratio_greater_equal<R, Zero>::value && IsPerfectSquare<R>::value>> {
1338 using type =
typename IsPerfectSquare<R>::Sqrt;
1341 template <
typename R,
typename Eps>
1342 struct Sqrt<
R, Eps,
std::
enable_if_t<(std::ratio_greater_equal<R, Zero>::value && !IsPerfectSquare<R>::value)>> : Sqrt_<R, Eps>{};
1366 template<
typename Ratio, std::
intmax_t Eps = 10000000000>
1377 template<
class Unit, std::
intmax_t Eps>
1381 using Conversion =
typename Unit::conversion_ratio;
1383 sqrt_base<traits::base_unit_of<typename Unit::base_unit_type>>,
1384 std::ratio_divide<typename Unit::pi_exponent_ratio, std::ratio<2>>,
1385 typename Unit::translation_ratio>;
1411 template<
class U, std::
intmax_t Eps = 10000000000>
1426 template<
class U,
class... Us>
struct compound_impl;
1427 template<
class U>
struct compound_impl<U> {
using type = U; };
1428 template<
class U1,
class U2,
class...Us>
1429 struct compound_impl<U1, U2, Us...>
1430 : compound_impl<unit_multiply<U1, U2>, Us...> {};
1444 template<
class U,
class... Us>
1458 template<
class Ratio,
class Unit>
1467 template <
int N,
class U>
1468 struct power_of_ratio
1470 typedef std::ratio_multiply<U,
typename power_of_ratio<N - 1, U>
::type>
type;
1475 struct power_of_ratio<1, U>
1512 template<
class U>
using kibi =
typename units::detail::prefix<std::ratio<1024>, U>
::type;
1513 template<
class U>
using mebi =
typename units::detail::prefix<std::ratio<1048576>, U>
::type;
1514 template<
class U>
using gibi =
typename units::detail::prefix<std::ratio<1073741824>, U>
::type;
1515 template<
class U>
using tebi =
typename units::detail::prefix<std::ratio<1099511627776>, U>
::type;
1516 template<
class U>
using pebi =
typename units::detail::prefix<std::ratio<1125899906842624>, U>
::type;
1517 template<
class U>
using exbi =
typename units::detail::prefix<std::ratio<1152921504606846976>, U>
::type;
1538 template<
class U1,
class U2>
1539 struct is_convertible_unit : std::is_same <traits::base_unit_of<typename units::traits::unit_traits<U1>::base_unit_type>,
1540 base_unit_of<typename units::traits::unit_traits<U2>::base_unit_type >> {};
1541 template<
class U1,
class U2>
1554 return y == 0 ? 1.0 : x *
pow(x,
y - 1);
1559 return x < 0 ? -x : x;
1563 template<
class UnitFrom,
class UnitTo,
class Ratio,
class PiRatio,
class Translation,
typename T>
1564 static inline constexpr T
convert(
const T&
value, std::true_type, std::false_type, std::false_type)
noexcept
1570 template<
class UnitFrom,
class UnitTo,
class Ratio,
class PiRatio,
class Translation,
typename T>
1571 static inline constexpr T
convert(
const T&
value, std::true_type, std::false_type, std::true_type)
noexcept
1577 template<
class UnitFrom,
class UnitTo,
class Ratio,
class PiRatio,
class Translation,
typename T>
1578 static inline constexpr T
convert(
const T&
value, std::true_type, std::true_type, std::false_type)
noexcept
1584 template<
class UnitFrom,
class UnitTo,
class Ratio,
class PiRatio,
class Translation,
typename T>
1585 static inline constexpr T
convert(
const T&
value, std::true_type, std::true_type, std::true_type)
noexcept
1591 template<
class UnitFrom,
class UnitTo,
class Ratio,
class PiRatio,
class Translation,
typename T>
1592 static inline constexpr T
convert(
const T&
value, std::false_type, std::false_type, std::false_type)
noexcept
1594 return ((
value * Ratio::num) / Ratio::den);
1599 template<
class UnitFrom,
class UnitTo,
class Ratio,
class PiRatio,
class Translation,
typename T>
1600 static inline constexpr
1601 std::enable_if_t<(PiRatio::num / PiRatio::den >= 1 && PiRatio::num % PiRatio::den == 0), T>
1602 convert(
const T&
value, std::false_type, std::true_type, std::false_type)
noexcept
1604 return ((
value *
pow(constants::detail::PI_VAL, PiRatio::num / PiRatio::den) * Ratio::num) / Ratio::den);
1609 template<
class UnitFrom,
class UnitTo,
class Ratio,
class PiRatio,
class Translation,
typename T>
1610 static inline constexpr
1611 std::enable_if_t<(PiRatio::num / PiRatio::den <= -1 && PiRatio::num % PiRatio::den == 0), T>
1612 convert(
const T&
value, std::false_type, std::true_type, std::false_type)
noexcept
1614 return (
value * Ratio::num) / (Ratio::den *
pow(constants::detail::PI_VAL, -PiRatio::num / PiRatio::den));
1619 template<
class UnitFrom,
class UnitTo,
class Ratio,
class PiRatio,
class Translation,
typename T>
1621 std::enable_if_t<(PiRatio::num / PiRatio::den < 1 && PiRatio::num / PiRatio::den > -1), T>
1622 convert(
const T&
value, std::false_type, std::true_type, std::false_type)
noexcept
1624 return ((
value *
std::pow(constants::detail::PI_VAL, PiRatio::num / PiRatio::den) * Ratio::num) / Ratio::den);
1628 template<
class UnitFrom,
class UnitTo,
class Ratio,
class PiRatio,
class Translation,
typename T>
1629 static inline constexpr T
convert(
const T&
value, std::false_type, std::false_type, std::true_type)
noexcept
1635 template<
class UnitFrom,
class UnitTo,
class Ratio,
class PiRatio,
class Translation,
typename T>
1636 static inline constexpr T
convert(
const T&
value,
const std::false_type,
const std::true_type,
const std::true_type)
noexcept
1638 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);
1658 template<
class UnitFrom,
class UnitTo,
typename T = UNIT_LIB_DEFAULT_TYPE>
1665 using Ratio = std::ratio_divide<typename UnitFrom::conversion_ratio, typename UnitTo::conversion_ratio>;
1666 using PiRatio = std::ratio_subtract<typename UnitFrom::pi_exponent_ratio, typename UnitTo::pi_exponent_ratio>;
1667 using Translation = std::ratio_divide<std::ratio_subtract<typename UnitFrom::translation_ratio, typename UnitTo::translation_ratio>,
typename UnitTo::conversion_ratio>;
1669 using isSame =
typename std::is_same<std::decay_t<UnitFrom>, std::decay_t<UnitTo>>
::type;
1670 using piRequired = std::integral_constant<bool, !(std::is_same<std::ratio<0>, PiRatio>
::value)>;
1671 using translationRequired = std::integral_constant<bool, !(std::is_same<std::ratio<0>, Translation>
::value)>;
1673 return units::detail::convert<UnitFrom, UnitTo, Ratio, PiRatio, Translation, T>
1674 (
value, isSame{}, piRequired{}, translationRequired{});
1690 template<
class T,
class Ret>
1691 struct has_operator_parenthesis_impl
1694 static constexpr auto test(U*) ->
decltype(std::declval<U>()()) {
return decltype(std::declval<U>()()){}; }
1696 static constexpr std::false_type test(...) {
return std::false_type{}; }
1698 using type =
typename std::is_same<Ret, decltype(test<T>(0))>
::type;
1706 template<
class T,
class Ret>
1707 struct has_operator_parenthesis : traits::detail::has_operator_parenthesis_impl<T, Ret>
::type {};
1718 template<
class T,
class Ret>
1719 struct has_value_member_impl
1722 static constexpr auto test(U* p) ->
decltype(p->m_value) {
return p->m_value; }
1724 static constexpr auto test(...)->std::false_type {
return std::false_type{}; }
1726 using type =
typename std::is_same<std::decay_t<Ret>, std::decay_t<decltype(test<T>(0))>>
::type;
1734 template<
class T,
class Ret>
1735 struct has_value_member : traits::detail::has_value_member_impl<T, Ret>
::type {};
1736 template<
class T,
class Ret>
1737 inline constexpr bool has_value_member_v = has_value_member<T, Ret>::value;
1754 template<
class T,
class Ret>
1756 std::is_default_constructible<T>::value &&
1757 has_operator_parenthesis<T, Ret>::value &&
1758 has_value_member<T, Ret>::value &&
1759 std::is_trivial<T>::value>
1769#ifdef FOR_DOXYGEN_PURPOSOES_ONLY
1776 template<
typename T>
1777 struct unit_t_traits
1779 typedef typename T::non_linear_scale_type non_linear_scale_type;
1780 typedef typename T::underlying_type underlying_type;
1781 typedef typename T::value_type value_type;
1782 typedef typename T::unit_type unit_type;
1791 template<
typename T,
typename =
void>
1792 struct unit_t_traits
1794 typedef void non_linear_scale_type;
1795 typedef void underlying_type;
1796 typedef void value_type;
1797 typedef void unit_type;
1805 template<
typename T>
1806 struct unit_t_traits <T, typename
void_t<
1807 typename T::non_linear_scale_type,
1808 typename T::underlying_type,
1809 typename T::value_type,
1810 typename T::unit_type>
::type>
1812 typedef typename T::non_linear_scale_type non_linear_scale_type;
1813 typedef typename T::underlying_type underlying_type;
1814 typedef typename T::value_type value_type;
1815 typedef typename T::unit_type unit_type;
1834 template<
class U1,
class U2>
1836 is_convertible_unit<typename units::traits::unit_t_traits<U1>::unit_type, typename units::traits::unit_t_traits<U2>::unit_type>::value>
1862 #if !defined(_MSC_VER) || _MSC_VER > 1800
1935 template<
class Units,
typename T = UNIT_LIB_DEFAULT_TYPE,
template<
typename>
class NonLinearScale =
linear_scale>
1936 class unit_t :
public NonLinearScale<T>, units::detail::_unit_t
1938 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).");
1943 using nls = NonLinearScale<T>;
1967 template<
class... Args>
1978 template<class Ty, class = typename std::enable_if<traits::is_dimensionless_unit<Units>::value && std::is_arithmetic<Ty>::value>
::type>
1990 inline constexpr unit_t(
const std::chrono::duration<Rep, Period>&
value) noexcept :
2001 template<
class UnitsRhs,
typename Ty,
template<
typename>
class NlsRhs>
2003 nls(units::convert<UnitsRhs, Units, T>(rhs.m_value), std::true_type() )
2013 template<
class UnitsRhs,
typename Ty,
template<
typename>
class NlsRhs>
2016 nls::m_value = units::convert<UnitsRhs, Units, T>(rhs.m_value);
2025 template<class Ty, class = std::enable_if_t<traits::is_dimensionless_unit<Units>::value && std::is_arithmetic<Ty>::value>>
2038 template<
class UnitsRhs,
typename Ty,
template<
typename>
class NlsRhs>
2041 return (nls::m_value < units::convert<UnitsRhs, Units>(rhs.m_value));
2050 template<
class UnitsRhs,
typename Ty,
template<
typename>
class NlsRhs>
2053 return (nls::m_value <= units::convert<UnitsRhs, Units>(rhs.m_value));
2062 template<
class UnitsRhs,
typename Ty,
template<
typename>
class NlsRhs>
2065 return (nls::m_value > units::convert<UnitsRhs, Units>(rhs.m_value));
2074 template<
class UnitsRhs,
typename Ty,
template<
typename>
class NlsRhs>
2077 return (nls::m_value >= units::convert<UnitsRhs, Units>(rhs.m_value));
2087 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>
2090 return detail::abs(nls::m_value - units::convert<UnitsRhs, Units>(rhs.m_value)) < std::numeric_limits<T>::epsilon() *
2091 detail::abs(nls::m_value + units::convert<UnitsRhs, Units>(rhs.m_value)) ||
2095 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>
2098 return nls::m_value == units::convert<UnitsRhs, Units>(rhs.m_value);
2108 template<
class UnitsRhs,
typename Ty,
template<
typename>
class NlsRhs>
2111 return !(*
this == rhs);
2127 template<typename Ty, class = std::enable_if_t<std::is_arithmetic<Ty>::value>>
2128 inline constexpr Ty
to() const noexcept
2130 return static_cast<Ty
>(*this);
2138 template<typename Ty, class = std::enable_if_t<std::is_arithmetic<Ty>::value>>
2141 return static_cast<Ty
>(
m_value);
2164 template<class Ty, std::enable_if_t<traits::is_dimensionless_unit<Units>::value && std::is_arithmetic<Ty>::value,
int> = 0>
2165 inline constexpr operator Ty() const noexcept
2175 template<class Ty, std::enable_if_t<!traits::is_dimensionless_unit<Units>::value && std::is_arithmetic<Ty>::value,
int> = 0>
2176 inline constexpr explicit operator Ty() const noexcept
2178 return static_cast<Ty
>((*this)());
2185 template<
typename U = Units, std::enable_if_t<units::traits::is_convertible_unit<U, unit<std::ratio<1>, category::time_unit>>::value,
int> = 0>
2186 inline constexpr operator std::chrono::nanoseconds() const noexcept
2188 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)())));
2194 inline constexpr const char*
name() const noexcept
2209 template<
class U,
typename Ty,
template<
typename>
class Nlt>
2227 template<class UnitType, typename T, class = std::enable_if_t<std::is_arithmetic<T>::value>>
2232 return UnitType(
value);
2235#if defined(UNIT_LIB_ENABLE_IOSTREAM)
2236 template<
class Units,
typename T,
template<
typename>
class NonLinearScale>
2237 inline std::ostream&
operator<<(std::ostream& os,
const unit_t<Units, T, NonLinearScale>& obj)
noexcept
2239 using BaseUnits = unit<std::ratio<1>,
typename traits::unit_traits<Units>::base_unit_type>;
2240 os << convert<Units, BaseUnits>(obj());
2242 if (traits::unit_traits<Units>::base_unit_type::meter_ratio::num != 0) { os <<
" m"; }
2243 if (traits::unit_traits<Units>::base_unit_type::meter_ratio::num != 0 &&
2244 traits::unit_traits<Units>::base_unit_type::meter_ratio::num != 1) { os <<
"^" << traits::unit_traits<Units>::base_unit_type::meter_ratio::num; }
2245 if (traits::unit_traits<Units>::base_unit_type::meter_ratio::den != 1) { os <<
"/" << traits::unit_traits<Units>::base_unit_type::meter_ratio::den; }
2247 if (traits::unit_traits<Units>::base_unit_type::kilogram_ratio::num != 0) { os <<
" kg"; }
2248 if (traits::unit_traits<Units>::base_unit_type::kilogram_ratio::num != 0 &&
2249 traits::unit_traits<Units>::base_unit_type::kilogram_ratio::num != 1) { os <<
"^" << traits::unit_traits<Units>::base_unit_type::kilogram_ratio::num; }
2250 if (traits::unit_traits<Units>::base_unit_type::kilogram_ratio::den != 1) { os <<
"/" << traits::unit_traits<Units>::base_unit_type::kilogram_ratio::den; }
2252 if (traits::unit_traits<Units>::base_unit_type::second_ratio::num != 0) { os <<
" s"; }
2253 if (traits::unit_traits<Units>::base_unit_type::second_ratio::num != 0 &&
2254 traits::unit_traits<Units>::base_unit_type::second_ratio::num != 1) { os <<
"^" << traits::unit_traits<Units>::base_unit_type::second_ratio::num; }
2255 if (traits::unit_traits<Units>::base_unit_type::second_ratio::den != 1) { os <<
"/" << traits::unit_traits<Units>::base_unit_type::second_ratio::den; }
2257 if (traits::unit_traits<Units>::base_unit_type::ampere_ratio::num != 0) { os <<
" A"; }
2258 if (traits::unit_traits<Units>::base_unit_type::ampere_ratio::num != 0 &&
2259 traits::unit_traits<Units>::base_unit_type::ampere_ratio::num != 1) { os <<
"^" << traits::unit_traits<Units>::base_unit_type::ampere_ratio::num; }
2260 if (traits::unit_traits<Units>::base_unit_type::ampere_ratio::den != 1) { os <<
"/" << traits::unit_traits<Units>::base_unit_type::ampere_ratio::den; }
2262 if (traits::unit_traits<Units>::base_unit_type::kelvin_ratio::num != 0) { os <<
" K"; }
2263 if (traits::unit_traits<Units>::base_unit_type::kelvin_ratio::num != 0 &&
2264 traits::unit_traits<Units>::base_unit_type::kelvin_ratio::num != 1) { os <<
"^" << traits::unit_traits<Units>::base_unit_type::kelvin_ratio::num; }
2265 if (traits::unit_traits<Units>::base_unit_type::kelvin_ratio::den != 1) { os <<
"/" << traits::unit_traits<Units>::base_unit_type::kelvin_ratio::den; }
2267 if (traits::unit_traits<Units>::base_unit_type::mole_ratio::num != 0) { os <<
" mol"; }
2268 if (traits::unit_traits<Units>::base_unit_type::mole_ratio::num != 0 &&
2269 traits::unit_traits<Units>::base_unit_type::mole_ratio::num != 1) { os <<
"^" << traits::unit_traits<Units>::base_unit_type::mole_ratio::num; }
2270 if (traits::unit_traits<Units>::base_unit_type::mole_ratio::den != 1) { os <<
"/" << traits::unit_traits<Units>::base_unit_type::mole_ratio::den; }
2272 if (traits::unit_traits<Units>::base_unit_type::candela_ratio::num != 0) { os <<
" cd"; }
2273 if (traits::unit_traits<Units>::base_unit_type::candela_ratio::num != 0 &&
2274 traits::unit_traits<Units>::base_unit_type::candela_ratio::num != 1) { os <<
"^" << traits::unit_traits<Units>::base_unit_type::candela_ratio::num; }
2275 if (traits::unit_traits<Units>::base_unit_type::candela_ratio::den != 1) { os <<
"/" << traits::unit_traits<Units>::base_unit_type::candela_ratio::den; }
2277 if (traits::unit_traits<Units>::base_unit_type::radian_ratio::num != 0) { os <<
" rad"; }
2278 if (traits::unit_traits<Units>::base_unit_type::radian_ratio::num != 0 &&
2279 traits::unit_traits<Units>::base_unit_type::radian_ratio::num != 1) { os <<
"^" << traits::unit_traits<Units>::base_unit_type::radian_ratio::num; }
2280 if (traits::unit_traits<Units>::base_unit_type::radian_ratio::den != 1) { os <<
"/" << traits::unit_traits<Units>::base_unit_type::radian_ratio::den; }
2282 if (traits::unit_traits<Units>::base_unit_type::byte_ratio::num != 0) { os <<
" b"; }
2283 if (traits::unit_traits<Units>::base_unit_type::byte_ratio::num != 0 &&
2284 traits::unit_traits<Units>::base_unit_type::byte_ratio::num != 1) { os <<
"^" << traits::unit_traits<Units>::base_unit_type::byte_ratio::num; }
2285 if (traits::unit_traits<Units>::base_unit_type::byte_ratio::den != 1) { os <<
"/" << traits::unit_traits<Units>::base_unit_type::byte_ratio::den; }
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>
2307 "parameters are not compatible units.");
2313 template<
class Units,
typename T,
template<
typename>
class NonLinearScale,
typename RhsType>
2317 "right-hand side parameter must be dimensionless.");
2323 template<
class Units,
typename T,
template<
typename>
class NonLinearScale,
typename RhsType>
2327 "right-hand side parameter must be dimensionless.");
2338 template<
class Units,
typename T,
template<
typename>
class NonLinearScale>
2345 template<
class Units,
typename T,
template<
typename>
class NonLinearScale>
2353 template<
class Units,
typename T,
template<
typename>
class NonLinearScale>
2362 template<
class Units,
typename T,
template<
typename>
class NonLinearScale>
2369 template<
class Units,
typename T,
template<
typename>
class NonLinearScale>
2377 template<
class Units,
typename T,
template<
typename>
class NonLinearScale>
2402 template<typename T, typename Units, class = std::enable_if_t<std::is_arithmetic<T>::value && traits::is_unit_t<Units>::value>>
2405 return static_cast<T
>(
value);
2413 template<
typename T>
struct decibel_scale;
2424#if !defined(_MSC_VER) || _MSC_VER > 1800
2425 template<
typename... T>
2426 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 > {};
2427 template<
typename... T>
2430 template<
typename T1,
typename T2 = T1,
typename T3 = T1>
2432 std::is_base_of<units::linear_scale<typename units::traits::unit_t_traits<T1>::underlying_type>, T1>::value &&
2433 std::is_base_of<units::linear_scale<typename units::traits::unit_t_traits<T2>::underlying_type>, T2>::value &&
2434 std::is_base_of<units::linear_scale<typename units::traits::unit_t_traits<T3>::underlying_type>, T3>::value> {};
2435 template<
typename T1,
typename T2 = T1,
typename T3 = T1>
2446#if !defined(_MSC_VER) || _MSC_VER > 1800
2447 template<
typename... T>
2448 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> {};
2449 template<
typename... T>
2452 template<
typename T1,
typename T2 = T1,
typename T3 = T1>
2454 std::is_base_of<units::decibel_scale<typename units::traits::unit_t_traits<T1>::underlying_type>, T1>::value &&
2455 std::is_base_of<units::decibel_scale<typename units::traits::unit_t_traits<T2>::underlying_type>, T2>::value &&
2456 std::is_base_of<units::decibel_scale<typename units::traits::unit_t_traits<T2>::underlying_type>, T3>::value> {};
2457 template<
typename T1,
typename T2 = T1,
typename T3 = T1>
2469 template<
typename T1,
typename T2>
2471 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>
2473 template<
typename T1,
typename T2>
2496 template<
typename T>
2503#if defined(_MSC_VER) && (_MSC_VER > 1800)
2507 template<
class... Args>
2529#if defined(_MSC_VER)
2530# pragma warning(push)
2531# pragma warning(disable : 4348)
2535#if defined(_MSC_VER)
2536# pragma warning(pop)
2543 template<class UnitTypeLhs, class UnitTypeRhs, std::enable_if_t<!traits::is_same_scale<UnitTypeLhs, UnitTypeRhs>::value,
int> = 0>
2544 constexpr inline int operator+(
const UnitTypeLhs& ,
const UnitTypeRhs& )
noexcept
2551 template<class UnitTypeLhs, class UnitTypeRhs, std::enable_if_t<traits::has_linear_scale<UnitTypeLhs, UnitTypeRhs>::value,
int> = 0>
2552 inline constexpr UnitTypeLhs
operator+(
const UnitTypeLhs& lhs,
const UnitTypeRhs& rhs)
noexcept
2554 using UnitsLhs =
typename units::traits::unit_t_traits<UnitTypeLhs>::unit_type;
2555 using UnitsRhs =
typename units::traits::unit_t_traits<UnitTypeRhs>::unit_type;
2556 return UnitTypeLhs(lhs() + convert<UnitsRhs, UnitsLhs>(rhs()));
2560 template<typename T, std::enable_if_t<std::is_arithmetic<T>::value,
int> = 0>
2567 template<typename T, std::enable_if_t<std::is_arithmetic<T>::value,
int> = 0>
2574 template<class UnitTypeLhs, class UnitTypeRhs, std::enable_if_t<traits::has_linear_scale<UnitTypeLhs, UnitTypeRhs>::value,
int> = 0>
2575 inline constexpr UnitTypeLhs
operator-(
const UnitTypeLhs& lhs,
const UnitTypeRhs& rhs)
noexcept
2577 using UnitsLhs =
typename units::traits::unit_t_traits<UnitTypeLhs>::unit_type;
2578 using UnitsRhs =
typename units::traits::unit_t_traits<UnitTypeRhs>::unit_type;
2579 return UnitTypeLhs(lhs() - convert<UnitsRhs, UnitsLhs>(rhs()));
2583 template<typename T, std::enable_if_t<std::is_arithmetic<T>::value,
int> = 0>
2590 template<typename T, std::enable_if_t<std::is_arithmetic<T>::value,
int> = 0>
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,
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;
2604 (lhs() * convert<UnitsRhs, UnitsLhs>(rhs()));
2608 template<
class UnitTypeLhs,
class UnitTypeRhs,
2609 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>
2612 using UnitsLhs =
typename units::traits::unit_t_traits<UnitTypeLhs>::unit_type;
2613 using UnitsRhs =
typename units::traits::unit_t_traits<UnitTypeRhs>::unit_type;
2614 return unit_t<compound_unit<UnitsLhs, UnitsRhs>>
2619 template<
class UnitTypeLhs,
typename UnitTypeRhs,
2620 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>
2621 inline constexpr UnitTypeLhs
operator*(
const UnitTypeLhs& lhs,
const UnitTypeRhs& rhs)
noexcept
2628 template<
class UnitTypeLhs,
typename UnitTypeRhs,
2629 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>
2630 inline constexpr UnitTypeRhs
operator*(
const UnitTypeLhs& lhs,
const UnitTypeRhs& rhs)
noexcept
2637 template<
class UnitTypeLhs,
typename T,
2638 std::enable_if_t<std::is_arithmetic<T>::value && traits::has_linear_scale<UnitTypeLhs>::value,
int> = 0>
2639 inline constexpr UnitTypeLhs
operator*(
const UnitTypeLhs& lhs, T rhs)
noexcept
2641 return UnitTypeLhs(lhs() * rhs);
2645 template<
class UnitTypeRhs,
typename T,
2646 std::enable_if_t<std::is_arithmetic<T>::value && traits::has_linear_scale<UnitTypeRhs>::value,
int> = 0>
2647 inline constexpr UnitTypeRhs
operator*(T lhs,
const UnitTypeRhs& rhs)
noexcept
2649 return UnitTypeRhs(lhs * rhs());
2653 template<
class UnitTypeLhs,
class UnitTypeRhs,
2654 std::enable_if_t<traits::is_convertible_unit_t<UnitTypeLhs, UnitTypeRhs>::value && traits::has_linear_scale<UnitTypeLhs, UnitTypeRhs>::value,
int> = 0>
2657 using UnitsLhs =
typename units::traits::unit_t_traits<UnitTypeLhs>::unit_type;
2658 using UnitsRhs =
typename units::traits::unit_t_traits<UnitTypeRhs>::unit_type;
2663 template<
class UnitTypeLhs,
class UnitTypeRhs,
2664 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>
2667 using UnitsLhs =
typename units::traits::unit_t_traits<UnitTypeLhs>::unit_type;
2668 using UnitsRhs =
typename units::traits::unit_t_traits<UnitTypeRhs>::unit_type;
2674 template<
class UnitTypeLhs,
class UnitTypeRhs,
2675 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>
2676 inline constexpr UnitTypeLhs
operator/(
const UnitTypeLhs& lhs,
const UnitTypeRhs& rhs)
noexcept
2682 template<
class UnitTypeLhs,
class UnitTypeRhs,
2683 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>
2691 template<
class UnitTypeLhs,
typename T,
2692 std::enable_if_t<std::is_arithmetic<T>::value && traits::has_linear_scale<UnitTypeLhs>::value,
int> = 0>
2693 inline constexpr UnitTypeLhs
operator/(
const UnitTypeLhs& lhs, T rhs)
noexcept
2695 return UnitTypeLhs(lhs() / rhs);
2699 template<
class UnitTypeRhs,
typename T,
2700 std::enable_if_t<std::is_arithmetic<T>::value && traits::has_linear_scale<UnitTypeRhs>::value,
int> = 0>
2703 using UnitsRhs =
typename units::traits::unit_t_traits<UnitTypeRhs>::unit_type;
2712 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2719 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2726 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2732 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2738 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2744 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2750 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2756 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2762 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2768 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2774 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2777 return lhs < static_cast<UNIT_LIB_DEFAULT_TYPE>(rhs);
2780 template<typename Units, class = std::enable_if_t<units::traits::is_dimensionless_unit<Units>::value>>
2794 template <
int N,
class U>
struct power_of_unit
2796 typedef typename units::detail::unit_multiply<U,
typename power_of_unit<N - 1, U>
::type>
type;
2800 template <
class U>
struct power_of_unit<1, U>
2816 template<int power, class UnitType, class = typename std::enable_if<traits::has_linear_scale<UnitType>::value,
int>>
2831 template<int power, class UnitType, class = typename std::enable_if<traits::has_linear_scale<UnitType>::value,
int>>
2834 static_assert(power >= 0,
"cpow cannot accept negative numbers. Try units::math::pow instead.");
2850 template<
typename T>
2857#if defined(_MSC_VER) && (_MSC_VER > 1800)
2862 template<
class... Args>
2882#if defined(UNIT_LIB_ENABLE_IOSTREAM)
2885 inline std::ostream&
operator<<(std::ostream& os,
const dB_t& obj) { os << obj() <<
" dB";
return os; }
2889#if __has_include(<fmt/format.h>) && !defined(UNIT_LIB_DISABLE_FMT)
2893 template <
typename FormatContext>
2895 FormatContext& ctx) ->
decltype(ctx.out())
2897 auto out = ctx.out();
2910 template<
class UnitTypeLhs,
class UnitTypeRhs,
2911 std::enable_if_t<traits::has_decibel_scale<UnitTypeLhs, UnitTypeRhs>::value,
int> = 0>
2914 using LhsUnits =
typename units::traits::unit_t_traits<UnitTypeLhs>::unit_type;
2915 using RhsUnits =
typename units::traits::unit_t_traits<UnitTypeRhs>::unit_type;
2916 using underlying_type =
typename units::traits::unit_t_traits<UnitTypeLhs>::underlying_type;
2919 (lhs.template toLinearized<underlying_type>() * convert<RhsUnits, LhsUnits>(rhs.template toLinearized<underlying_type>()), std::true_type());
2923 template<class UnitTypeLhs, std::enable_if_t<traits::has_decibel_scale<UnitTypeLhs>::value && !traits::is_dimensionless_unit<UnitTypeLhs>::value,
int> = 0>
2926 using underlying_type =
typename units::traits::unit_t_traits<UnitTypeLhs>::underlying_type;
2927 return UnitTypeLhs(lhs.template toLinearized<underlying_type>() * rhs.template toLinearized<underlying_type>(), std::true_type());
2931 template<class UnitTypeRhs, std::enable_if_t<traits::has_decibel_scale<UnitTypeRhs>::value && !traits::is_dimensionless_unit<UnitTypeRhs>::value,
int> = 0>
2934 using underlying_type =
typename units::traits::unit_t_traits<UnitTypeRhs>::underlying_type;
2935 return UnitTypeRhs(lhs.template toLinearized<underlying_type>() * rhs.template toLinearized<underlying_type>(), std::true_type());
2939 template<class UnitTypeLhs, class UnitTypeRhs, std::enable_if_t<traits::has_decibel_scale<UnitTypeLhs, UnitTypeRhs>::value,
int> = 0>
2942 using LhsUnits =
typename units::traits::unit_t_traits<UnitTypeLhs>::unit_type;
2943 using RhsUnits =
typename units::traits::unit_t_traits<UnitTypeRhs>::unit_type;
2944 using underlying_type =
typename units::traits::unit_t_traits<UnitTypeLhs>::underlying_type;
2947 (lhs.template toLinearized<underlying_type>() / convert<RhsUnits, LhsUnits>(rhs.template toLinearized<underlying_type>()), std::true_type());
2951 template<class UnitTypeLhs, std::enable_if_t<traits::has_decibel_scale<UnitTypeLhs>::value && !traits::is_dimensionless_unit<UnitTypeLhs>::value,
int> = 0>
2954 using underlying_type =
typename units::traits::unit_t_traits<UnitTypeLhs>::underlying_type;
2955 return UnitTypeLhs(lhs.template toLinearized<underlying_type>() / rhs.template toLinearized<underlying_type>(), std::true_type());
2959 template<class UnitTypeRhs, std::enable_if_t<traits::has_decibel_scale<UnitTypeRhs>::value && !traits::is_dimensionless_unit<UnitTypeRhs>::value,
int> = 0>
2962 using RhsUnits =
typename units::traits::unit_t_traits<UnitTypeRhs>::unit_type;
2963 using underlying_type =
typename units::traits::unit_t_traits<RhsUnits>::underlying_type;
2966 (lhs.template toLinearized<underlying_type>() / rhs.template toLinearized<underlying_type>(), std::true_type());
2976 template<
class Units>
2977 struct _unit_value_t {};
2983#ifdef FOR_DOXYGEN_PURPOSES_ONLY
2991 template<
typename T>
2992 struct unit_value_t_traits
2994 typedef typename T::unit_type unit_type;
2995 typedef typename T::ratio ratio;
3004 template<
typename T,
typename =
void>
3005 struct unit_value_t_traits
3007 typedef void unit_type;
3016 template<
typename T>
3017 struct unit_value_t_traits <T, typename
void_t<
3018 typename T::unit_type,
3019 typename T::ratio>
::type>
3021 typedef typename T::unit_type unit_type;
3022 typedef typename T::ratio ratio;
3044 template<
typename Units, std::u
intmax_t Num, std::u
intmax_t Denom = 1>
3064 template<typename T, typename Units = typename traits::unit_value_t_traits<T>::unit_type>
3066 std::is_base_of<units::detail::_unit_value_t<Units>, T>::value>
3068 template<typename T, typename Units = typename traits::unit_value_t_traits<T>::unit_type>
3076 template<
typename Category,
typename T>
3078 std::is_same<units::traits::base_unit_of<typename traits::unit_value_t_traits<T>::unit_type>, Category>::value>
3082 template<
typename Category,
typename T>
3090 template<
class U1,
class U2>
3091 struct unit_value_arithmetic
3096 using _UNIT1 =
typename traits::unit_value_t_traits<U1>::unit_type;
3097 using _UNIT2 =
typename traits::unit_value_t_traits<U2>::unit_type;
3098 using _CONV1 =
typename units::traits::unit_traits<_UNIT1>::conversion_ratio;
3099 using _CONV2 =
typename units::traits::unit_traits<_UNIT2>::conversion_ratio;
3100 using _RATIO1 =
typename traits::unit_value_t_traits<U1>::ratio;
3101 using _RATIO2 =
typename traits::unit_value_t_traits<U2>::ratio;
3102 using _RATIO2CONV =
typename std::ratio_divide<std::ratio_multiply<_RATIO2, _CONV2>, _CONV1>;
3103 using _PI_EXP = std::ratio_subtract<typename units::traits::unit_traits<_UNIT2>::pi_exponent_ratio,
typename units::traits::unit_traits<_UNIT1>::pi_exponent_ratio>;
3118 template<
class U1,
class U2>
3119 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>
3122 using Base = units::detail::unit_value_arithmetic<U1, U2>;
3123 typedef typename Base::_UNIT1 unit_type;
3124 using ratio = std::ratio_add<typename Base::_RATIO1, typename Base::_RATIO2CONV>;
3137 using UsePi = std::integral_constant<bool, Base::_PI_EXP::num != 0>;
3138 return value(UsePi());
3149 static constexpr const unit_t<unit_type>
value(std::true_type)
noexcept
3167 template<
class U1,
class U2>
3168 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>
3171 using Base = units::detail::unit_value_arithmetic<U1, U2>;
3173 typedef typename Base::_UNIT1 unit_type;
3174 using ratio = std::ratio_subtract<typename Base::_RATIO1, typename Base::_RATIO2CONV>;
3187 using UsePi = std::integral_constant<bool, Base::_PI_EXP::num != 0>;
3188 return value(UsePi());
3199 static constexpr const unit_t<unit_type>
value(std::true_type)
noexcept
3217 template<
class U1,
class U2>
3219 units::detail::_unit_value_t<typename std::conditional<traits::is_convertible_unit<typename traits::unit_value_t_traits<U1>::unit_type,
3220 typename traits::unit_value_t_traits<U2>::unit_type>::value, compound_unit<squared<typename traits::unit_value_t_traits<U1>::unit_type>>,
3221 compound_unit<typename traits::unit_value_t_traits<U1>::unit_type, typename traits::unit_value_t_traits<U2>::unit_type>>::type>
3224 using Base = units::detail::unit_value_arithmetic<U1, U2>;
3227 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>>;
3238 using UsePi = std::integral_constant<bool, Base::_PI_EXP::num != 0>;
3239 return value(UsePi());
3250 static constexpr const unit_t<unit_type>
value(std::true_type)
noexcept
3267 template<
class U1,
class U2>
3269 units::detail::_unit_value_t<typename std::conditional<traits::is_convertible_unit<typename traits::unit_value_t_traits<U1>::unit_type,
3270 typename traits::unit_value_t_traits<U2>::unit_type>::value, dimensionless::scalar, compound_unit<typename traits::unit_value_t_traits<U1>::unit_type,
3271 inverse<typename traits::unit_value_t_traits<U2>::unit_type>>>::type>
3274 using Base = units::detail::unit_value_arithmetic<U1, U2>;
3277 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>>;
3288 using UsePi = std::integral_constant<bool, Base::_PI_EXP::num != 0>;
3289 return value(UsePi());
3300 static constexpr const unit_t<unit_type>
value(std::true_type)
noexcept
3316 template<
class U1,
int power>
3317 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>
3320 using Base = units::detail::unit_value_arithmetic<U1, U1>;
3324 using pi_exponent = std::ratio_multiply<std::ratio<power>,
typename Base::_UNIT1::pi_exponent_ratio>;
3335 using UsePi = std::integral_constant<bool, Base::_PI_EXP::num != 0>;
3336 return value(UsePi());
3347 static constexpr const unit_t<unit_type>
value(std::true_type)
noexcept
3363 template<
class U1, std::
intmax_t Eps = 10000000000>
3364 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>>
3367 using Base = units::detail::unit_value_arithmetic<U1, U1>;
3382 using UsePi = std::integral_constant<bool, Base::_PI_EXP::num != 0>;
3383 return value(UsePi());
3394 static constexpr const unit_t<unit_type>
value(std::true_type)
noexcept
3419 template<
class UnitTypeLhs,
class UnitTypeRhs>
3420 UnitTypeLhs (
min)(
const UnitTypeLhs& lhs,
const UnitTypeRhs& rhs)
3424 return (lhs < r ? lhs : r);
3427 template<
class UnitTypeLhs,
class UnitTypeRhs>
3428 UnitTypeLhs (
max)(
const UnitTypeLhs& lhs,
const UnitTypeRhs& rhs)
3432 return (lhs > r ? lhs : r);
3438# if _MSC_VER <= 1800
3439# pragma warning(pop)
3441# pragma pop_macro("constexpr")
3443# pragma pop_macro("noexcept")
3444# undef _ALLOW_KEYWORD_MACROS
3446# pragma pop_macro("pascal")
3449#if defined(UNIT_HAS_LITERAL_SUPPORT)
3454#if __has_include(<fmt/format.h>) && !defined(UNIT_LIB_DISABLE_FMT)
#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:1937
constexpr bool operator<(const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) const noexcept
less-than
Definition: base.h:2039
constexpr bool operator<=(const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) const noexcept
less-than or equal
Definition: base.h:2051
constexpr unit_t< U > convert() const noexcept
conversion
Definition: base.h:2154
unit_t & operator=(const Ty &rhs) noexcept
assignment
Definition: base.h:2026
constexpr unit_t(const std::chrono::duration< Rep, Period > &value) noexcept
chrono constructor
Definition: base.h:1990
constexpr underlying_type value() const noexcept
unit value
Definition: base.h:2118
constexpr unit_t(const Ty value) noexcept
constructor
Definition: base.h:1979
constexpr unit_t(const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) noexcept
copy constructor (converting)
Definition: base.h:2002
constexpr const char * name() const noexcept
returns the unit name
Definition: base.h:2194
constexpr Ty toLinearized() const noexcept
linearized unit value
Definition: base.h:2139
constexpr Ty to() const noexcept
unit value
Definition: base.h:2128
constexpr bool operator!=(const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) const noexcept
inequality
Definition: base.h:2109
Units unit_type
Type of unit the unit_t represents (e.g. meters)
Definition: base.h:1951
constexpr bool operator>(const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) const noexcept
greater-than
Definition: base.h:2063
T value_type
Synonym for underlying type. May be removed in future versions. Prefer underlying_type.
Definition: base.h:1950
constexpr bool operator==(const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) const noexcept
equality
Definition: base.h:2088
constexpr unit_t(const T value, const Args &... args) noexcept
constructor
Definition: base.h:1968
constexpr const char * abbreviation() const noexcept
returns the unit abbreviation
Definition: base.h:2202
NonLinearScale< T > non_linear_scale_type
Type of the non-linear scale of the unit_t (e.g. linear_scale)
Definition: base.h:1948
NonLinearScale< T > nls
Definition: base.h:1943
constexpr bool operator>=(const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) const noexcept
greater-than or equal
Definition: base.h:2075
constexpr unit_t()=default
default constructor.
unit_t & operator=(const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) noexcept
assignment
Definition: base.h:2014
T underlying_type
Type of the underlying storage of the unit_t (e.g. double)
Definition: base.h:1949
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:2403
static constexpr T convert(const T &value) noexcept
converts a value from one type to another.
Definition: base.h:1659
typename units::detail::Sqrt< Ratio, std::ratio< 1, Eps > >::type ratio_sqrt
Calculate square root of a ratio at compile-time.
Definition: base.h:1367
constexpr UnitType make_unit(const T value) noexcept
Constructs a unit container from an arithmetic type.
Definition: base.h:2228
typename units::detail::prefix< std::peta, U >::type peta
Represents the type of class U with the metric 'peta' prefix appended.
Definition: base.h:1502
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:1515
typename units::detail::prefix< std::milli, U >::type milli
Represents the type of class U with the metric 'milli' prefix appended.
Definition: base.h:1493
typename units::detail::inverse_impl< U >::type inverse
represents the inverse unit type of class U.
Definition: base.h:1145
typename units::detail::prefix< std::micro, U >::type micro
Represents the type of class U with the metric 'micro' prefix appended.
Definition: base.h:1492
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:1513
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:1517
typename units::detail::prefix< std::giga, U >::type giga
Represents the type of class U with the metric 'giga' prefix appended.
Definition: base.h:1500
typename units::detail::squared_impl< U >::type squared
represents the unit type of class U squared
Definition: base.h:1176
typename units::detail::prefix< std::deca, U >::type deca
Represents the type of class U with the metric 'deca' prefix appended.
Definition: base.h:1496
typename units::detail::prefix< std::deci, U >::type deci
Represents the type of class U with the metric 'deci' prefix appended.
Definition: base.h:1495
typename units::detail::cubed_impl< U >::type cubed
represents the type of class U cubed.
Definition: base.h:1206
typename units::detail::prefix< std::femto, U >::type femto
Represents the type of class U with the metric 'femto' prefix appended.
Definition: base.h:1489
typename units::detail::prefix< std::pico, U >::type pico
Represents the type of class U with the metric 'pico' prefix appended.
Definition: base.h:1490
typename units::detail::prefix< std::tera, U >::type tera
Represents the type of class U with the metric 'tera' prefix appended.
Definition: base.h:1501
typename units::detail::prefix< std::hecto, U >::type hecto
Represents the type of class U with the metric 'hecto' prefix appended.
Definition: base.h:1497
typename units::detail::prefix< std::atto, U >::type atto
Represents the type of class U with the metric 'atto' prefix appended.
Definition: base.h:1488
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:1514
typename units::detail::prefix< std::exa, U >::type exa
Represents the type of class U with the metric 'exa' prefix appended.
Definition: base.h:1503
typename units::detail::sqrt_impl< U, Eps >::type square_root
represents the square root of type class U.
Definition: base.h:1412
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:1516
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:1512
typename units::detail::prefix< std::centi, U >::type centi
Represents the type of class U with the metric 'centi' prefix appended.
Definition: base.h:1494
typename units::detail::prefix< std::nano, U >::type nano
Represents the type of class U with the metric 'nano' prefix appended.
Definition: base.h:1491
typename units::detail::prefix< std::mega, U >::type mega
Represents the type of class U with the metric 'mega' prefix appended.
Definition: base.h:1499
typename units::detail::prefix< std::kilo, U >::type kilo
Represents the type of class U with the metric 'kilo' prefix appended.
Definition: base.h:1498
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:1445
@ 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 bfloat16 &v)
Definition: BFloat16.h:594
const Scalar & y
Definition: MathFunctions.h:821
Definition: format-inl.h:32
Definition: BFloat16.h:88
base_unit< detail::meter_ratio< 0 >, std::ratio< 0 >, std::ratio< 1 > > time_unit
Represents an SI base unit of time.
Definition: base.h:809
base_unit< detail::meter_ratio< 0 >, std::ratio< 1 > > mass_unit
Represents an SI base unit of mass.
Definition: base.h:808
base_unit< detail::meter_ratio<-3 >, std::ratio< 1 > > density_unit
Represents an SI derived unit of density.
Definition: base.h:845
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:833
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:821
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:831
base_unit< detail::meter_ratio< 1 > > length_unit
Represents an SI base unit of length.
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< 0 >, std::ratio< 1 > > luminous_intensity_unit
Represents an SI base unit of luminous intensity.
Definition: base.h:814
base_unit concentration_unit
Represents a unit of concentration.
Definition: base.h:846
base_unit< detail::meter_ratio< 2 >, std::ratio< 1 >, std::ratio<-2 > > energy_unit
Represents an SI derived unit of energy.
Definition: base.h:827
base_unit< detail::meter_ratio< 3 > > volume_unit
Represents an SI derived unit of volume.
Definition: base.h:844
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:837
base_unit dimensionless_unit
Represents a quantity with no dimension.
Definition: base.h:803
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:847
base_unit< detail::meter_ratio<-1 >, std::ratio< 1 >, std::ratio<-2 > > pressure_unit
Represents an SI derived unit of pressure.
Definition: base.h:825
base_unit< detail::meter_ratio< 1 >, std::ratio< 0 >, std::ratio<-2 > > acceleration_unit
Represents an SI derived unit of acceleration.
Definition: base.h:822
base_unit scalar_unit
Represents a quantity with no dimension.
Definition: base.h:802
base_unit< detail::meter_ratio< 2 >, std::ratio< 1 >, std::ratio<-3 > > power_unit
Represents an SI derived unit of power.
Definition: base.h:828
base_unit< detail::meter_ratio< 0 >, std::ratio< 0 >, std::ratio<-1 > > frequency_unit
Represents an SI derived unit of frequency.
Definition: base.h:819
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:810
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:811
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:826
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:818
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:813
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:829
base_unit< detail::meter_ratio< 0 >, std::ratio< 0 >, std::ratio<-1 > > radioactivity_unit
Represents an SI derived unit of radioactivity.
Definition: base.h:838
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:836
base_unit< detail::meter_ratio< 2 >, std::ratio< 1 >, std::ratio<-2 > > torque_unit
Represents an SI derived unit of torque.
Definition: base.h:842
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:835
base_unit< detail::meter_ratio< 1 >, std::ratio< 0 >, std::ratio<-1 > > velocity_unit
Represents an SI derived unit of velocity.
Definition: base.h:820
base_unit< detail::meter_ratio< 1 >, std::ratio< 1 >, std::ratio<-2 > > force_unit
Represents an SI derived unit of force.
Definition: base.h:824
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:823
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:848
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:830
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:832
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:834
base_unit< detail::meter_ratio< 2 > > area_unit
Represents an SI derived unit of area.
Definition: base.h:843
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:812
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:2879
unit< std::ratio< 1 >, units::category::dimensionless_unit > dimensionless
Definition: base.h:2522
dB_t dBi_t
Definition: base.h:2880
scalar_t dimensionless_t
Definition: base.h:2525
unit_t< scalar > scalar_t
Definition: base.h:2524
unit< std::ratio< 1 >, units::category::scalar_unit > scalar
Definition: base.h:2521
UnitTypeLhs() max(const UnitTypeLhs &lhs, const UnitTypeRhs &rhs)
Definition: base.h:3428
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:2832
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:2817
UnitTypeLhs() min(const UnitTypeLhs &lhs, const UnitTypeRhs &rhs)
Definition: base.h:3420
constexpr bool has_decibel_scale_v
Definition: base.h:2450
constexpr bool is_convertible_unit_v
Definition: base.h:1542
constexpr bool has_linear_scale_v
Definition: base.h:2428
constexpr bool is_unit_value_t_category_v
Definition: base.h:3083
constexpr bool is_same_scale_v
Definition: base.h:2474
constexpr bool is_unit_v
Definition: base.h:732
constexpr bool is_unit_t_v
Definition: base.h:1877
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:943
constexpr bool is_ratio_v
Definition: base.h:604
constexpr bool is_unit_value_t_v
Definition: base.h:3069
Unit Conversion Library namespace.
Definition: magnetic_flux.h:31
unit_t< Units, T, NonLinearScale > & operator*=(unit_t< Units, T, NonLinearScale > &lhs, const RhsType &rhs) noexcept
Definition: base.h:2314
unit_t< Units, T, NonLinearScale > & operator/=(unit_t< Units, T, NonLinearScale > &lhs, const RhsType &rhs) noexcept
Definition: base.h:2324
constexpr bool operator!=(const UNIT_LIB_DEFAULT_TYPE lhs, const Units &rhs) noexcept
Definition: base.h:2727
unit_t< Units, T, NonLinearScale > & operator+=(unit_t< Units, T, NonLinearScale > &lhs, const RhsType &rhs) noexcept
Definition: base.h:2292
constexpr const char * abbreviation(const T &)
constexpr bool operator==(const UNIT_LIB_DEFAULT_TYPE lhs, const Units &rhs) noexcept
Definition: base.h:2713
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:2655
constexpr const char * name(const T &)
constexpr bool operator<(const UNIT_LIB_DEFAULT_TYPE lhs, const Units &rhs) noexcept
Definition: base.h:2775
unit_t< Units, T, NonLinearScale > & operator++(unit_t< Units, T, NonLinearScale > &u) noexcept
Definition: base.h:2346
unit_t< Units, T, NonLinearScale > & operator-=(unit_t< Units, T, NonLinearScale > &lhs, const RhsType &rhs) noexcept
Definition: base.h:2303
constexpr bool operator<=(const UNIT_LIB_DEFAULT_TYPE lhs, const Units &rhs) noexcept
Definition: base.h:2763
unit_t< Units, T, NonLinearScale > & operator--(unit_t< Units, T, NonLinearScale > &u) noexcept
Definition: base.h:2370
constexpr bool operator>=(const UNIT_LIB_DEFAULT_TYPE lhs, const Units &rhs) noexcept
Definition: base.h:2739
constexpr bool operator>(const UNIT_LIB_DEFAULT_TYPE lhs, const Units &rhs) noexcept
Definition: base.h:2751
constexpr unit_t< Units, T, NonLinearScale > operator-(const unit_t< Units, T, NonLinearScale > &u) noexcept
Definition: base.h:2363
constexpr unit_t< Units, T, NonLinearScale > operator+(const unit_t< Units, T, NonLinearScale > &u) noexcept
Definition: base.h:2339
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:2599
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:769
Kilogram kilogram_ratio
Definition: base.h:781
Radian radian_ratio
Definition: base.h:783
Kelvin kelvin_ratio
Definition: base.h:785
Ampere ampere_ratio
Definition: base.h:784
Byte byte_ratio
Definition: base.h:788
Candela candela_ratio
Definition: base.h:787
Second second_ratio
Definition: base.h:782
Meter meter_ratio
Definition: base.h:780
Mole mole_ratio
Definition: base.h:786
unit_t scale for representing decibel values.
Definition: base.h:2852
decibel_scale & operator=(const decibel_scale &)=default
constexpr decibel_scale(const T value) noexcept
Definition: base.h:2861
constexpr decibel_scale(const T value, std::true_type, Args &&...) noexcept
Definition: base.h:2863
constexpr decibel_scale()=default
T m_value
linearized value
Definition: base.h:2866
constexpr T operator()() const noexcept
Definition: base.h:2864
constexpr decibel_scale(const decibel_scale &)=default
unit_t scale which is linear
Definition: base.h:2498
constexpr T operator()() const noexcept
returns value.
Definition: base.h:2509
UNIT_LIB_DEFAULT_TYPE m_value
linearized value.
Definition: base.h:2511
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:2508
Trait which tests whether a type is inherited from a decibel scale.
Definition: base.h:2448
Trait which tests whether a type is inherited from a linear scale.
Definition: base.h:2426
Trait which tests if a class is a base_unit type.
Definition: base.h:704
Trait which tests whether two container types derived from unit_t are convertible to each other.
Definition: base.h:1837
Trait which checks whether two units can be converted to each other.
Definition: base.h:1540
Trait which tests that class T meets the requirements for a non-linear scale.
Definition: base.h:1760
Trait that tests whether a type represents a std::ratio.
Definition: base.h:602
Trait which tests whether two types has the same non-linear scale.
Definition: base.h:2472
Traits which tests if a class is a unit
Definition: base.h:1875
Trait which tests whether type T is a unit_value_t with a unit type in the given category.
Definition: base.h:3079
Trait which tests whether a type is a unit_value_t representing the given unit type.
Definition: base.h:3067
Traits which tests if a class is a unit
Definition: base.h:730
adds two unit_value_t types at compile-time
Definition: base.h:3120
static constexpr const unit_t< unit_type > value() noexcept
Value of sum.
Definition: base.h:3135
divides two unit_value_t types at compile-time
Definition: base.h:3272
static constexpr const unit_t< unit_type > value() noexcept
Value of quotient.
Definition: base.h:3286
multiplies two unit_value_t types at compile-time
Definition: base.h:3222
static constexpr const unit_t< unit_type > value() noexcept
Value of product.
Definition: base.h:3236
raises unit_value_to a power at compile-time
Definition: base.h:3318
static constexpr const unit_t< unit_type > value() noexcept
Value of exponentiation.
Definition: base.h:3333
calculates square root of unit_value_t at compile-time
Definition: base.h:3365
static constexpr const unit_t< unit_type > value() noexcept
Value of square root.
Definition: base.h:3380
subtracts two unit_value_t types at compile-time
Definition: base.h:3169
static constexpr const unit_t< unit_type > value() noexcept
Value of difference.
Definition: base.h:3185
Stores a rational unit value as a compile-time constant.
Definition: base.h:3046
Units unit_type
Definition: base.h:3047
std::ratio< Num, Denom > ratio
Definition: base.h:3048
static constexpr const unit_t< Units > value()
Definition: base.h:3051
Type representing an arbitrary unit.
Definition: base.h:895
std::ratio_add< std::ratio_multiply< typename BaseUnit::conversion_ratio, Translation >, typename BaseUnit::translation_ratio > translation_ratio
Definition: base.h:903
std::ratio_multiply< typename BaseUnit::conversion_ratio, Conversion > conversion_ratio
Definition: base.h:901
units::traits::unit_traits< BaseUnit >::base_unit_type base_unit_type
Definition: base.h:900
std::ratio_add< typename BaseUnit::pi_exponent_ratio, PiExponent > pi_exponent_ratio
Definition: base.h:902
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