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.
Связанное правило · Integer exponentiation requires a nonnegative exponent →Действия
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.
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
Ссылкаfunction power(exponent: int) -> int {2 ** exponent}power(-1)
Нет стандартного вывода.Ожидаемый результат
Ожидаемый результат
Этап отклонения run. Ненулевой код завершения.
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
Ссылкаfunction power(exponent: int) -> int {2 ** exponent}power(0)
Нет стандартного вывода.Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 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.