Easytrieve Math Functions Index

Math functions and operators extend beyond everyday ABS and rounding into powers, roots, and transcendental calculations used in statistical, scientific, and engineering batch jobs on mainframe data. Exponentiation operator ** raises values to powers in arithmetic expressions—COMPOUND = PRINCIPAL * RATE ** YEARS in simplified illustrative formulas. SQRT and logarithm builtins appear in Easytrieve Plus Application Reference where licensed. Operator precedence determines evaluation order: ** before * and / before + and -. Parentheses override for clarity. Math category complements numeric category—route variance checks to numeric ABS; route distance or standard deviation components to math. Division by zero and negative SQRT input cause runtime failures—guard with IF. This index catalogs math capabilities, contrasts operators with function calls, explains precedence with examples, and notes Report Generator limitations versus Plus catalogs for advanced names.

Progress0 of 0 lessons

Math in Easytrieve Expressions

Math happens inside arithmetic-expression on assignment and conditional lines. Operators + - * / ** combine numeric fields and literals. Function calls like SQRT(x) nest inside expressions when documented. Result type follows operand promotion rules—fractional results into integer-defined fields need ROUNDED TRUNCATED or INTEGER modifier on assignment.

Math Capabilities Index

Math operations index
OperationMechanismNotes
Addition+ operatorSee addition operator tutorial
Subtraction- operatorUnary minus in expressions
Multiplication* operatorScale propagation on P fields
Division/ operatorGuard zero divisor
Exponentiation** operatorPower precedence high
Square rootSQRT(expr)Plus—verify availability
LogarithmLOG(expr) per manualDomain positive only
Nested formulasParenthesesClarity and override precedence

Exponentiation With **

SIDE ** 2 squares a value for area calculations. BASE ** EXPONENT raises to arbitrary integer power—watch overflow when exponent large and base big. Non-integer exponents may require function form if documented. ** binds tighter than * so A * B ** 2 multiplies A by B squared not (A*B) squared unless parenthesized.

text
1
2
3
AREA = LENGTH ** 2 VOLUME = LENGTH ** 3 COMPOUND-FACTOR = (1 + RATE) ** PERIODS

Operator Precedence

Evaluation order (typical)
RankOperatorsExample
1 (tightest)**2 + 3 ** 2 → 11
2* /10 - 8 / 2 → 6
3 (loosest)+ -Left to right at same rank
Override( )(10 - 8) / 2 → 1

SQRT and Roots

SQRT returns square root for non-negative operand in documented implementations. Negative input causes runtime error—IF X GE 0 before assign. Result may be fractional—assign into P field with adequate decimal count. Integer-only contexts use INTEGER or ROUNDED after SQRT. Higher roots may use ** (1.0/n) pattern if fractional exponent supported—verify compiler behavior on your release before relying on non-integer **.

Logarithms and Statistical Use

LOG functions support growth rate and entropy-style calculations rare in classic payroll but present in forecast batch jobs. Domain errors on non-positive arguments—validate input range in IF. Combine with ABS from numeric category when log of magnitude needed without sign. Profile runtime on large files—transcendental functions cost more than add.

MOD Operator

MOD remainder operator documented under operators section complements math for cyclic keys—IF MOD(SEQ, 10) EQ 0 for every tenth record sampling. See MOD operator tutorial for divide-by-zero guard on modulus.

Math Versus Numeric Category

Numeric: ABS MIN MAX rounding modifiers for business rules. Math: ** SQRT LOG advanced expression forms. Payroll tip: gross minus tax lives in numeric; engineering unit conversion with powers lives in math. Cross-link both indexes when job mixes variance ABS with statistical root mean square.

Precision and Rounding After Math

Long fractional intermediate results assign into short P fields—explicit ROUNDED on assignment documents penny policy. Chain: WS-FULL = SQRT(VARIANCE) then DISPLAY-FLD = WS-FULL ROUNDED into P 2. Skipping intermediate W field loses precision in multi-step actuarial formulas.

Common Math Mistakes

  • Wrong precedence without parentheses in mixed ** and +.
  • Division or MOD by zero uncaught.
  • SQRT of negative without guard.
  • Assuming COBOL FUNCTION semantics identical in Easytrieve.
  • Overflow on ** with large exponent.
  • Using Plus-only LOG on Report Generator compile LPAR.

Explain It Like I'm Five

Math tools are fancy calculators inside your recipe. Plus and minus mix ingredients. Times and divide share or split piles. ** means multiply a number by itself a counted number of times—two star two is four. SQRT asks what number times itself gives this square—reverse of **. Parentheses tell the calculator which part to do first so the recipe does not come out wrong.

Exercises

  1. Evaluate 5 + 2 ** 3 by hand then write Easytrieve expression.
  2. Write AREA = SIDE ** 2 with SIDE from file field.
  3. Add IF guard before SQRT on field that can be negative.
  4. Explain math versus numeric category with one job example each.
  5. Rewrite A * B ** 2 with parentheses for (A*B)**2 intent.

Quiz

Test Your Knowledge

1. BASE ** 2 in Easytrieve means:

  • BASE raised to power 2
  • Multiply BASE by 2 only
  • String repeat
  • File merge

2. SQRT function availability:

  • Documented on Plus; verify on Report Generator
  • Forbidden always
  • JCL only
  • REPORT only

3. Math category differs from numeric because:

  • Math covers roots powers logs; numeric covers ABS MIN rounding
  • Identical
  • Math is alphabetic
  • Numeric is JCL

4. Expression 2 + 3 ** 2 evaluates ** first giving:

  • 11
  • 25
  • 36
  • Compile error

5. Divide by zero in math expression:

  • Runtime error—guard with IF
  • Returns zero always
  • Returns one
  • Ignored
Published
Read time15 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve ** exponentiation; SQRT LOG per Plus Application ReferenceSources: Broadcom Easytrieve Report Generator 11.6 operators, EZT Plus Application ReferenceApplies to: Easytrieve math functions and advanced arithmetic