LogoLogo
Github
  • Overview
    • 📄Litepaper
  • GraphLinq Chain
    • Networks
      • Specs
        • Geth Client
        • Clique Consensus
      • GraphLinq Chain (Mainnet)
        • Wallet
          • Add GraphLinq Chain to Metamask
          • Add GraphLinq Chain To Ledger
        • RPC Public Nodes
        • Json-RPC API
        • Libraries
        • Execution Clients
        • Explorer
        • Status
    • GLQ
      • Allocation
      • Bridge
      • Rewards
  • 🎶Run a node
    • Installation
  • Dev tooling
    • Introduction
      • Vision
    • Graphs
      • What are Graphs and how do they work?
      • Creating a graph
      • File compression
      • Graph Cycle Costs
      • Node & Fees
    • Engine
      • Setting up the environment
      • Running an Engine locally
    • Dashboard Interface
      • Importing Graph/Template
      • Deploying a Graph
      • Managing Graph State
    • Blocks
      • Base Variable
        • Boolean
        • Decimal
        • Integer
        • KeyValue
        • Long
        • String
        • Get variable
        • Is Variable Exist
        • Set variable
        • Variable Portal
        • Secret String
      • Common
        • Entry Point
        • On Graph Start
        • Stop Graph
      • Time
        • Get Milliseconds Timestamp
        • Get Milliseconds Timestamp Offset
        • Get Timestamp
        • Get Timestamp Offset
        • Timer
        • Format Date
        • Millisecond Timestamp to Date
        • Timestamp to Date
        • Execution Time Interval
      • JSON
        • Last Node to JSON
        • Convert To JSON
        • Add JSON Property
        • Create JSON Object
        • JSON Deserialize To Array
        • JSON to JSON Object
        • Merge JSON
        • Serialize JSON Object
        • Serialize to JSON
      • Log
        • Print
      • WebSocket
        • WebSocket Client Close
        • WebSocket Client Connector
        • On WebSocket Client Disconnect
        • WebSock Receive Data Event
        • WebSocket Send Data
      • String
        • String Contains
        • Concat String
        • Replace String in String
      • Math
        • Subtract A - B
        • Add A + B
        • Ceiling
        • Divide A / B
        • Floor
        • Modulo A % B
        • Multiply A * B
        • Percentage Difference
        • Round
      • HTTP
        • Array To Body Values
        • Array To JSON Body
        • Put HTTP Request
        • Post HTTP Request
        • Get HTTP Request
        • Delete HTTP Request
      • Function
        • Function Block
        • Add Function Parameter
        • Set Function Result
        • Call Function
        • Get Function Result Parameter
        • Get Function Parameter
      • Transformers
        • String to Base64
      • Data
      • CSV
      • Base Condition
        • Decimal Branch
        • Integer Branch
        • String Branch
        • Boolean Branch
      • Range Condition
        • Decimal Range Branch
      • Array
        • Add Array Element
        • Clear Array
        • Create Array
        • Each Element In Array
        • Get Array Element At Index
        • Get Array Size
        • Keep Last X Elements In Array
      • Dictionary
      • Hosted API
    • Blocks (Messaging)
      • Twitter
      • Twitch
      • Telegram
      • SMTP
      • ShortenURL
      • PushOver
      • PushBullet
      • OpenAI
      • Discord
        • Add Emoji On Message
        • Send Discord Channel File
        • Add Role User
        • On Discord Channel Message
        • On Reaction Added Message
        • On Reaction Removed Message
        • Remove Role User
        • Reply Private Discord Message
        • Send Discord Channel Message
        • Discord Connector
        • On Discord Private Message
    • Blocks (Exchange)
      • Binance
      • Bitfinex
      • Bittrex
      • CoinEx
      • CoinGecko
        • Get CoinGecko Coin
      • Huobi
      • Kraken
      • KuCoin
      • LiveCoinWatch
      • MXC
    • Blocks (Blockchains)
      • Avalanche
        • Network Blocks
          • Avalanche Connector
          • Get Block Parameters
          • Get Transaction Parameters
          • On Avalanche Block
          • On Avalanche Transaction
        • Avascan
          • Get Avascan Supply
          • Get Avascan Global Stats
          • Get Avascan Staking Stats
          • Get Avascan Burned Fees
        • SnowTrace
          • SnowTrace Connector
          • Get ERC-20 Balance For Contract
          • Get ERC-20 Token Supply
          • Get Total AVAX on C-Chain
          • Get AVAX Balance Single Address
      • Binance Smart Chain
        • Network Blocks
          • Binance Smart Chain Connector
          • On Binance Smart Chain Block
          • On Binance Smart Chain Transaction
          • On Binance Smart Chain Wallet Transaction
        • BEP20 Blocks
          • Create BEP20 Token
          • Deploy BEP20 Token
      • Elrond
        • Elrond Connector
        • Get Elrond HyperBlock By Hash
        • Get Elrond Transaction
        • Get Elrond Wallet Balance
      • Ethereum
        • Ethereum Connector
        • On Ethereum Block
        • On Ethereum Transaction
        • On Ethereum Wallet Transaction
        • Estimate Gas Price
        • Get Ether Balance
        • Get Block Parameters
        • Get Transaction Parameters
        • Etherscan
          • Etherscan Connector
          • Etherscan Get Gas Price
        • Ethereum Managed Wallet
          • Get Personal Managed Wallet
        • Ethereum ERC20
          • Get ERC20 Holders
          • Get ERC20 Balance
          • Get ERC20 Information
          • Create ERC20 Token
          • Deploy ERC20 Token
        • Ethereum NFT
          • Create NFT Contract
          • Deploy NFT Contact
          • Create New Mintable NFT Token
          • Deploy New Mintable NFT Token
      • Polygon
        • Polygon Connector
      • Quickswap
        • Get Quickswap Pair Price
        • Get Quickswap Token Price
        • Get Quickswap LP Token
        • Get Quickswap LP Token Price
        • On Quickswap Swap
        • On Quickswap Sync
      • Unicrypt
        • Get Unicrypt Locked Token Parameters
        • Get Unicrypt Locked Tokens
        • Get Unicrypt Total Locked Liquidity
        • Get Unicrypt All LP Locked Tokens Address
        • On Unicrypt Deposit
      • Uniswap
        • Get Uniswap LP Token
        • Get Uniswap LP Token Price
        • Uniswap Get Pair Price
        • Get Uniswap Token Price
        • On Uniswap Swap
        • On Uniswap Sync
      • Solana
    • Blocks (Charting)
      • Generate Time Series One Line Chart
      • Generate Time Series Two Line Chart
    • Blocks (Machine Learning)
      • Spam Detection
      • Sentiment Analysis
    • Node Connector Colors
      • Strings & Variables
      • Execution Logic (Yellow)
      • Integers (orange)
      • Booleans (pink)
    • Block Execution Order
      • Additional Block Execution
    • Block Color
      • Colors & Meaning
    • Block Type Overview
      • Function Type
      • Entry Point Type
      • Event Trigger Type
      • Variable Type
      • Condition Type
      • Connector Type
  • Nocode Users
    • Instant Deploy Wizard
    • GraphLinq Marketplace
  • Twitter
  • Medium
  • Github
  • GraphLinq Explorer
  • Audit Report
