Auxiliary Functions in PG
The macro file PGauxiliaryFunctions.pl, which is automatically loaded by PGstandard.pl, contains many useful numerical recipies.
- The max function
max(-1,4,2*pi,5);
will return 6.28319.
- The min function
min(10,2*pi,-1,5);
will return -1.
- The greatest common factor (or divisor) function
gcf(4,6);
or gcd(4,6);
will return 2. For perl code that gives an extended gcd function xgcd(a,b) = d = ax+by
, see the online references below.
- The least common multiple function
lcm(4,6);
will return 12.
- The ceiling and floor functions
ceil(-3.4);
and floor(-3.4);
will return -3 and -4.
- The prime test function
isPrime(4);
and isPrime(5);
will return 0 and 1.
- The signum (or sign) function
sgn(-pi);
and sgn(0);
and sgn(6)
will return -1, 0, and 1.
- The Heaviside step function, which is 1 when the input is positive and zero otherwise, is
step(-0.1);
and step(0);
and step(0.1);
which returns 0, 0, and 1.
- The integer rounding function
round(1.49999);
and round(1.5);
and round(-1.5);
and round(-1.49999);
will return 1, 2, -2, -1.
Online References