]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
gcd: Allow customizing the parameter and result type.
authorBruno Haible <bruno@clisp.org>
Sun, 22 Jun 2025 20:12:23 +0000 (22:12 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 22 Jun 2025 20:12:44 +0000 (22:12 +0200)
* lib/gcd.h (GCD_WORD_T): New type.
(gcd): Use GCD_WORD_T instead of 'unsigned long'.
* lib/gcd.c (WORD_T): Likewise.

ChangeLog
lib/gcd.c
lib/gcd.h

index bf1fea6a0594f7450ae134466223e6ebcd49ae8c..7b5ded386ad563b3e570fe5f7ccccccdd6a3c0b9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2025-06-22  Bruno Haible  <bruno@clisp.org>
+
+       gcd: Allow customizing the parameter and result type.
+       * lib/gcd.h (GCD_WORD_T): New type.
+       (gcd): Use GCD_WORD_T instead of 'unsigned long'.
+       * lib/gcd.c (WORD_T): Likewise.
+
 2025-06-18  Bruno Haible  <bruno@clisp.org>
 
        string-desc: Fix a compiler warning.
index 8a7fb8ed10b79bac112a7bb22f38efb8457a26cd..25170abfc61b55d622c7f2c455a00fdca3eb8ec3 100644 (file)
--- a/lib/gcd.c
+++ b/lib/gcd.c
@@ -22,7 +22,7 @@
 #ifndef WORD_T
 /* Specification.  */
 # include "gcd.h"
-# define WORD_T unsigned long
+# define WORD_T GCD_WORD_T
 # define GCD gcd
 #endif
 
index 02a8adccd94b2be60e5fbb0fdfd8e77f9d6f8a3f..24b8ad54bf94378f8a671c75388caff900dfd410 100644 (file)
--- a/lib/gcd.h
+++ b/lib/gcd.h
 #ifndef _GCD_H
 #define _GCD_H
 
+/* Before including this file, you may define:
+     GCD_WORD_T         The parameter type and result type of the gcd function.
+ */
+
+#ifdef GCD_WORD_T
+/* Make sure that GCD_WORD_T is defined as a type.  */
+# include <stddef.h>
+# include <stdint.h>
+#else
+# define GCD_WORD_T unsigned long
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 
 /* Return the greatest common divisor of a > 0 and b > 0.  */
-extern unsigned long gcd (unsigned long a, unsigned long b);
+extern GCD_WORD_T gcd (GCD_WORD_T a, GCD_WORD_T b);
 
 
 #ifdef __cplusplus