waves_logo Docs
  • Ride Programming Language
    Ride Programming Language
  • Getting Started
    Getting Started
  • Syntax Basics
    • Directives
      Directives
    • Definition
      Definition
    • Expression
      Expression
    • Constant
      Constant
    • Variable
      Variable
    • Function
      Function
    • Exception
      Exception
    • Comment
      Comment
    Syntax Basics
  • Script Types
    • dApp Script
      • Annotations
        Annotations
      • Callable Function
        Callable Function
      • Verifier Function
        Verifier Function
      dApp Script
    • Account Script
      Account Script
    • Asset Script
      Asset Script
    Script Types
  • Standard Library
    Standard Library
  • Data types
    • Boolean
      Boolean
    • ByteVector
      ByteVector
    • Int
      Int
    • String
      String
    • Unit
      Unit
    • List
      List
    • Tuple
      Tuple
    • Union
      Union
    Data types
  • Structures
    • Script Actions
      • BinaryEntry (v4)
        BinaryEntry (v4)
      • BooleanEntry (v4)
        BooleanEntry (v4)
      • Burn (v4)
        Burn (v4)
      • DataEntry (v3)
        DataEntry (v3)
      • DeleteEntry (v4)
        DeleteEntry (v4)
      • IntegerEntry (v4)
        IntegerEntry (v4)
      • Issue (v4)
        Issue (v4)
      • Reissue (v4)
        Reissue (v4)
      • ScriptTransfer (v3 and v4)
        ScriptTransfer (v3 and v4)
      • SponsorFee (v4)
        SponsorFee (v4)
      • StringEntry (v4)
        StringEntry (v4)
      Script Actions
    • Script Results (v3)
      • ScriptResult
        ScriptResult
      • TransferSet
        TransferSet
      • WriteSet
        WriteSet
      Script Results (v3)
    • Common Structures
      • Address
        Address
      • Alias
        Alias
      • Asset
        Asset
      • AssetPair
        AssetPair
      • AttachedPayment
        AttachedPayment
      • BalanceDetails
        BalanceDetails
      • BlockInfo
        BlockInfo
      • Invocation
        Invocation
      • Order
        Order
      • Transfer
        Transfer
      Common Structures
    • Transaction Structures
      • BurnTransaction
        BurnTransaction
      • CreateAliasTransaction
        CreateAliasTransaction
      • DataTransaction
        DataTransaction
      • ExchangeTransaction
        ExchangeTransaction
      • GenesisTransaction
        GenesisTransaction
      • InvokeScriptTransaction
        InvokeScriptTransaction
      • IssueTransaction
        IssueTransaction
      • LeaseCancelTransaction
        LeaseCancelTransaction
      • LeaseTransaction
        LeaseTransaction
      • MassTransferTransaction
        MassTransferTransaction
      • ReissueTransaction
        ReissueTransaction
      • SetAssetScriptTransaction
        SetAssetScriptTransaction
      • SetScriptTransaction
        SetScriptTransaction
      • SponsorFeeTransaction
        SponsorFeeTransaction
      • TransferTransaction
        TransferTransaction
      • UpdateAssetInfoTransaction
        UpdateAssetInfoTransaction
      Transaction Structures
    Structures
  • Built-in Variables
    Built-in Variables
  • Built-in Functions
    • Account Data Storage Functions
      Account Data Storage Functions
    • Blockchain Functions
      Blockchain Functions
    • Byte Array Functions
      Byte Array Functions
    • Converting Functions
      Converting Functions
    • Data Transaction Functions
      Data Transaction Functions
    • Decoding Functions
      Decoding Functions
    • Encoding Functions
      Encoding Functions
    • Exception Functions
      Exception Functions
    • Hashing Functions
      Hashing Functions
    • List Functions
      List Functions
    • Math Functions
      Math Functions
    • String Functions
      String Functions
    • Union Functions
      Union Functions
    • Verification Functions
      Verification Functions
    Built-in Functions
  • Operators
    Operators
  • Pattern Matching: match-case
    Pattern Matching: match-case
  • Interations with FOLD<N>
    Interations with FOLD<N>
  • Limitations
    • Complexity
      Complexity
    • Data Weight
      Data Weight
    Limitations
  • Version 5 (Stagenet)
    • dApp-to-dApp Invocation
      dApp-to-dApp Invocation
    • Strict Variable
      Strict Variable
    • Callable Function
      Callable Function
    • Data types
      • Any
        Any
      • BigInt
        BigInt
      • Boolean
        Boolean
      • ByteVector
        ByteVector
      • Int
        Int
      • String
        String
      • Unit
        Unit
      • List
        List
      • Tuple
        Tuple
      • Union
        Union
      Data types
    • Structures
      • Script Actions
        • BinaryEntry
          BinaryEntry
        • BooleanEntry
          BooleanEntry
        • Burn
          Burn
        • DeleteEntry
          DeleteEntry
        • IntegerEntry
          IntegerEntry
        • Issue
          Issue
        • Lease
          Lease
        • LeaseCancel
          LeaseCancel
        • Reissue
          Reissue
        • ScriptTransfer
          ScriptTransfer
        • SponsorFee
          SponsorFee
        • StringEntry
          StringEntry
        Script Actions
      • Common Structures
        • Address
          Address
        • Alias
          Alias
        • Asset
          Asset
        • AssetPair
          AssetPair
        • AttachedPayment
          AttachedPayment
        • BalanceDetails
          BalanceDetails
        • BlockInfo
          BlockInfo
        • Invocation
          Invocation
        • Order
          Order
        • Transfer
          Transfer
        Common Structures
      • Transaction Structures
        • BurnTransaction
          BurnTransaction
        • CreateAliasTransaction
          CreateAliasTransaction
        • DataTransaction
          DataTransaction
        • ExchangeTransaction
          ExchangeTransaction
        • GenesisTransaction
          GenesisTransaction
        • InvokeScriptTransaction
          InvokeScriptTransaction
        • IssueTransaction
          IssueTransaction
        • LeaseCancelTransaction
          LeaseCancelTransaction
        • LeaseTransaction
          LeaseTransaction
        • MassTransferTransaction
          MassTransferTransaction
        • ReissueTransaction
          ReissueTransaction
        • SetAssetScriptTransaction
          SetAssetScriptTransaction
        • SetScriptTransaction
          SetScriptTransaction
        • SponsorFeeTransaction
          SponsorFeeTransaction
        • TransferTransaction
          TransferTransaction
        • UpdateAssetInfoTransaction
          UpdateAssetInfoTransaction
        Transaction Structures
      Structures
    • Built-in Variables
      Built-in Variables
    • Built-in Functions
      • Account Data Storage Functions
        Account Data Storage Functions
      • Blockchain Functions
        Blockchain Functions
      • Byte Array Functions
        Byte Array Functions
      • Converting Functions
        Converting Functions
      • Data Transaction Functions
        Data Transaction Functions
      • Decoding Functions
        Decoding Functions
      • Encoding Functions
        Encoding Functions
      • Exception Functions
        Exception Functions
      • Hashing Functions
        Hashing Functions
      • dApp-to-dApp Invocation Function
        dApp-to-dApp Invocation Function
      • List Functions
        List Functions
      • Math Functions
        Math Functions
      • String Functions
        String Functions
      • Union Functions
        Union Functions
      • Verification Functions
        Verification Functions
      Built-in Functions
    • Operators
      Operators
    • Limitations
      • Data Weight
        Data Weight
      Limitations
    Version 5 (Stagenet)
  • Ride Components
    Ride Components
  • Script performance tests
    Script performance tests
      • English
      • Русский
      On this page
        • fraction
        • log
        • median
        • pow
        • Rounding Variables
      waves_logo Docs

          # Math functions

          Name Description Complexity
          fraction Multiplies and divides integers to avoid overflow 1
          log Calculates logarithm of a number with a given base 100
          median Returns the median of a list of integers 20
          pow Raises a number to a given power 100

          # fraction

          Multiplies integers a, b and divides the result by the integer c to avoid overflow.

          Fraction a × b / c should not exceed the maximum value of the integer type 9,223,372,036,854,755,807.

          fraction(a: Int, b: Int, c: Int): Int
          

          # Parameters

          Parameter Description
          a: Int Integer a
          b: Int Integer b
          c: Int Integer c

          # Example

          Lets assume that:

          a = 100,000,000,000,

          b = 50,000,000,000,000,

          c = 2,500,000.

          The following formula, with operators * and /, fails due to overflow:

          a * b / c #  overflow, because a × b exceeds max integer value
          

          The fraction function with no overflow:

          fraction(a, b, c) # Result: 2,000,000,000,000,000,000
          

          # log

          Calculates logba.

          log(value: Int, vp: Int, base: Int, bp: Int, rp: Int, round: UP|DOWN|CEILING|FLOOR|HALFUP|HALFDOWN|HALFEVEN): Int
          

          In Ride, there is no data type with the floating point. That is why, for example, when you need to calculate log2.716.25 then the number value = 1625, vp = 2 and the base = 27, bp = 1.

          More examples:

          a value vp
          16.25 1625 2
          5 5 0
          5.00 500 2

          If the log function returns, for example, 2807, and the parameter of function rp = 3, then the result is 2.807; in the number 2807 the last 3 digits is a fractional part.

          # Parameters

          Parameter Description
          value: Int Number a without decimal point
          vp: Int Number of decimals of a
          base: Int Logarithm base b without decimal point
          bp: Int Number of decimals of b
          rp: Int Number of decimals in the resulting value, from 0 to 8 inclusive. Specifies the accuracy of the calculated result.
          round: UP|DOWN|CEILING|FLOOR|HALFUP|HALFDOWN|HALFEVEN One of the rounding variables

          # Examples

          log2.716.25 = 2.807035421...

          log(1625, 2, 27, 1, 2, HALFUP) # Function returns 281, so the result is: 2.81
          log(1625, 2, 27, 1, 5, HALFUP) # Function returns 280703542, so the result is: 2.80704
          
          log(0, 0, 2, 0, 0, HALFUP)     # Result: -Infinity
          

          # median

          Returns the median of the list. The list can't be empty, otherwise, the function fails.

          ⚠️ The median function is added in Standard library version 4.

          median(arr: List[Int]): Int
          

          # Parameters

          Parameter Description
          arr: List[Int] List of integers

          # Examples

          median([1, 2, 3])         # Returns 2
          median([2, 4, 9, 20])     # Returns 6
          median([-2, -4, -9, -20]) # Returns -7
          

          # pow

          Calculates ab.

          pow(base: Int, bp: Int, exponent: Int, ep: Int, rp: Int, round: UP|DOWN|CEILING|FLOOR|HALFUP|HALFDOWN|HALFEVEN): Int
          

          In Ride, there is no data type with the floating point. That is why, for example, when you need to calculate, 16.252.7, then the number base = 1625, bp = 2, and the exponent = 27, ep = 1.

          If the pow function returns, for example, 18591057, and the parameter of function rp = 4, then the result is 1859.1057; in the number 18591057 the last 4 digits is a fractional part.

          # Parameters

          Parameter Description
          base: Int Number a without decimal point
          bp: Int Number of decimals of a
          exponent: Int Exponent b without decimal point
          ep: Int Number of decimals of b
          rp: Int Number of decimals in the resulting value. Specifies the accuracy of the calculated result. The value of the variable can be 0 to 8 integer inclusive
          round: UP|DOWN|CEILING|FLOOR|HALFUP|HALFDOWN|HALFEVEN One of the rounding variables

          # Examples

          16.252.7 = 1859,1057168...

          pow(1625, 2, 27, 1, 2, HALFUP) # function returns 185911, so the result is: 1859.11
          pow(1625, 2, 27, 1, 5, HALFUP) # function returns 185910572, so, the result is: 1859.10572
          

          # Rounding Variables

          Below is the list of built-in rounding variables. Every variable corresponds to the rounding method (opens new window).

          The rounding variables are only used as the parameters of functions log and pow.

          Name Description
          CEILING Rounds towards positive infinity
          DOWN Rounds towards zero
          FLOOR Rounds towards negative infinity
          HALFDOWN Rounds towards the nearest integer; if the integers are equidistant - rounds towards zero
          HALFEVEN Rounds towards the nearest integer; if the integers are equidistant - rounds towards the nearest even integer
          HALFUP Rounds towards the nearest integer; if the integers are equidistant - rounds away from zero
          UP Rounding away from zero

          # Examples

          Input number/Rounding method UP DOWN CEILING FLOOR HALFUP HALFDOWN HALFEVEN
          5.5 6 5 6 5 6 5 6
          2.5 3 2 3 2 3 2 2
          1.6 2 1 2 1 2 2 2
          1.1 2 1 2 1 1 1 1
          1.0 1 1 1 1 1 1 1
          -1.0 -1 -1 -1 -1 -1 -1 -1
          -1.1 -2 -1 -1 -2 -1 -1 -1
          -1.6 -2 -1 -1 -2 -2 -2 -2
          -2.5 -3 -2 -2 -3 -3 -2 -2
          -5.5 -6 -5 -5 -6 -6 -5 -6
          List Functions
          String Functions
          List Functions
          String Functions