refactor: pow10 functions to pow.h
This commit is contained in:
1 parent
40fb1e1e8b
commit
2f5be094b2
3 files changed
+63
-32
No files matched your search
@@ -26,6 +26,7 @@
|
||||
#include <units/customization_points.h>
|
||||
#include <units/bits/dimension_op.h>
|
||||
#include <units/bits/external/type_traits.h>
|
||||
#include <units/pow.h>
|
||||
#include <units/quantity.h>
|
||||
#include <units/quantity_point.h>
|
||||
#include <cassert>
|
||||
@@ -37,38 +38,6 @@
|
||||
|
||||
namespace units {
|
||||
|
||||
constexpr std::intmax_t ipow10(std::intmax_t exp)
|
||||
{
|
||||
assert(exp >= 0);
|
||||
if (exp == 0) return 1;
|
||||
std::intmax_t result = 1;
|
||||
while (exp > 0) {
|
||||
result *= 10;
|
||||
--exp;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename Rep>
|
||||
constexpr Rep fpow10(std::intmax_t exp)
|
||||
{
|
||||
if (exp == 0) return Rep(1.0);
|
||||
Rep result = Rep(1.0);
|
||||
if (exp < 0) {
|
||||
while (exp < 0) {
|
||||
result = result / Rep(10.0);
|
||||
++exp;
|
||||
}
|
||||
} else {
|
||||
while (exp > 0) {
|
||||
result = result * Rep(10.0);
|
||||
--exp;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// QuantityOf
|
||||
template<typename T, typename Dim>
|
||||
concept QuantityOf = Quantity<T> && Dimension<Dim> && equivalent_dim<typename T::dimension, Dim>;
|
||||
|
||||
Reference in new issue
Block a user