ARITH(3) ARITH(3) NAME abs, sgn, gcd, lcm, min, max, labs - integer arithmetic functions: absolute value, sign, greatest common divisor, least common multiple, minimum, maximum SYNOPSIS int abs(a) int sgn(a) int gcd(a, b) long lcm(a, b) int min(a, b) int max(a, b) long labs(a) long a; DESCRIPTION Abs returns the absolute value of a. Sgn returns -1, 0, 1, if a<0, a=0, a>0, respectively. Gcd returns the greatest common divisor of a and b. More precisely, gcd returns the largest machine-representable generator of the ideal generated by a and b. This means that gcd(0,0) = 0, and gcd(N,0) = gcd(N,N) = N, where N is the most negative integer. Lcm returns the least common multiple of a and b. When the result is representable, it satisfies abs(a*b)== lcm(a,b)*gcd(a,b). Min (max) returns the minimum (maximum) of a and b. SEE ALSO floor(3) for fabs DIAGNOSTICS Abs returns the most negative integer when the true result is unrepresentable. There are no guarantees about the value of lcm when the true value is unrepresentable. BUGS The result of lcm is undefined when it doesn't fit in a ARITH(3) ARITH(3) long. Labs, provided for ANSI compatibility, is lonely; there is no lsign, lmax, etc.