Interest Protocol
  • 👋Welcome to Interest Protocol
  • Overview
    • Sui💧
      • Contracts
        • Memez
        • Libs 📚
      • Suicoins
        • Swap
        • Dollar-Cost Averaging (DCA)
        • Airdrop
          • Suiplay Airdrop
        • Incinerator
        • Send
        • Merger
        • Suicoins Terminal
      • Memez.gg
        • Coins on Memez.GG
        • Memez.Fun
          • SDK
            • Pump API
            • Interfaces
          • Configuration
          • Migrators
          • Bonding Curve
          • Fees
      • IPX Coin Standard
    • Movement
      • Interest Protocol Decentralized Exchange (DEX)
        • Key Features
        • Core Innovations
      • sr-AMM
      • Token
        • Tokenomics
        • Utility
      • GTM
    • Audits
    • Security
    • Deprecated
      • Coin X Oracle 🔮
        • Pyth Network
        • Switchboard
      • Sui Tears 💧
        • Airdrop
          • Airdrop
          • Airdrop Utils
          • Linear Vesting Airdrop
        • Capabilities
          • Access Control
          • Owner
          • Quest
          • Timelock
        • Collections
          • Bitmap
          • Coin Decimals
        • DeFi
          • Oracle
          • Farm
          • Fund
          • Linear Vesting Wallet
          • Linear Clawback Vesting Wallet
          • Vesting
        • Governance
          • DAO
          • DAO Admin
          • DAO Treasury
        • Utils
          • ASCII
          • Comparator
          • Merkle Proof
          • Vectors
        • Math
          • Fixed Point 64
          • Fixed Point Roll
          • Fixed Point Wad
          • Int
          • Math64
          • Math128
          • Math256
      • CLAMM🐚
        • Hooks
      • Whitepapers
  • Glossary
Powered by GitBook
On this page
  • Interface
  • roll
  • try_mul_down
  • try_mul_up
  • try_div_down
  • try_div_up
  • mul_down
  • mul_up
  • div_down
  • div_up
  • to_roll

Was this helpful?

Export as PDF
  1. Overview
  2. Deprecated
  3. Sui Tears 💧
  4. Math

Fixed Point Roll

A set of functions to operate over u64 numbers with 1e9 precision.

Interface

roll

It returns 1 ROLL - 1_000_000_000.

public fun roll(): u64
  • @return u64. 1e9

try_mul_down

It tries to x * y / 1_000_000_000 rounding down. It returns zero instead of throwing an overflow error.

public fun try_mul_down(x: u64, y: u64): (bool, u64)
  • @param x: The first operand.

  • @param y: The second operand.

  • @return bool. If the operation was successful.

  • @return u64. The result of x * y / 1_000_000_000.

try_mul_up

It tries to x * y / 1_000_000_000 rounding up. It returns zero instead of throwing an overflow error.

public fun try_mul_up(x: u64, y: u64): (bool, u64)
  • @param x: The first operand.

  • @param y: The second operand.

  • @return bool. If the operation was successful.

  • @return u64. The result of x * y / 1_000_000_000.

try_div_down

It tries to x * 1_000_000_000 / y rounding down. It returns zero instead of throwing an overflow error.

public fun try_div_down(x: u64, y: u64): (bool, u64)
  • @param x: The first operand.

  • @param y: The second operand.

  • @return bool. If the operation was successful.

  • @return u64. The result of x * 1_000_000_000 / y.

try_div_up

It tries to x * 1_000_000_000 / y rounding up. It returns zero instead of throwing an overflow error.

public fun try_div_up(x: u64, y: u64): (bool, u64)
  • @param x: The first operand.

  • @param y: The second operand.

  • @return bool. If the operation was successful.

  • @return u64. The result of x * 1_000_000_000 / y.

mul_down

x * y / 1_000_000_000 rounding down.

public fun mul_down(x: u64, y: u64): u64
  • @param x: The first operand.

  • @param y: The second operand.

  • @return u64. The result of x * y / 1_000_000_000.

Aborts

  • On overflow. If the result is over the maximum u256 number.

mul_up

x * y / 1_000_000_000 rounding up.

public fun mul_up(x: u64, y: u64): u64
  • @param x: The first operand.

  • @param y: The second operand.

  • @return u64. The result of x * y / 1_000_000_000.

Aborts

  • On overflow. If the result is over the maximum u256 number.

div_down

x * 1_000_000_000 / y rounding down.

public fun div_down(x: u64, y: u64): u64
  • @param x: The first operand.

  • @param y: The second operand.

  • @return u64. The result of x * 1_000_000_000 / y.

Aborts

  • On zero division.

div_up

x * 1_000_000_000 / y rounding up.

public fun div_up(x: u64, y: u64): u64
  • @param x: The first operand.

  • @param y: The second operand.

  • @return u64. The result of x * 1_000_000_000 / y.

Aborts

  • On zero division.

to_roll

It converts x precision to a ROLL, a number with a precision of 1e9.

public fun to_roll(x: u64, decimal_factor: u64): u64
  • @param x: The value to be converted.

  • @param decimal_factor: The current decimal scalar of x.

  • @return u64. The result of x * 1_000_000_000 / y.

Aborts

  • decimal_factor is zero.

PreviousFixed Point 64NextFixed Point Wad

Last updated 1 year ago

Was this helpful?