본문으로 건너뛰기
토파즈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)
    기대 출력0이 아닌 종료 코드
    표준 출력 없음.
    $ topaz run example.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    거절 단계 run. 종료 코드가 0이 아닙니다.

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

    메뉴

    다운로드 →