CPT — Compute

Description
Section titled “Description”CPT (Compute) evaluates a free-form expression and writes the result to Dest every scan its rung is true. One instruction replaces a chain of ADD, MUL and DIV blocks and the temporary tags between them. Use CPT for any calculation with more than one operation, for a function call such as SQR or SIN, or when the formula reads better as text than as three blocks. Do not use CPT for a plain two-operand sum or a single MOV; the dedicated block is clearer on the rung and costs less code. Compare by expression is CMP, which uses the same language and gates the rung instead of writing a value.
Operands
Section titled “Operands”| Operand | Type | Format | Valid Range | Required | Description |
|---|---|---|---|---|---|
| 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. |
| Expression | Text | Tags, numbers, operators, functions, parentheses | Must not be empty | Yes | The formula. |
Vocabulary:
| Kind | Accepted | Notes |
|---|---|---|
| Tags | Temp, TMR[0].ACC, Speeds[3], Status.3 |
Any numeric tag, member, element or INT/DINT bit. STRING tags cannot be used. |
| Numbers | 25, -3, 72.5, 0x1F |
Hexadecimal for masks. |
| Arithmetic | + - * | / |
| is the SLC 500 divide symbol; / also divides. No **; use XPY(base, exp). |
| Comparison | < > <= >= == != |
Each yields 1 or 0, usable as a number. |
| Bit operators | AND OR XOR NOT |
Bitwise, on whole numbers. |
| Functions | SQR ABS SIN COS TAN ASN ACS ATN LN LOG EXP DEG RAD XPY TRN |
Trig in radians. TRN truncates to a whole number. EXP and TRN have no block of their own. |
| Grouping | ( ) |
Use them freely; * and | bind tighter than + and -. |
Division is floating point. Every | or / in an expression divides as a REAL, whatever the operand types: 7 | 2 is 3.5. A whole-number Dest then truncates the final result toward zero, so 7 | 2 into an INT is 3, and 7 | 2 * 2 into an INT is 7, not 6. This differs from the DIV block, which divides whole numbers as whole numbers when Dest is a whole-number type.
Dest type. The expression is evaluated in floating point when any operand or division is involved. A REAL Dest keeps the fraction; a whole-number Dest truncates toward zero and wraps silently past its range. Trig and log results into an INT are 0 or ±1; give them a REAL.
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”The expression is evaluated with the current tag values and the result is written to Dest, every scan the rung is true. A function given an out-of-range argument (SQR of a negative, LN of 0, ASN of 2) yields 0 with no fault.
Postscan
Section titled “Postscan”Nothing.
Example
Section titled “Example”Scenario: A pressure transmitter feeds an analog input that reads 0 to 1023. The live zero of the transmitter sits at 512, and full scale is 1023, so the useful span is 512 counts. The operator display wants percent of span.
Tags:
Scale— Compute percent, BOOLRaw— Analog input counts, INTPercent— Percent of span, REAL
Rung 1:
—] [Scale———[CPT Percent (Raw-512)*100|512]———Scan 1 — Scale = 0. Raw reads 768. The rung is false: Percent holds 0. The face shows Dest with its live value beneath it, and the expression as typed; the tags inside the expression do not paint their values, so read them in the Tag Browser.

Scan 2 — Scale = 1. (768 − 512) × 100 ÷ 512 is written: Percent reads 50.

Type 640 into Raw and Percent reads 25. Had Percent been an INT, 25.0 would still be 25, but 700 counts would give 36 instead of 36.7188.
See Also
Section titled “See Also”- CMP — Compare by expression (the same language as a rung condition)
- SCP — Scale with Parameters (this example without writing the formula)
- DIV — Divide (whole-number division when that is what you want)
- Math Functions — the functions as standalone blocks
- Compute Instructions — Category index
Reserved names. A tag cannot be named after a function or keyword (Log, Exp, And), so an expression never confuses the two. The Tag Creator refuses such names.
Spaces. Optional. (Raw-512)*100|512 and (Raw - 512) * 100 | 512 are the same expression; the block shows what you typed.
Bits as values. Status.3 reads as 0 or 1, so Status.3 * 100 is a quick way to turn a bit into a full-scale number.
Comparison as arithmetic. (Temp > 60) * 5 is 5 when the test holds and 0 otherwise; a way to select between two values without a second rung.
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