Return to the RPG Tips
Math Functions in RPG
Q. Is it possible to perform higher math functions in RPG, such as exponentials, cos(x), sin(x), and so on?A. Exponentiation is available directly using the ** operator (e.g., x=y**z). All other higher math functions (including exponentiation) are available in RPG by calling C functions in directory QC2LE. You can view sample RPG code that calls the Cosine function in the Redbook "Who Knew You Could Do That with RPG IV? A Sorcerer's Guide to System Access and More," which is viewable and downloadable at http://www.redbooks.ibm.com/redpieces/abstracts/sg245402.html.
Here is a list of math functions in QC2LE:
- acos - Arc cosine function.
- asin - Arc sine function.
- atan - Arc tangent function.
- atan2 - Arc tangent function.
- ceil - Round to smallest integral value greater than or equal to.
- cos - Cosine function.
- cosh - Hyperbolc cosine function.
- exp - Exponentiation function.
- fabs - Floating point absolute value function.
- floor - Round to largest integral value not greater than.
- fmod - Floating point remainder function.
- frexp - Convert floating point number to fractional and integral components.
- ldexp - Multiply a floating point number by an integral power of two.
- log - Natural logarithm function.
- log10 - Base 10 logarithm function.
- modf - Extract signed integral and fractional parts from a floating point number.
- pow - Compute the first argument to the power of the second.
- sin - Sine function.
- sinh - Hyperbolic sine function.
- sqrt - Square root function.
- tan - Tangent function.
- tanh - Hyperbolic tangent function.
[report a broken link by clicking here]