Перейти к содержимому
Топаз6.0 · До релиза
Загрузка →

Поиск в документации

Спецификация 6.0

Выберите результат стрелками и нажмите Enter, чтобы открыть его.

Введите имя API, номер диагностики, правило или тему проекта.

    Диагностика TPZ4005

    Integer exponentiation received a negative exponent.

    Diagnostic and cause

    Ссылка

    Negative integer exponent

    Семейство
    topaz
    Этап
    run
    Код
    TPZ4005

    Причина и условия

    For two int operands, exponentiation rejects a negative exponent at runtime with TPZ4005. A nonnegative exponent is accepted when the exponent and result fit their required integer ranges.

    Действия

    Use a nonnegative integer exponent whose result fits int, or use float operands for a fractional result.

    Compiler phase: runtime.

    Compiler explanation: Integer exponentiation received a negative exponent.

    Message templates are Pending. The explanation above is not an observed CLI message.

    Observed for the candidate in Topaz 5.21.3. Execution

    • error[TPZ4005]: integer exponent must be non-negative; use float operands

    Integer exponentiation with two int operands rejects a negative exponent at runtime with TPZ4005. The guard runs before conversion to u32 and checked exponentiation.

    Правилоdiagnostics.tpz4005.p5.rule

    Integer exponentiation requires a nonnegative exponent

    For two int operands, exponentiation rejects a negative exponent at runtime with TPZ4005. A nonnegative exponent is accepted when the exponent and result fit their required integer ranges.

    Response

    Ссылка

    Use a nonnegative integer exponent whose result fits int, or use float operands for a fractional result.

    Reproduction and verification

    Ссылка

    Rejected program

    Ссылка
    example.tpzRejected program
    1. function power(exponent: int) -> int {
    2. 2 ** exponent
    3. }
    4. power(-1)
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz run example.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения run. Ненулевой код завершения.

    • TPZ4005 →

      negative-integer-exponent at example.tpz:2:5

    Run these runtime diagnostic assertions with TOPAZ_BIN set using node docs/topaz-reference/templates/diagnostics-p5-runtime.product.mjs. The shared example observer currently evaluates check diagnostics.

    Repaired program

    Ссылка
    example.tpzRepaired program
    1. function power(exponent: int) -> int {
    2. 2 ** exponent
    3. }
    4. power(0)
    Ожидаемый выводКод завершения 0
    Нет стандартного вывода.
    $ topaz run example.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Run these runtime diagnostic assertions with TOPAZ_BIN set using node docs/topaz-reference/templates/diagnostics-p5-runtime.product.mjs. The shared example observer currently evaluates check diagnostics.

    Меню

    Загрузка →