LMCAS
Lamina Computer Algebra System
载入中...
搜索中...
未找到
unit.hpp
浏览该文件的文档.
1#pragma once
2
3#include <map>
4#include <string>
5#include <unordered_map>
6
7#include "lmcas_export.hpp"
8#include "rational.hpp"
9#include "result.hpp"
10
11namespace LMCAS {
12
13/** A canonical product of base dimensions raised to exact rational powers. */
14class LMCAS_API DimensionSignature {
15public:
16 using Exponents = std::map<std::string, Rational>;
17
18 DimensionSignature() = default;
19 explicit DimensionSignature(Exponents exponents);
20
21 static DimensionSignature base(std::string name);
22
23 bool is_dimensionless() const noexcept { return exponents_.empty(); }
24 const Exponents& exponents() const noexcept { return exponents_; }
25
26 DimensionSignature multiplied_by(const DimensionSignature& other) const;
27 DimensionSignature divided_by(const DimensionSignature& other) const;
28 DimensionSignature raised_to(const Rational& exponent) const;
29 std::string to_string() const;
30
31 bool operator==(const DimensionSignature& other) const noexcept {
32 return exponents_ == other.exponents_;
33 }
34 bool operator!=(const DimensionSignature& other) const noexcept {
35 return !(*this == other);
36 }
37
38private:
39 Exponents exponents_;
40};
41
43 DimensionSignature dimension;
44 Rational scale_to_base = Rational(1);
45};
46
47/** Owns unit declarations for one computation context. */
48class LMCAS_API UnitSystem {
49public:
50 UnitSystem();
51
52 Result<void> declare_base_unit(const std::string& name);
53 Result<void> declare_derived_unit(const std::string& name,
55 Result<UnitDefinition> resolve(const std::string& name) const;
56 Result<Rational> conversion_factor(const std::string& source,
57 const std::string& target) const;
58
59private:
60 std::unordered_map<std::string, UnitDefinition> units_;
61};
62
63} // namespace LMCAS
#define LMCAS_API
DimensionSignature dimension
std::string UnitDefinition definition
const ExprPtr & target
__attribute__((visibility("default"))) Result< EqvProfile > eqv_profile_from_name(const std const std::string & name
精确有理数 Rational,基于 BigInt 分子/分母表示,自动约分。