Skip to main content
Sigil provides arbitrary precision number types—Integer and Decimal—for financial calculations that require exact arithmetic without overflow or rounding errors.

Integer Type

The Integer type provides 256-bit signed arbitrary precision integers.

Structure

Maximum value: 2^256 - 1 (roughly 115 quattuorvigintillion)

Creating Integers

Arithmetic Operations

Unchecked operations (panic on overflow):
Checked operations (return Result):

Comparisons

Conversions

When to Use Integer

Use Integer for:
  • Token balances
  • Large financial calculations
  • Vote counts
  • Pool liquidity amounts
  • Any value that might exceed u64 (18.4 quintillion)
  • Exact arithmetic requirements
Use u64 for:
  • Small counters
  • Block heights
  • Array indices
  • When you know the value fits in 64 bits

Decimal Type

The Decimal type provides arbitrary precision decimals for calculations requiring fractional values.

Structure

Creating Decimals

Operations

When to Use Decimal

Use Decimal for:
  • Price calculations
  • Percentage calculations
  • Logarithmic operations
  • Scientific calculations
Most contracts use Integer for exact arithmetic and avoid decimals entirely.

Example: Token Contract

Example: AMM Pool Math

Choosing Between Checked and Unchecked

Use checked operations when:
  • Working with user inputs
  • Complex calculations where overflow is possible
  • You want specific error messages for overflow
  • Financial calculations requiring exact results
Use unchecked operations when:
  • You’ve already validated the operation is safe
  • Performance is critical
  • The overflow would indicate a bug (panic is appropriate)
See the token contract example above for combining both approaches—validation with checked arithmetic, then unchecked operations after validation.

Common Patterns

Safe Division

Square Root for LP Tokens

Percentage Calculations

Comparison Utilities

Quick Reference

Number Types and Ranges

Integer
  • 256-bit signed arbitrary precision integers
  • Range: ±115_792_089_237_316_195_423_570_985_008_687_907_853_269_984_665_640_564_039_457
  • Maximum value: 2^256 - 1
Decimal
  • Arbitrary precision decimals with up to 18 decimal places
  • Range: ±(2^256 - 1) / 10^18
  • Full range: ±115_792_089_237_316_195_423_570_985_008_687_907_853_269_984_665_640_564_039_457.584_007_913_129_639_936

Arithmetic Operations

Both types support basic arithmetic operations (add, sub, mul, div) and comparisons. Unchecked (using operators):
Checked (using methods):

Advanced Operations

Integer:
  • .sqrt() - Square root (returns Result<Integer, Error>)
Decimal:
  • .log10() - Base-10 logarithm (returns Result<Decimal, Error>)
  • Additional operations to be expanded

Type Conversions