1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
.TH ARITH 3
.CT 2 math
.SH NAME
abs, sgn, gcd, lcm, min, max, labs \(mi integer arithmetic functions:
absolute value, sign,
greatest common divisor, least common multiple, minimum, maximum
.SH SYNOPSIS
.B int abs(a)
.PP
.B int sgn(a)
.PP
.B int gcd(a, b)
.PP
.B long lcm(a, b)
.PP
.B int min(a, b)
.PP
.B int max(a, b)
.PP
.B long labs(a)
.br
.B long a;
.SH DESCRIPTION
.I Abs
returns
the absolute value of
.I a.
.PP
.I Sgn
returns
\-1, 0, 1,
if
.L
\fIa\fR<0, \fIa\fR=0, \fIa\fR>0,
respectively.
.PP
.I Gcd
returns the greatest common divisor of
.I a
and
.I b.
More precisely,
.I gcd
returns the largest machine-representable
generator of the ideal generated by
.I a
and
.I b.
This means that
.B gcd(0,0)
= 0, and
.B gcd(N,0)
=
.B gcd(N,N)
=
.BR N ,
where
.B N
is the most negative integer.
.PP
.I Lcm
returns the least common multiple of
.I a
and
.I b.
When the result is representable, it satisfies
.BR "abs(a*b)== lcm(a,b)*gcd(a,b)" .
.PP
.I Min
.RI ( max )
returns the minimum (maximum) of
.I a
and
.I b.
.SH SEE ALSO
.IR floor (3)
for
.I fabs
.SH DIAGNOSTICS
.I Abs
returns
the most negative integer when the true result is unrepresentable.
.PP
There are no guarantees about the value of
.I lcm
when the true value is unrepresentable.
.SH BUGS
The result of
.I lcm
is undefined when it doesn't fit in a long.
.br
.I Labs,
provided for
.SM ANSI
compatibility, is lonely; there is no
.I lsign, lmax,
etc.
|