LMMP
4.3.0
Lamina High-Precision Arithmetic Library
Toggle main menu visibility
载入中...
搜索中...
未找到
divexact_odd.c
浏览该文件的文档.
1
/**
2
* Copyright (C) 2026 HJimmyK (Jericho Knox)
3
*
4
* This file is part of LMMP.
5
*
6
* LMMP is free software: you can redistribute it and/or modify it
7
* under the terms of the GNU Lesser General Public License as
8
* published by the Free Software Foundation; either version 3 of
9
* the License, or (at your option) any later version.
10
*
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU Lesser General Public License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this library. If not, see
18
* <https://www.gnu.org/licenses/>.
19
*
20
* SPDX-License-Identifier: LGPL-3.0-or-later
21
*/
22
23
#include "
lmmpn/divexact.h
"
24
#include "
impl/longlong.h
"
25
26
27
mp_limb_t
lmmp_divexact_odd_pi_
(
mp_ptr
dst,
mp_srcptr
numa,
mp_size_t
na,
mp_limb_t
d,
mp_limb_t
di,
unsigned
shr) {
28
mp_limb_t
c, l, u, un,
lo
;
29
mp_size_t
i;
30
31
lmmp_param_assert
(na > 0);
32
lmmp_param_assert
((d & 1) != 0);
33
lmmp_param_assert
(shr <
LIMB_BITS
);
34
lmmp_param_assert
(d * di == 1);
35
36
if
(shr != 0) {
37
c = 0;
38
u = numa[0];
39
for
(i = 1; i < na; i++) {
40
un = numa[i];
41
u = (u >> shr) | (un << (
LIMB_BITS
- shr));
42
l = u - c;
43
c = l > u;
44
l *= di;
45
dst[i - 1] = l;
46
u = un;
47
_umul64to128_
(l, d, &
lo
, &un);
48
c += un;
49
}
50
u >>= shr;
51
l = u - c;
52
c = l > u;
53
l *= di;
54
dst[na - 1] = l;
55
}
else
{
56
c = 0;
57
i = 0;
58
do
{
59
u = numa[i];
60
l = u - c;
61
c = l > u;
62
l *= di;
63
dst[i] = l;
64
_umul64to128_
(l, d, &
lo
, &un);
65
c += un;
66
}
while
(++i < na);
67
}
68
return
c;
69
}
divexact.h
lmmp_divexact_odd_pi_
mp_limb_t lmmp_divexact_odd_pi_(mp_ptr dst, mp_srcptr numa, mp_size_t na, mp_limb_t d, mp_limb_t di, unsigned shr)
通用奇除数精确除,可带 2^shr 因子: [dst,na] = [numa,na] / (d*2^shr),其中 d 为奇数、di = d^(-1) mod B
定义
divexact_odd.c:27
mp_ptr
mp_limb_t * mp_ptr
定义
lmmp.h:96
mp_size_t
uint64_t mp_size_t
定义
lmmp.h:93
mp_srcptr
const mp_limb_t * mp_srcptr
定义
lmmp.h:97
mp_limb_t
uint64_t mp_limb_t
定义
lmmp.h:92
LIMB_BITS
#define LIMB_BITS
定义
lmmp.h:102
lmmp_param_assert
#define lmmp_param_assert(x)
定义
lmmp.h:509
longlong.h
_umul64to128_
static void _umul64to128_(uint64_t a, uint64_t b, uint64_t *low, uint64_t *high)
定义
longlong.h:132
lo
#define lo
src
lmmp
lmmpn
divexact_odd.c
生成于
, 为 LMMP使用
1.18.0