• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
      • Apt
      • Zfc
      • Acre
      • Milawa
      • Smtlink
      • Abnf
      • Vwsim
      • Isar
      • Wp-gen
      • Dimacs-reader
      • Pfcs
      • Legacy-defrstobj
      • C
      • Proof-checker-array
      • Soft
      • Farray
      • Rp-rewriter
      • Instant-runoff-voting
      • Imp-language
      • Sidekick
      • Ethereum
      • Leftist-trees
      • Java
      • Riscv
      • Taspi
      • Bitcoin
      • Zcash
      • Des
      • X86isa
      • Sha-2
      • Yul
      • Proof-checker-itp13
      • Regex
      • ACL2-programming-language
      • Json
      • Jfkr
      • Equational
      • Cryptography
      • Axe
      • Poseidon
      • Where-do-i-place-my-book
      • Aleo
        • Aleobft
        • Aleovm
        • Leo
          • Grammar
          • Early-version
            • Json2ast
            • Testing
            • Definition
              • Flattening
              • Abstract-syntax
              • Dynamic-semantics
                • Execution
                • Values
                • Dynamic-environments
                • Arithmetic-operations
                  • Integer-arithmetic-operations
                    • Op-int-rem-wrapped
                    • Op-int-div-wrapped
                    • Op-int-div
                    • Op-int-sub-wrapped
                    • Op-int-sub
                    • Op-int-mul-wrapped
                    • Op-int-mul
                    • Op-int-add-wrapped
                    • Op-int-add
                    • Op-int-rem
                    • Op-int-pow-wrapped
                    • Op-int-pow
                    • Op-int-abs-wrapped
                    • Op-int-neg
                    • Op-int-abs
                  • Field-arithmetic-operations
                  • Scalar-field-arithmetic-operations
                  • Group-arithmetic-operations
                  • Op-mul
                  • Op-add
                  • Op-sub-wrapped
                  • Op-sub
                  • Op-rem-wrapped
                  • Op-pow-wrapped
                  • Op-pow
                  • Op-mul-wrapped
                  • Op-div-wrapped
                  • Op-div
                  • Op-add-wrapped
                  • Op-rem
                  • Op-square-root
                  • Op-square
                  • Op-neg
                  • Op-inv
                  • Op-double
                  • Op-abs-wrapped
                  • Op-abs
                • Curve-parameterization
                • Shift-operations
                • Errors
                • Value-expressions
                • Locations
                • Input-execution
                • Edwards-bls12-generator
                • Equality-operations
                • Logical-operations
                • Program-execution
                • Ordering-operations
                • Bitwise-operations
                • Literal-evaluation
                • Type-maps-for-struct-components
                • Output-execution
                • Tuple-operations
                • Struct-operations
              • Compilation
              • Static-semantics
              • Concrete-syntax
      • Bigmems
      • Builtins
      • Execloader
      • Solidity
      • Paco
      • Concurrent-programs
      • Bls12-377-curves
    • Debugging
    • Community
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
    • Math
    • Testing-utilities
  • Arithmetic-operations

Integer-arithmetic-operations

Leo integer arithmetic operations.

These are negation (unary), absolute value and wrapped absolute value (unary), addition, subtraction, multiplication, division, remainder, and exponentiation, and wrapped versions of those six (all binary ops). The result has always the same type as the first operand.

The binary operations are currently only allowed on integers of the same type (there are no automatic conversions), except that any signed or unsigned integer value may be raised to the power of any unsigned integer value. The result type is always the common type, or the type of the base (i.e. first operand) for exponentiation.

Except for the -wrapped versions of operations, if the exact mathematical result is not representable in the result type, it is considered an error in the same way as division by zero. We defensively return an error indication when these events happen.

For the -wrapped versions of operations, if the exact mathematical result is not representable in the result type, then the return value is computed from the mathematical result by taking the low N bits if positive, or if negative by forming the sign-extended two's complement bit pattern and taking the low N bits of that. In either case, the resulting bitvector is then interpreted as an integer of the result type.

For example 127i8.add_wrapped(127i8) becomes 254, which has the bit pattern 1111 1110, which represents the returned value -2i8.

for another example, -128i8.add_wrapped(-2i8) becomes -130, which in two's complement requires 9 bits: 1 0111 1110. The low 8 bits are 0111 1110, which represents the returned value 126i8.

Subtopics

Op-int-rem-wrapped
Leo integer wrapped remainder operation.
Op-int-div-wrapped
Leo integer wrapped division operation.
Op-int-div
Leo integer division operation.
Op-int-sub-wrapped
Leo integer wrapped subtraction operation.
Op-int-sub
Leo integer subtraction operation.
Op-int-mul-wrapped
Leo integer wrapped multiplication operation.
Op-int-mul
Leo integer multiplication operation.
Op-int-add-wrapped
Leo integer wrapped addition operation.
Op-int-add
Leo integer addition operation.
Op-int-rem
Leo integer remainder operation.
Op-int-pow-wrapped
Leo integer wrapped exponentiation operation.
Op-int-pow
Leo integer exponentiation operation.
Op-int-abs-wrapped
Leo integer wrapped absolute value operation.
Op-int-neg
Leo integer negation operation.
Op-int-abs
Leo integer absolute value operation.