diff options
| author | David Faulkner <[email protected]> | 2026-08-07 23:40:47 -0500 |
|---|---|---|
| committer | David Faulkner <[email protected]> | 2026-08-07 23:40:47 -0500 |
| commit | b3e9e62599532050fc776c5e8f076915b56c2235 (patch) | |
| tree | af252346106a61b18cc6fc6fdbd32e962d096f1c /euclid.h | |
Import official C23 code examples for Modern C (Jens Gustedt, 2024)HEADupstream-importmain
- Add official C source files, Makefile, c23-fallback.h, and LICENSE
- Update README.md with study mirror notice
Diffstat (limited to 'euclid.h')
| -rw-r--r-- | euclid.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/euclid.h b/euclid.h new file mode 100644 index 0000000..82fca4e --- /dev/null +++ b/euclid.h @@ -0,0 +1,24 @@ +#ifndef EUCLID_H +# define EUCLID_H 1 + +# include "c23-fallback.h" +# include <stdio.h> +# include <assert.h> + +inline size_t gcd2(size_t a, size_t b) [[__unsequenced__]] { + assert(a <= b); /*@\label{gcd2-precondition}*/ + if (!a) return b; /*@\label{gcd2-bottom}*/ + size_t rem = b % a; /*@\label{gcd2-remainder}*/ + return gcd2(rem, a); /*@\label{gcd2-recurse}*/ +} + +inline size_t gcd(size_t a, size_t b) [[__unsequenced__]] { + assert(a); + assert(b); + if (a < b) + return gcd2(a, b); + else + return gcd2(b, a); +} + +#endif |
