Skip to content

Commit

Permalink
xo-unit: refactor: use natural_unit<> instead of unit2<>
Browse files Browse the repository at this point in the history
  • Loading branch information
Rconybea committed Apr 23, 2024
1 parent 404930a commit 2312fd7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions include/xo/unit/Quantity2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "quantity2_concept.hpp"
#include "scaled_unit2.hpp"
#include "unit2.hpp"
#include "natural_unit.hpp"

namespace xo {
namespace qty {
Expand All @@ -29,11 +29,12 @@ namespace xo {
class Quantity2 {
public:
using repr_type = Repr;
using unit_type = unit2<Int>;
using unit_type = natural_unit<Int>;
using ratio_int_type = Int;

public:
constexpr Quantity2(Repr scale, const unit2<Int> & unit)
constexpr Quantity2(Repr scale,
const natural_unit<Int> & unit)
: scale_{scale}, unit_{unit} {}

constexpr const repr_type & scale() const { return scale_; }
Expand Down Expand Up @@ -66,7 +67,7 @@ namespace xo {
/** @brief quantity represents this multiple of a unit amount **/
Repr scale_ = Repr{};
/** @brief unit for this quantity **/
unit2<Int> unit_;
natural_unit<Int> unit_;
}; /*Quantity2*/

/** note: won't have constexpr result until c++26 (when ::sqrt(), ::pow() are constexpr)
Expand All @@ -75,8 +76,9 @@ namespace xo {
typename Int = std::int64_t>
inline constexpr Quantity2<Repr, Int>
unit_qty(const scaled_unit2<Int> & u) {
return Quantity2<Repr, Int>(u.outer_scale_exact_.template to<double>() * ::sqrt(u.outer_scale_sq_),
u.natural_unit_);
return Quantity2<Repr, Int>
(u.outer_scale_exact_.template to<double>() * ::sqrt(u.outer_scale_sq_),
u.natural_unit_);
}

/** note: won't have constexpr result until c++26 (when ::sqrt(), ::pow() are constexpr)
Expand Down
4 changes: 2 additions & 2 deletions include/xo/unit/bpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ namespace xo {

static constexpr bpu_abbrev_type
bpu_abbrev(dim native_dim,
const scalefactor_ratio_type & scalefactor,
const power_ratio_type & power)
const scalefactor_ratio_type & scalefactor,
const power_ratio_type & power)
{
return (bpu_abbrev_type::from_flatstring
(flatstring_concat
Expand Down

0 comments on commit 2312fd7

Please sign in to comment.