TypeSI
Units of 'Système international' Blended for C++
Loading...
Searching...
No Matches
si_math.hpp
Go to the documentation of this file.
1#pragma once
4#include "si_internal.hpp"
5#include "si_prefix.hpp"
6#include <cmath>
7namespace Si {
8namespace Internal {
9template <typename T> struct std_pow {
10 T operator()(const T &base, const T &power) const {
11 return std::pow(base, power);
12 }
13};
14} // namespace Internal
16namespace Math {
24template <typename Power, typename T, typename Function = Internal::std_pow<T>,
25 typename... Powers>
29 Function()(static_cast<T>(base),
30 static_cast<T>(Power::num) / static_cast<T>(Power::den)));
31}
39template <
40 typename Power, typename Unit,
42 typename PrefixRatio>
44 typename std::ratio<static_cast<std::intmax_t>(std::pow(PrefixRatio::num,
45 Power::num)),
46 static_cast<std::intmax_t>(std::pow(PrefixRatio::den,
47 Power::num))>::type,
48 decltype(pow<Power>(std::declval<Unit>()))>
50 static_assert(
51 Power::den == 1,
52 "std::ratio for power in case of unit with prefix has to be integer");
54 typename std::ratio<static_cast<std::intmax_t>(
55 std::pow(PrefixRatio::num, Power::num)),
56 static_cast<std::intmax_t>(
57 std::pow(PrefixRatio::den, Power::num))>::type,
58 decltype(pow<Power>(std::declval<Unit>()))>(
59 +pow<Power, decltype(+std::declval<Unit>()), Function>(base.raw()));
60}
61} // namespace Math
62} // namespace Si
Generic type of unit with prefix.
Definition: si_prefix.hpp:12
const Unit & raw() const
Getter for raw Unit reference without prefix applied.
Definition: si_prefix.hpp:18
Generic unit type.
Definition: si_internal.hpp:22
Internal::Unit< T, std::ratio_multiply< Power, Powers >... > pow(const Internal::Unit< T, Powers... > &base)
Function for exponentiation with Unit as base.
Definition: si_math.hpp:27
Core logic of units.
Prefixes for SI units.
Definition: si_math.hpp:9