Skip to content

XPY — X to the Power of Y

Category
Compute
Type
Output
Availability
All platforms

XPY instruction block: Source A Base, Source B Exponent, Dest Power


XPY (X to the Power of Y) writes Source A raised to the power Source B to Dest every scan its rung is true. It is an output instruction with no state and no status bits. Use XPY for a bit weight (2 to the n), a square or cube without a chain of MULs, or a fractional exponent such as a pump affinity law. Do not reach for XPY to square a value that is used once; MUL X X is cheaper on an 8-bit controller, where a power is computed in floating point.


Operand Type Format Valid Range Required Description
Source A Any numeric tag, member, element or bit, or a literal Tag, Tag.Member, Tag[n], Tag.bit, or a literal Any resolvable numeric reference Yes The base, X.
Source B Same as Source A Same Any resolvable numeric reference Yes The exponent, Y.
Dest A writable numeric tag, member or element Tag, Tag.Member, Tag[n] SINT, INT, DINT or REAL; not a literal, not an input pin Yes Where the result is written.

Dest type. The power is computed in floating point and then stored in Dest’s type: a whole-number Dest truncates toward zero and wraps silently past its range. 2 to the 15th already exceeds an INT; use a DINT or a REAL. A negative base with a fractional exponent has no real result and writes 0.


Nothing. Dest keeps its power-up value.

The instruction does nothing. Dest holds its last value.

Both sources are read, the power is computed and written to Dest every scan the rung is true.

Nothing.


Scenario: A bit mask is built from a bit number: bit n has the weight 2 to the n.

Tags:

  • Calc_Pow — Compute the weight, BOOL
  • Base — Always 2 here, INT
  • Exponent — Bit number, INT (Exp itself is a reserved function name)
  • Power — Weight of that bit, DINT

Rung 1:

—] [Calc_Pow———[XPY Base Exponent Power]———

Scan 1 — Calc_Pow = 0. Base reads 2 and Exponent reads 10. The rung is false: Power holds 0.

Figure 1 — XPY rung false: Base 2, Exponent 10, Power 0, rung dark

Scan 2 — Calc_Pow = 1. Power reads 1024.

Figure 2 — XPY rung true: Power reads 1024, rung lit

Power is a DINT so that Exponent can go to 30. In an INT the weight would wrap at bit 15.


  • SQR — Square Root (an exponent of 0.5)
  • MUL — Multiply
  • CPT — Compute (XPY(base, exp) inside an expression; there is no ** operator)
  • Compute Instructions — Category index

Inside CPT. Write XPY(X, Y) with a comma. The ** operator is refused by the validator.

Precision. The result is a 32-bit float on most boards, about seven significant digits. 2 to the 30th is exact; 3 to the 20th is not.

The block never colours. Watch the rung wire and the Dest value line.

Applies to LadderIDE >=1.2.2 · Last reviewed 2026-09-11 · Screenshots verified 2026-09-11