Skip to content

Integer Binary Operator

Summary

  • Internal name: IntegerBinaryOps
  • Category: Arithmetic
  • Purpose: Apply a binary arithmetic operation on two integer values and store the result in a workflow variable.
  • Task type: Normal

Compatibility

  • Minimum AndroMate version: 1.1.0

  • Maximum AndroMate version: 1.1.0

  • Minimum Android: Android 13 (API 33)

  • Maximum Android tested: Android 16 (API 36)

  • Supported manufacturers:

    • ✅ Samsung (One UI 6.x / 7.x / 8.x)
    • ✅ Google Pixel (Android Stock)
    • ⚠️ Other manufacturers — not tested
  • Required permissions:

    • None

Detailed description

The Integer Binary Operator task applies an arithmetic operation between two integer operands (var_n1 and var_n2) and writes the result to a workflow variable (ops_output).

Both var_n1 and var_n2 support $workflow_variable references — resolved at runtime and parsed as int values before the operation is performed. Division (DIV) and modulo (MOD) perform integer arithmetic (fractional part discarded). Both throw ARITHMETIC-OPS-002 if var_n2 is 0.


Supported operations

The arithmetic_ops field is an integer code that selects the operation to apply between var_n1 and var_n2.

arithmetic_ops code Operation Description
1 ADD var_n1 + var_n2
2 SUB var_n1 - var_n2
3 MUL var_n1 × var_n2
4 DIV var_n1 ÷ var_n2 (integer division)
5 MOD var_n1 % var_n2 (remainder)
6 POW var_n1 ^ var_n2 (power)

Input parameters

Parameter Type Required Possible values Android Compatibility AndroMate Compatibility Default
var_n1 Integer Yes Any integer — supports $variable references Android 13 (API 33) → Android 16 (API 36) 1.1.0 → 1.1.0 0
var_n2 Integer Yes Any integer — supports $variable references Android 13 (API 33) → Android 16 (API 36) 1.1.0 → 1.1.0 0
arithmetic_ops Integer Yes 1 (ADD), 2 (SUB), 3 (MUL), 4 (DIV), 5 (MOD), 6 (POW) Android 13 (API 33) → Android 16 (API 36) 1.1.0 → 1.1.0

Output parameters

Field Type Trigger condition Android Compatibility AndroMate Compatibility Default
ops_output Integer (as String) Always — on successful operation Android 13 (API 33) → Android 16 (API 36) 1.1.0 → 1.1.0 <ANDROMATE_NULL_VALUE>

Exceptions

Code Trigger
ARITHMETIC-OPS-001 The arithmetic_ops code does not match any supported operation
ARITHMETIC-OPS-002 var_n2 is 0 and the operation is DIV (code 4) or MOD (code 5) — division by zero

Execution flowchart

flowchart TD
    Start([▶ IntegerBinaryOps]) --> ResolveAll[🔄 Resolve var_n1 and var_n2\nfrom workflow context]
    ResolveAll --> ValidateOps{arithmetic_ops code known?}
    ValidateOps -->|No| E1[❌ ARITHMETIC-OPS-001\nUnknown operator]

    ValidateOps -->|Yes| Switch{arithmetic_ops}

    Switch -->|1: ADD| AddOp["var_n1 + var_n2"]
    Switch -->|2: SUB| SubOp["var_n1 - var_n2"]
    Switch -->|3: MUL| MulOp["var_n1 × var_n2"]
    Switch -->|4: DIV| DivCheck{var_n2 == 0?}
    DivCheck -->|Yes| E2[❌ ARITHMETIC-OPS-002\nDivision by zero]
    DivCheck -->|No| DivOp["var_n1 ÷ var_n2"]
    Switch -->|5: MOD| ModCheck{var_n2 == 0?}
    ModCheck -->|Yes| E2
    ModCheck -->|No| ModOp["var_n1 % var_n2"]
    Switch -->|6: POW| PowOp["var_n1 ^ var_n2"]

    AddOp --> WriteOutput[💾 Write result to ops_output]
    SubOp --> WriteOutput
    MulOp --> WriteOutput
    DivOp --> WriteOutput
    ModOp --> WriteOutput
    PowOp --> WriteOutput

    WriteOutput --> Success([✅ TaskIntegerResult])
    E1 --> Error([❌ Exception])
    E2 --> Error

    style Start fill:#e3f2fd
    style Success fill:#c8e6c9
    style Error fill:#ffcdd2
    style E1 fill:#ffcdd2
    style E2 fill:#ffcdd2
    style ResolveAll fill:#fff9c4
    style AddOp fill:#f3e5f5
    style SubOp fill:#f3e5f5
    style MulOp fill:#f3e5f5
    style DivOp fill:#f3e5f5
    style ModOp fill:#f3e5f5
    style PowOp fill:#f3e5f5
    style WriteOutput fill:#c8e6c9

