Skip to content

Conversation

@lichaofan2008
Copy link

@lichaofan2008 lichaofan2008 commented Jan 20, 2026

This reverts commit 31fab1d.

Summary by Sourcery

Bug Fixes:

  • Reinstate calculation of percentage values based on the preceding operand instead of using a fixed standalone percentage.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 20, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR reverts a previous behavioral change to percentage evaluation in the core evaluator, restoring the use of the preceding value (val2) when computing percentages.

Sequence diagram for percentage evaluation restored behavior

sequenceDiagram
    participant Evaluator
    participant Stack_Quantity as Stack
    participant Quantity
    participant HNumber

    Evaluator->>Stack: pop() to get val1 (current value)
    Evaluator->>Stack: peek() or previous result to get val2

    %% New (restored) behavior
    Evaluator->>HNumber: create("0.01")
    HNumber-->>Evaluator: hNum_001

    Evaluator->>Quantity: multiply(val1, hNum_001)
    Quantity-->>Evaluator: percentBase

    Evaluator->>Quantity: multiply(val2, percentBase)
    Quantity-->>Evaluator: percentResult

    Evaluator->>Evaluator: checkOperatorResult(percentResult)
    Evaluator->>Stack: push(percentResult)
    Evaluator->>Evaluator: m_standardPercent = percentResult
Loading

Class diagram for Evaluator percentage handling in exec

classDiagram
    class Evaluator {
        +exec(opcodes QVector_Opcode, stack Stack_Quantity) Quantity
        -m_standardPercent Quantity
    }

    class Quantity
    class HNumber
    class Opcode
    class QVector_Opcode
    class Stack_Quantity

    Evaluator --> Quantity
    Evaluator --> HNumber
    Evaluator --> QVector_Opcode
    Evaluator --> Stack_Quantity

    %% Focus on the changed percentage computation inside exec
    class PercentageEvaluationContext {
        +val1 Quantity
        +val2 Quantity
        +applyPercent(val1 Quantity, val2 Quantity) Quantity
    }

    Evaluator ..> PercentageEvaluationContext : uses

    %% Old vs new behavior (conceptual methods)
    PercentageEvaluationContext : +applyPercent_old(val1 Quantity) Quantity
    PercentageEvaluationContext : +applyPercent_new(val1 Quantity, val2 Quantity) Quantity
Loading

File-Level Changes

Change Details Files
Restore prior percentage operator behavior to again depend on the preceding value in expression evaluation.
  • Change percent calculation to multiply the current value by 0.01 and then by the preceding value instead of ignoring the preceding value
  • Revert the previously added logic and comment that made 10% independent of the prior operand
3rdparty/core/evaluator.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Since this reintroduces the prior percent behavior that was recently changed, consider adding a brief comment near this logic describing the intended semantics of % (especially how val2 is used) to avoid future flip-flop changes here.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Since this reintroduces the prior percent behavior that was recently changed, consider adding a brief comment near this logic describing the intended semantics of `%` (especially how `val2` is used) to avoid future flip-flop changes here.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link

deepin pr auto review

以下是对这段代码变更的详细审查和改进建议:

1. 语法逻辑审查

当前变更分析:
代码将 val1 = checkOperatorResult(/*val2 * */(val1 * HNumber("0.01"))); 修改为 val1 = checkOperatorResult(val2 * (val1 * HNumber("0.01")));

  • 原代码逻辑:被注释掉的 val2 * 表明之前可能是为了实现类似 val1 * val2 * 0.01 的计算,但实际执行的是 val1 * 0.01。注释说明意图是让 10% 计算为 0.1(绝对值),而不是依赖之前的数值(例如 100 + 10% = 110)。
  • 新代码逻辑:恢复了 val2 的参与,计算变为 val2 * (val1 * 0.01)。这实际上将百分比计算变回了"相对值"模式(例如 100 + 10% 会变成 100 * 0.1 = 10,结果可能是 110100 + 10,取决于上下文)。

潜在问题:

  • 逻辑矛盾:注释声称"用户期望:10%+10%=0.2"(即绝对值模式),但代码却恢复了 val2 的乘法,这会导致计算结果依赖于上下文(相对值模式)。如果目标是实现绝对值模式(10% = 0.1),则 val2 不应参与计算。
  • 语义不清val2 的来源未在代码片段中明确,假设 val2 是栈顶的前一个值(例如 100 + 10% 中的 100),则新代码会实现相对值计算,这与注释的意图相反。

2. 代码质量审查

  • 可读性
    • 表达式 val2 * (val1 * HNumber("0.01")) 可以简化为 (val1 * val2) * HNumber("0.01")val1 * val2 * 0.01(如果 HNumber 支持隐式转换)。
    • 注释与代码不一致,容易误导开发者。建议明确说明百分比计算的模式(绝对值或相对值)。
  • 可维护性
    • 魔法数字 "0.01" 应定义为常量,例如 static const HNumber PERCENT_FACTOR("0.01");
    • 百分比计算模式(绝对值/相对值)应通过配置或参数控制,而不是硬编码。

3. 代码性能审查

  • HNumber("0.01") 每次调用都会构造一个临时对象,建议复用静态常量以减少开销。
  • 如果 val1val2 是大数或高精度数,乘法运算可能较慢,但这是业务逻辑需求,无法优化。

4. 代码安全审查

  • 数值溢出val1 * val2 可能导致溢出,需检查 HNumber 是否处理了这种情况。
  • 精度问题HNumber 可能是高精度数类型,需确保 0.01 的表示不会引入精度误差(例如 0.01 在二进制浮点中无法精确表示)。

改进建议

  1. 明确百分比计算模式

    • 如果目标是绝对值模式(10% = 0.1),则应移除 val2
      val1 = checkOperatorResult(val1 * HNumber("0.01"));
    • 如果目标是相对值模式(100 + 10% = 110),则需更新注释以匹配逻辑。
  2. 使用常量

    static const HNumber PERCENT_FACTOR("0.01");
    val1 = checkOperatorResult(val2 * val1 * PERCENT_FACTOR);
  3. 添加边界检查

    if (val2.isZero()) {
        val1 = Quantity(0); // 或其他默认行为
    } else {
        val1 = checkOperatorResult(val2 * val1 * PERCENT_FACTOR);
    }
  4. 统一注释和代码

    // 相对值模式:100 + 10% = 110(即 100 * 0.1 + 100)
    val1 = checkOperatorResult(val2 * val1 * PERCENT_FACTOR);

最终改进代码示例

static const HNumber PERCENT_FACTOR("0.01");

// 绝对值模式:10% = 0.1,10% + 10% = 0.2
val1 = checkOperatorResult(val1 * PERCENT_FACTOR);
m_standardPercent = val1;
stack.push(val1);
break;

或(相对值模式):

static const HNumber PERCENT_FACTOR("0.01");

// 相对值模式:100 + 10% = 110(即 100 * 0.1 + 100)
val1 = checkOperatorResult(val2 * val1 * PERCENT_FACTOR);
m_standardPercent = val1;
stack.push(val1);
break;

总结

  • 如果目标是绝对值模式,则当前变更不正确,应移除 val2
  • 如果目标是相对值模式,则需更新注释并优化常量使用。
  • 建议通过配置或参数控制百分比计算模式,以提高灵活性。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lichaofan2008, max-lvs

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@lichaofan2008
Copy link
Author

/merge

@deepin-bot deepin-bot bot merged commit 619a660 into linuxdeepin:release/eagle Jan 20, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants