LAMMP 4.2.0
Lamina High-Precision Arithmetic Library
载入中...
搜索中...
未找到
gcd_basecase.c
浏览该文件的文档.
1/**
2 * Copyright (C) 2026 HJimmyK(Jericho Knox)
3 *
4 * This file is part of LAMMP.
5 *
6 * LAMMP is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License (LGPL) as published
8 * by the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed WITHOUT ANY WARRANTY.
12 *
13 * See <https://www.gnu.org/licenses/>.
14 */
15
16#include "../../../include/lammp/impl/tmp_alloc.h"
17#include "../../../include/lammp/lmmpn.h"
18#include "../../../include/lammp/numth.h"
19
21 lmmp_param_assert(un > 0 && vn > 0);
22 if (un < vn) {
25 } else if (un == vn) {
26 int cmp = lmmp_cmp_(up, vp, un);
27 if (cmp < 0) {
29 } else if (cmp == 0) {
30 lmmp_copy(dst, up, un);
31 return un;
32 }
33 }
35#define an un
36#define bn vn
39 lmmp_copy(a, up, an);
40 lmmp_copy(b, vp, bn);
41 while (bn > 0 || (bn == 1 && b[0] == 0)) {
42 // dst = a % b;
43 lmmp_div_(NULL, dst, a, an, b, bn);
44 lmmp_copy(a, b, bn);
45 an = bn;
46 while (dst[bn - 1] == 0 && bn > 0) {
47 --bn;
48 }
49 lmmp_copy(b, dst, bn);
50 }
51 lmmp_copy(dst, a, an);
53 return an;
54#undef an
55#undef bn
56}
mp_size_t lmmp_gcd_basecase_(mp_ptr dst, mp_srcptr up, mp_size_t un, mp_srcptr vp, mp_size_t vn)
Copyright (C) 2026 HJimmyK(Jericho Knox)
#define an
#define bn
mp_limb_t * mp_ptr
Definition lmmp.h:80
#define LMMP_SWAP(x, y, type)
Definition lmmp.h:355
#define lmmp_copy(dst, src, n)
Definition lmmp.h:367
uint64_t mp_size_t
Definition lmmp.h:77
const mp_limb_t * mp_srcptr
Definition lmmp.h:81
uint64_t mp_limb_t
Definition lmmp.h:76
#define lmmp_param_assert(x)
Definition lmmp.h:401
static int lmmp_cmp_(mp_srcptr numa, mp_srcptr numb, mp_size_t n)
大数比较函数(内联)
Definition lmmpn.h:996
void lmmp_div_(mp_ptr dstq, mp_ptr dstr, mp_srcptr numa, mp_size_t na, mp_srcptr numb, mp_size_t nb)
大数除法和取模操作
Definition div.c:74
#define n
#define TEMP_DECL
Definition tmp_alloc.h:131
#define TEMP_FREE
Definition tmp_alloc.h:150
#define TALLOC_TYPE(n, type)
Definition tmp_alloc.h:148