How it works:

  1. Resolve operands: var_n1 and var_n2 are resolved from the workflow context and parsed as int
  2. Validate operator: if arithmetic_ops is unknown, throws ARITHMETIC-OPS-001
  3. Check for division by zero: for DIV and MOD, if var_n2 is 0, throws ARITHMETIC-OPS-002
  4. Execute operation: the corresponding arithmetic operation is applied
  5. Store result: the result is written to ops_output
  6. Result: returns TaskIntegerResult on success

Code examples

Example 1 — Add two values

{
  "IntegerBinaryOps": [
    {
      "id": "1",
      "title": "Total latency",
      "var_n1": "$dns_rtt",
      "var_n2": "$http_rtt",
      "arithmetic_ops": 1,
      "ops_output": "$total_rtt"
    }
  ]
}

Stores $dns_rtt + $http_rtt in $total_rtt.


Example 2 — Compute difference

{
  "IntegerBinaryOps": [
    {
      "id": "2",
      "title": "RTT delta",
      "var_n1": "$current_rtt",
      "var_n2": "$baseline_rtt",
      "arithmetic_ops": 2,
      "ops_output": "$rtt_delta"
    }
  ]
}

Stores $current_rtt - $baseline_rtt in $rtt_delta.


Example 3 — Integer division

{
  "IntegerBinaryOps": [
    {
      "id": "3",
      "title": "Average RTT",
      "var_n1": "$total_rtt",
      "var_n2": "$sample_count",
      "arithmetic_ops": 4,
      "ops_output": "$avg_rtt"
    }
  ]
}

Stores $total_rtt ÷ $sample_count (integer division) in $avg_rtt.


Example 4 — Power

{
  "IntegerBinaryOps": [
    {
      "id": "4",
      "title": "Power of two",
      "var_n1": "2",
      "var_n2": "$exponent",
      "arithmetic_ops": 6,
      "ops_output": "$result"
    }
  ]
}

Stores 2 ^ $exponent in $result.


Input parameter details

1. Input parameter: var_n1 — Left operand

The left-hand integer operand. Supports $workflow_variable references — resolved at runtime and parsed as an int.

  • Default: 0
  • Supports variables: Yes

2. Input parameter: var_n2 — Right operand

The right-hand integer operand. Supports $workflow_variable references — resolved at runtime and parsed as an int.

Warning: must not be 0 when using DIV (code 4) or MOD (code 5) — throws ARITHMETIC-OPS-002.

  • Default: 0
  • Supports variables: Yes

3. Input parameter: arithmetic_ops — Operation code

Integer code selecting the binary operation to apply between var_n1 and var_n2.

Code Name Operation Notes
1 ADD var_n1 + var_n2
2 SUB var_n1 - var_n2
3 MUL var_n1 × var_n2
4 DIV var_n1 ÷ var_n2 Integer division — fractional part discarded
5 MOD var_n1 % var_n2 Remainder of integer division
6 POW var_n1 ^ var_n2 Power (exponentiation)
  • Default: — (required, no default — triggers ARITHMETIC-OPS-001 if unknown)

Output parameter details

ops_output — Operation result

Workflow variable name to store the integer result. Must be declared in the Start task.

Operation Value written
ADD var_n1 + var_n2
SUB var_n1 - var_n2
MUL var_n1 × var_n2
DIV var_n1 ÷ var_n2 (integer)
MOD var_n1 % var_n2
POW var_n1 ^ var_n2
  • Default: "" (result not stored if empty)

Complete JSON example

{
  "IntegerBinaryOps": [
    {
      "id": "1",
      "title": "Compute average RTT",
      "var_n1": "$total_rtt",
      "var_n2": "$sample_count",
      "arithmetic_ops": 4,
      "ops_output": "$avg_rtt"
    }
  ]
}