source: mainline/uspace/lib/c/include/adt/gcdlcm.h@ cd1e3fc0

Last change on this file since cd1e3fc0 was d7f7a4a, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago

Replace some license headers with SPDX identifier

Headers are replaced using tools/transorm-copyright.sh only
when it can be matched verbatim with the license header used
throughout most of the codebase.

  • Property mode set to 100644
File size: 790 bytes
Line 
1/*
2 * SPDX-FileCopyrightText: 2009 Martin Decky
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7/** @addtogroup libc
8 * @{
9 */
10/** @file
11 */
12
13#ifndef _LIBC_GCDLCM_H_
14#define _LIBC_GCDLCM_H_
15
16#include <stddef.h>
17#include <stdint.h>
18
19#define DECLARE_GCD(type, name) \
20 static inline type name(type a, type b) \
21 { \
22 if (a == 0) \
23 return b; \
24 \
25 while (b != 0) { \
26 if (a > b) \
27 a -= b; \
28 else \
29 b -= a; \
30 } \
31 \
32 return a; \
33 }
34
35#define DECLARE_LCM(type, name, gcd) \
36 static inline type name(type a, type b) \
37 { \
38 return (a * b) / gcd(a, b); \
39 }
40
41DECLARE_GCD(uint32_t, gcd32);
42DECLARE_GCD(uint64_t, gcd64);
43DECLARE_GCD(size_t, gcd);
44
45DECLARE_LCM(uint32_t, lcm32, gcd32);
46DECLARE_LCM(uint64_t, lcm64, gcd64);
47DECLARE_LCM(size_t, lcm, gcd);
48
49#endif
50
51/** @}
52 */
Note: See TracBrowser for help on using the repository browser.