XPY — X to the Power of Y

Description
Section titled “Description”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.
Operands
Section titled “Operands”| 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.
Scan Behavior
Section titled “Scan Behavior”Prescan
Section titled “Prescan”Nothing. Dest keeps its power-up value.
Rung-condition-in is false
Section titled “Rung-condition-in is false”The instruction does nothing. Dest holds its last value.
Rung-condition-in is true
Section titled “Rung-condition-in is true”Both sources are read, the power is computed and written to Dest every scan the rung is true.
Postscan
Section titled “Postscan”Nothing.
Example
Section titled “Example”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, BOOLBase— Always 2 here, INTExponent— Bit number, INT (Expitself 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.

Scan 2 — Calc_Pow = 1. Power reads 1024.

Power is a DINT so that Exponent can go to 30. In an INT the weight would wrap at bit 15.
See Also
Section titled “See Also”- 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