Hash :
a897449a
Author :
Date :
2006-08-14T22:19:54
Add copyright notices to long-enough files that lack them, since otherwise the files aren't clearly free. Use the same notice that getdate.texi already uses. * doc/alloca-opt.texi: Add copyright notice. * doc/alloca.texi: Likewise. * doc/ctime.texi: Likewise. * doc/functions.texi: Likewise. * doc/gcd.texi: Likewise. * doc/gnulib-tool.texi: Likewise. * doc/inet_ntoa.texi: Likewise. * doc/visibility.texi: Likewise. Change copyright notice from LGPL 2 to GPL 2, since that's the standard form used in the gnulib repository. * lib/lock.c: LGPL -> GPL. * lib/lock.h: Likewise. * lib/strnlen1.c: Likewise. * lib/strnlen1.h: Likewise. * lib/tls.c: Likewise. * lib/tls.h: Likewise. * lib/tmpdir.c: Likewise. * tests/test-lock.c: Likewise. * tests/test-stdint.c: Likewise. * tests/test-tls.c: Likewise.
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
@node gcd
@section gcd: greatest common divisor
@findex gcd
@c Copyright (C) 2006 Free Software Foundation, Inc.
@c Permission is granted to copy, distribute and/or modify this document
@c under the terms of the GNU Free Documentation License, Version 1.2 or
@c any later version published by the Free Software Foundation; with no
@c Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
@c Texts. A copy of the license is included in the ``GNU Free
@c Documentation License'' file as part of this distribution.
The @code{gcd} function returns the greatest common divisor of two numbers
@code{a > 0} and @code{b > 0}. It is the caller's responsibility to ensure
that the arguments are non-zero.
If you need a gcd function for an integer type larger than
@samp{unsigned long}, you can include the @file{gcd.c} implementation file
with parametrization. The parameters are:
@itemize @bullet
@item WORD_T
Define this to the unsigned integer type that you need this function for.
@item GCD
Define this to the name of the function to be created.
@end itemize
The created function has the prototype
@smallexample
WORD_T GCD (WORD_T a, WORD_T b);
@end smallexample
If you need the least common multiple of two numbers, it can be computed
like this: @code{lcm(a,b) = (a / gcd(a,b)) * b} or
@code{lcm(a,b) = a * (b / gcd(a,b))}.
Avoid the formula @code{lcm(a,b) = (a * b) / gcd(a,b)} because - although
mathematically correct - it can yield a wrong result, due to integer overflow.
In some applications it is useful to have a function taking the gcd of two
signed numbers. In this case, the gcd function result is usually normalized
to be non-negative (so that two gcd results can be compared in magnitude
or compared against 1, etc.). Note that in this case the prototype of the
function has to be
@smallexample
unsigned long gcd (long a, long b);
@end smallexample
and not
@smallexample
long gcd (long a, long b);
@end smallexample
because @code{gcd(LONG_MIN,LONG_MIN) = -LONG_MIN = LONG_MAX + 1} does not
fit into a signed @samp{long}.