LMCAS
Lamina Computer Algebra System
载入中...
搜索中...
未找到
symbolic_number_order.cpp
浏览该文件的文档.
2
3namespace LMCAS {
4namespace {
5
6template <typename Number>
7int compare_values(const Number& left, const Number& right) {
8 if (left < right) {
9 return -1;
10 }
11 if (left == right) {
12 return 0;
13 }
14 return 1;
15}
16
17int compare_exact_to_rational(const NumberNode& left, const Rational& right) {
18 if (const auto* rational = std::get_if<Rational>(&left.value())) {
20 }
21 return compare_values(Rational(std::get<BigInt>(left.value())), right);
22}
23
25 if (const auto* rational = std::get_if<Rational>(&right.value())) {
27 }
28 if (const auto* rational = std::get_if<Rational>(&left.value())) {
30 }
31 return compare_values(std::get<BigInt>(left.value()), std::get<BigInt>(right.value()));
32}
33
34}
35
37 const auto& right = static_cast<const NumberNode&>(other);
38 return compare_exact_nodes(*this, right);
39}
40
42 if (const auto* integer = std::get_if<BigInt>(&value_)) {
43 const auto narrowed = integer->try_to_int64();
44 return narrowed && *narrowed == -1;
45 }
46 return std::get<Rational>(value_) == Rational(-1);
47}
48
49}
int compare_same_type(const SymbolicNode &other) const override
const std::variant< BigInt, Rational > & value() const noexcept
NumberNode(const BigInt &v)
const std::variant< BigInt, Rational > value_
SymbolicNode()=default
int compare_values(const Number &left, const Number &right)
int compare_exact_to_rational(const NumberNode &left, const Rational &right)
int compare_exact_nodes(const NumberNode &left, const NumberNode &right)
ExprResult integer(Integer)=delete
const ExprPtr & right
ExprResult rational(const Rational &value)
内部 AST 定义。