|
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
|
| Rev | Line | |
|---|
| [db24058] | 1 | /*
|
|---|
| [d7f7a4a] | 2 | * SPDX-FileCopyrightText: 2009 Martin Decky
|
|---|
| [db24058] | 3 | *
|
|---|
| [d7f7a4a] | 4 | * SPDX-License-Identifier: BSD-3-Clause
|
|---|
| [db24058] | 5 | */
|
|---|
| 6 |
|
|---|
| 7 | /** @addtogroup libc
|
|---|
| 8 | * @{
|
|---|
| 9 | */
|
|---|
| 10 | /** @file
|
|---|
| 11 | */
|
|---|
| 12 |
|
|---|
| [4805495] | 13 | #ifndef _LIBC_GCDLCM_H_
|
|---|
| 14 | #define _LIBC_GCDLCM_H_
|
|---|
| [db24058] | 15 |
|
|---|
| [8d2dd7f2] | 16 | #include <stddef.h>
|
|---|
| 17 | #include <stdint.h>
|
|---|
| [db24058] | 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 |
|
|---|
| 41 | DECLARE_GCD(uint32_t, gcd32);
|
|---|
| 42 | DECLARE_GCD(uint64_t, gcd64);
|
|---|
| 43 | DECLARE_GCD(size_t, gcd);
|
|---|
| 44 |
|
|---|
| 45 | DECLARE_LCM(uint32_t, lcm32, gcd32);
|
|---|
| 46 | DECLARE_LCM(uint64_t, lcm64, gcd64);
|
|---|
| 47 | DECLARE_LCM(size_t, lcm, gcd);
|
|---|
| 48 |
|
|---|
| 49 | #endif
|
|---|
| 50 |
|
|---|
| 51 | /** @}
|
|---|
| 52 | */
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.