Powered by GitBook
On this page
  • Block Description
  • Input Parameters
  • Output
  • Example Use Case
  • Conclusion
  • More Information
  • Full Example
  1. Dev tooling
  2. Blocks
  3. Math

Modulo A % B

Calculate the remainder after dividing one numeric value

The Modulo A % B block in the GraphLinq IDE is a versatile mathematical block used to calculate the remainder after dividing one numeric value (A) by another (B). This block is particularly useful for handling cyclic or repetitive patterns, as well as determining even or odd numbers.

Block Description

The Modulo A % B block belongs to the Math blocks category in the GraphLinq IDE. Like other blocks in this category, it is a non-executive block, meaning it does not have yellow connectors and is implicitly called when its output is needed by other blocks during graph execution.

Input Parameters

The Modulo A % B block requires two input parameters:

  1. A (Numeric Type): The A input represents the dividend or the numeric value from which the remainder is calculated.

  2. B (Numeric Type): The B input is the divisor, representing the numeric value used to divide A and calculate the remainder.

Both A and B inputs accept various numeric data types, such as decimals, integers, and longs. It is essential to ensure that the B input is not set to zero, as division by zero is undefined and may result in errors in the graph's execution.

Output

The Modulo A % B block outputs the remainder obtained by dividing the value of input A by the value of input B. The output is of the same data type as the inputs and represents the result of the modulo operation.

Example Use Case

Let's explore a practical example of how the Modulo A % B block can be used within a graph:

  1. The graph receives a series of timestamp values (A) representing events.

  2. The Modulo A % B block is called, taking the timestamp values (A) as the dividend and a fixed value (B), such as 24, as the divisor.

  3. The block calculates the remainder when each timestamp is divided by 24, representing the hours of the day.

  4. The output represents the hours of the day (0 to 23) for each event timestamp, indicating the occurrence of events within different hours.

In this example, the Modulo A % B block helps identify the cyclic pattern of events throughout the day, providing valuable insights into the timing and frequency of occurrences.

Conclusion

