Skip to content
Topaz6.0 · Before release
Download

Search documentation

Specification 6.0 · Not released · Tested product 5.21.3

Use arrow keys to choose a result. Press Enter to open.

Type an API name, diagnostic number, rule, or project topic.

    Diagnostics

    TPZ4005: Negative integer exponent

    Integer exponentiation received a negative exponent.

    Diagnostic and cause

    Link

    Negative integer exponent

    Family
    topaz
    Phase
    run
    Code
    TPZ4005

    Cause and conditions

    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.

    Source evidence

    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.

    Rulediagnostics.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.

    Source evidence

    Response

    Link

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

    Reproduction and verification

    Link

    Rejected program

    Link
    example.tpzRejected program
    1. function power(exponent: int) -> int {
    2. 2 ** exponent
    3. }
    4. power(-1)
    Expected outputNonzero exit
    No stdout.
    $ topaz run example.tpz · target product 5.21.3
    Expected result

    Expected result

    Rejection during run. Nonzero exit.

    • 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.

    Source evidence

    Repaired program

    Link
    example.tpzRepaired program
    1. function power(exponent: int) -> int {
    2. 2 ** exponent
    3. }
    4. power(0)
    Expected outputexit 0
    No stdout.
    $ topaz run example.tpz · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 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.

    Source evidence

    Menu

    Download