Skip to main content

Addition

This node adds two numbers together and returns the result.

The Addition node performs mathematical addition with error handling and value validation.

The Addition node takes two numeric inputs and calculates their sum. It is a fundamental building block for any logic involving arithmetic. It includes built-in validation to ensure inputs are valid numbers and that the result stays within acceptable bounds (-1,000,000,000,000 to 1,000,000,000,000).

Inputs

Numbers

DataDescription
First NumberThe first number to add (default: 0). Must be a valid number within the allowed range.
Second NumberThe second number to add (default: 0). Must be a valid number within the allowed range.

Actions

SignalDescription
DoTriggers the addition calculation. The result is only updated when this signal is received.
ResetResets all inputs and the result to 0, and clears any errors.

Outputs

Data

DataDescription
ResultThe sum of the two input numbers.

Signals

SignalDescription
DoneTriggered when the calculation is successfully completed and the Result output has been updated.
Reset DoneTriggered when the Reset action is completed.

Usage

The Addition node is used for basic arithmetic operations in your application. It supports:

  • Integer and Decimal Addition: Handles both whole numbers and floating-point numbers.
  • Automatic Input Validation: Rejects non-numeric inputs immediately when they are set.
  • Range Checking: Prevents overflow/underflow by enforcing a safe range of ±1 trillion.
  • Error Handling: Logs errors to the console and prevents signal emission if inputs or results are invalid.

Example Use Cases

  1. Counter Logic: Incrementing a counter value.
    • Connect a variable (current count) to First Number.
    • Set Second Number to 1.
    • Trigger Do to increment.
  2. Financial Calculations: Adding prices, taxes, or fees.
    • Note: For precise financial calculations, be aware of standard floating-point arithmetic limitations in JavaScript.
  3. Game Scoring: Combining point values from different sources.
  4. Data Processing: Summing numeric values from user inputs or database records.

Detailed Behavior

  1. Input Setting: When First Number or Second Number is set, the node validates the value.
    • If the value is not a number (isNaN), an error is logged.
    • If the value exceeds 1,000,000,000,000 or is less than -1,000,000,000,000, an error is logged.
    • If an error occurs during input setting, the lastError state is set, preventing future calculations until resolved.
  2. Calculation: When Do is triggered:
    • The node checks if there are any existing errors. If so, it aborts.
    • It calculates First Number + Second Number.
    • It checks if the result is within the allowed range.
    • If valid, it updates Result and triggers Done.
    • If invalid, it logs an error and does not trigger Done.

Troubleshooting

  • No Output Signal: If you trigger Do but don't get a Done signal, check the console for errors. It is likely that one of your inputs is invalid or the result exceeded the ±1 trillion limit.
  • Incorrect Result: Ensure your inputs are numbers. String inputs might be coerced or cause unexpected behavior if not properly handled upstream, though this node attempts to validate them.
  • Resetting: If the node gets into an error state, triggering Reset will clear all values and errors, allowing you to start fresh.