The Modulo A % B block is a valuable mathematical tool in the GraphLinq IDE, enabling developers to perform modulo operations and extract remainders from numeric values. Its versatility makes it suitable for various applications, including time-related calculations, periodic event analysis, and determining even or odd numbers. By leveraging the Modulo A % B block, developers can efficiently handle cyclic patterns and gain valuable information from numeric data within their graphs.


More Information

The Modulo A % B block in the GraphLinq IDE performs the modulo operation on two given numeric values "A" and "B." The modulo operation calculates the remainder after dividing "A" by "B." This block is useful for obtaining the remainder of a division and is particularly relevant in scenarios where repetitive patterns or cyclical behaviors need to be identified.

Block Details

The Modulo A % B block has two input parameters, "A" and "B," representing the numeric values for which the modulo operation is to be performed. Both "A" and "B" can be of various numeric data types, such as decimal, integer, or long.

Execution

As with other block types in the Math category, the Modulo A % B block is non-executive. It does not have yellow connectors and is implicitly called whenever its output is needed as input by other executing blocks. When the Modulo A % B block's output is required in a graph, it performs the modulo operation on the input values "A" and "B" and provides the remainder as output.

Use Case

The Modulo A % B block finds applications in various fields, including computer programming, finance, and cryptography. In computer programming, it is used for tasks such as checking if a number is even or odd, generating random numbers with a specific range, and implementing algorithms for handling cyclical behaviors or circular data structures.

Example

Let's consider an example to illustrate the usage of the Modulo A % B block. Suppose we have a graph that simulates a clock with hours, minutes, and seconds. The graph takes the total number of seconds as input and needs to calculate the equivalent time in hours, minutes, and remaining seconds.

To achieve this, we can use the Modulo A % B block. First, we divide the total number of seconds by 3600 (the number of seconds in an hour) to calculate the hours. Then, we take the remainder after this division using the Modulo A % B block to find the remaining seconds. Next, we divide this remainder by 60 (the number of seconds in a minute) to calculate the minutes.

By using the Modulo A % B block, we can efficiently determine the cyclical components of the clock, ensuring that the time representation is accurate and conforms to the conventional time format.

The Modulo A % B block's ability to calculate remainders is invaluable in various scenarios where cyclical or repetitive patterns need to be analyzed or managed. It offers developers a powerful tool for handling modulo operations within their graphs, contributing to the versatility and functionality of their applications.


Full Example

Modulo A % B blocks output the result of a modulo operation* of two given numbers.

As you might imagine, Modulo A % B blocks have two input parameters called "A" and "B". In the division that determines the output of the modulo operation, "A" is the numerator and "B" is the denominator. Both of these input parameters should be of the integer data type.

One of the most common uses of the modulo operator is as a divisibility check for the purpose of tracking every nth instance of something. For example, say we want to detect programatically if we are in a fiscal quarter end month. Those happen every 3 months; in other words, they happen in every month whose number is divisible by 3. Whenever a number is divisible by another, the result of the first number % the second number will always be 0. So, we can simply check if [current month] % 3 is equal to 0. If so, then we are in a fiscal quarter end month (3, 6, 9, or 12).

We use a similar technique in the graph below to detect every 100th Bitcoin block added to the chain:

In the example above, we use a Discord bot to send a message in a Discord channel that contains some data about the most recent Bitcoin block (the block height, the number of transactions, and the amount transacted). However, we don't want this to happen for every single Bitcoin block, as there are about 6 blocks added every hour, and we don't want to flood our Discord channel with 150 messages each day about new blocks. Instead, we would like to send these Discord notifications only for every 100th block added, so that our channel will be updated about Bitcoin block production only once or twice a day, which is much more reasonable.

The On Bitcoin Block event block will fire every time a new Bitcoin block is added to the chain. The "Height" output parameter represents the total amount of blocks on the Bitcoin chain (ie: the block number for the most recent block). If we take the modulo of that number and 100, the result will be 0 only when the block height is some multiple of 100, like 500, 6000, or 765400

Whenever the block height does happen to be a multiple of 100, then we simply use a chain of Replace String In String blocks to build a message string containing the data we're interested in, and then send it to our Discord channel via some bot we control using a Send Discord Channel Message block.

*Modulo (%) operations are arithmetic operations between two operands that return the remainder after a division of the first operand by the second. For example, 7 % 3 = 1, because 3 fits into 7 2 full times, which leaves a remainder of 1. This operation is often used to determine if given numbers are even or odd, multiples/factors of other numbers, or prime.

PreviousFloorNextMultiply A * B

Last updated 1 year ago

So, we use our Modulo A % B block to calculate the modulo between the current block height and the number 100, and then we use an to check if the result equals 0; only if it does do we proceed to build and send our Discord message. So, the Integer Branch the block will only call the block once for every 100 times that the On Bitcoin Block event fires, thanks to our modulo check.

Integer Branch
Send Discord Channel Message