LAMMP 4.2.0
Lamina High-Precision Arithmetic Library
载入中...
搜索中...
未找到
cbrt.c 文件参考
+ cbrt.c 的引用(Include)关系图:

浏览源代码.

函数

mp_limb_t lmmp_cbrt_3_ (mp_limb_t a0, mp_limb_t a1, mp_limb_t a2)
 计算算数立方根 floor(cbrt(a0+a1*B+a2*B^2))
 
void lmmp_cbrt_6_ (mp_ptr dst, mp_srcptr numa, mp_size_t na)
 计算算数立方根 floor(cbrt([numa,na]))
 
mp_limb_t lmmp_cbrtapprox_3_ (mp_limb_t a0, mp_limb_t a1, mp_limb_t a2)
 计算近似立方根 floor(cbrt(a0+a1*B+a2*B^2))-[0|1]
 
void lmmp_cbrtapprox_6_ (mp_ptr dst, mp_srcptr numa, mp_size_t na)
 计算近似立方根 floor(cbrt([numa,na]))-[0|1]
 
static mp_size_t lmmp_cube_ (mp_ptr restrict dst, mp_srcptr restrict numa, mp_size_t na, mp_ptr restrict tp)
 计算 [numa, na] 的立方
 
static void lmmp_cube_3_ (mp_ptr restrict dst, mp_limb_t a)
 Copyright (C) 2026 HJimmyK(Jericho Knox)
 

函数说明

◆ lmmp_cbrt_3_()

mp_limb_t lmmp_cbrt_3_ ( mp_limb_t  a0,
mp_limb_t  a1,
mp_limb_t  a2 
)

计算算数立方根 floor(cbrt(a0+a1*B+a2*B^2))

参数
a0低位 limb
a1中位 limb
a2高位 limb
警告
a1>0
注解
a2可以为0,但a1需要大于0,即这个数至少应有65个bit
返回
floor(cbrt(a0+a1*B+a2*B^2))

在文件 cbrt.c74 行定义.

74 {
76
78 if (r == LIMB_MAX)
79 return LIMB_MAX;
80 mp_limb_t t[3], a[3] = {a0, a1, a2};
81 lmmp_cube_3_(t, r + 1);
82 int cmp = lmmp_cmp_(t, a, 3);
83 // approx的结果至多只会低估1
84 if (cmp <= 0)
85 return r + 1;
86 else
87 return r;
88}
mp_limb_t lmmp_cbrtapprox_3_(mp_limb_t a0, mp_limb_t a1, mp_limb_t a2)
计算近似立方根 floor(cbrt(a0+a1*B+a2*B^2))-[0|1]
Definition cbrt.c:32
static void lmmp_cube_3_(mp_ptr restrict dst, mp_limb_t a)
Copyright (C) 2026 HJimmyK(Jericho Knox)
Definition cbrt.c:23
#define LIMB_MAX
Definition lmmp.h:89
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
#define a0
#define a1
#define a2
#define t
#define n

引用了 a0, a1, a2, LIMB_MAX, lmmp_cbrtapprox_3_(), lmmp_cmp_(), lmmp_cube_3_(), lmmp_param_assert, n , 以及 t.

+ 函数调用图:

◆ lmmp_cbrt_6_()

void lmmp_cbrt_6_ ( mp_ptr  dst,
mp_srcptr  numa,
mp_size_t  na 
)

计算算数立方根 floor(cbrt([numa,na]))

参数
dst结果指针(长度为 2 个limb)
numa被开方数指针
na被开方数的 limb 长度
警告
dst!=NULL, numa!=NULL, 3<na<=6, numa[na-1]!=0, eqsep(dst,numa)

在文件 cbrt.c152 行定义.

152 {
153 mp_limb_t ret[2];
155
156 if (ret[1] == LIMB_MAX && ret[0] == LIMB_MAX) {
157 dst[0] = LIMB_MAX;
158 dst[1] = LIMB_MAX;
159 } else {
160 mp_limb_t r[2];
161 r[0] = ret[0] + 1;
162 r[1] = ret[1] + (r[0] == 0 ? 1 : 0);
163 mp_limb_t t[10];
164 mp_size_t tn = lmmp_cube_(t, r, 2, t + 6);
165 if (tn < na) {
166 dst[0] = r[0];
167 dst[1] = r[1];
168 } else if (tn > na) {
169 dst[0] = ret[0];
170 dst[1] = ret[1];
171 } else if (tn == na) {
172 int cmp = lmmp_cmp_(t, numa, tn);
173 // approx的结果至多只会低估1
174 if (cmp <= 0) {
175 dst[0] = r[0];
176 dst[1] = r[1];
177 } else {
178 dst[0] = ret[0];
179 dst[1] = ret[1];
180 }
181 }
182 }
183}
static mp_size_t lmmp_cube_(mp_ptr restrict dst, mp_srcptr restrict numa, mp_size_t na, mp_ptr restrict tp)
计算 [numa, na] 的立方
Definition cbrt.c:98
void lmmp_cbrtapprox_6_(mp_ptr dst, mp_srcptr numa, mp_size_t na)
计算近似立方根 floor(cbrt([numa,na]))-[0|1]
Definition cbrt.c:106
uint64_t mp_size_t
Definition lmmp.h:77

引用了 LIMB_MAX, lmmp_cbrtapprox_6_(), lmmp_cmp_(), lmmp_cube_(), n , 以及 t.

+ 函数调用图:

◆ lmmp_cbrtapprox_3_()

mp_limb_t lmmp_cbrtapprox_3_ ( mp_limb_t  a0,
mp_limb_t  a1,
mp_limb_t  a2 
)

计算近似立方根 floor(cbrt(a0+a1*B+a2*B^2))-[0|1]

参数
a0低位 limb
a1中位 limb
a2高位 limb
警告
a1>0
注解
a2可以为0,但a1需要大于0,即这个数至少应有65个bit
返回
floor(cbrt(a0+a1*B+a2*B^2))-[0|1]

在文件 cbrt.c32 行定义.

32 {
34 mp_limb_t x[2];
35 /* exact high 65 bits */
38 if (a2 == 0) {
41 a1_bits--;
42 if (a1_bits == 0)
43 a_hi = a0;
44 else
45 a_hi = (a1 << (LIMB_BITS - a1_bits)) | (a0 >> a1_bits);
46 } else {
48 bits = LIMB_BITS * 2 + a2_bits;
49 a2_bits--;
50 if (a2_bits == 0)
51 a_hi = a1;
52 else
53 a_hi = (a2 << (LIMB_BITS - a2_bits)) | (a1 >> a2_bits);
54 }
56
57 x[1] = bits - 1;
58 x[0] = log2_fixed_64(a_hi);
59
60 mp_limb_t r = lmmp_div_1_(x, x, 2, 3);
61 if (2 * r >= 3) // round
62 lmmp_inc(x);
63
64 mp_bitcnt_t shift = x[1];
65 x[0] = exp2_fixed_64(x[0]);
66
68 if (shift == 64)
69 return LIMB_MAX;
70 else
71 return (x[0] >> (64 - shift)) | (1ULL << shift);
72}
#define lmmp_limb_bits_
Definition inlines.h:162
size_t mp_bitcnt_t
Definition lmmp.h:82
#define lmmp_debug_assert(x)
Definition lmmp.h:390
#define LIMB_BITS
Definition lmmp.h:86
mp_limb_t lmmp_div_1_(mp_ptr dstq, mp_srcptr numa, mp_size_t na, mp_limb_t x)
单精度数除法
Definition div.c:77
#define lmmp_inc(p)
大数加1宏(预期无进位)
Definition lmmpn.h:938
uint64_t exp2_fixed_64(uint64_t x)
floor(exp2(x/B)*B-B), B=2^64
Definition log2_exp2.c:485
uint64_t log2_fixed_64(uint64_t x)
Copyright (C) 2026 HJimmyK(Jericho Knox)
Definition log2_exp2.c:458

引用了 a0, a1, a2, exp2_fixed_64(), LIMB_BITS, LIMB_MAX, lmmp_debug_assert, lmmp_div_1_(), lmmp_inc, lmmp_limb_bits_, lmmp_param_assert, log2_fixed_64() , 以及 n.

被这些函数引用 lmmp_cbrt_3_().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ lmmp_cbrtapprox_6_()

void lmmp_cbrtapprox_6_ ( mp_ptr  dst,
mp_srcptr  numa,
mp_size_t  na 
)

计算近似立方根 floor(cbrt([numa,na]))-[0|1]

参数
dst结果指针(长度为 2 个limb)
numa被开方数指针
na被开方数的 limb 长度
警告
dst!=NULL, numa!=NULL, 3<na<=6, numa[na-1]!=0, eqsep(dst,numa)

在文件 cbrt.c106 行定义.

106 {
107 lmmp_param_assert(na > 3 && na <= 6);
109 lmmp_param_assert(numa[na - 1] != 0);
110 /* extract the first 129 bits */
111 int bits = lmmp_limb_bits_(numa[na - 1]);
112 mp_bitcnt_t n = bits - 1;
114 if (bits == 1) {
115 high = numa[na - 2];
116 low = numa[na - 3];
117 } else {
118 bits--;
119 high = (numa[na - 1] << (64 - bits)) | (numa[na - 2] >> bits);
120 low = (numa[na - 2] << (64 - bits)) | (numa[na - 3] >> bits);
121 }
122
123 n += LIMB_BITS * (na - 1);
124 mp_limb_t x[3] = {0, 0, n};
125
127 mp_limb_t r = lmmp_div_1_(x, x, 3, 3);
128 if (2 * r >= 3) // round
129 lmmp_inc(x);
130
131 n = x[2];
132 high = x[1];
133 low = x[0];
134
136
137 lmmp_debug_assert(n >= 64 && n <= 128);
138 if (n == 64) {
139 dst[0] = x[1];
140 dst[1] = 1;
141 } else if (n < 128) {
142 n -= 64;
143 mp_limb_t t = 1ULL << n;
144 dst[1] = (x[1] >> (64 - n)) | t;
145 dst[0] = (x[1] << n) | (x[0] >> (64 - n));
146 } else {
147 dst[1] = LIMB_MAX;
148 dst[0] = LIMB_MAX;
149 }
150}
void exp2_fixed_128(uint64_t *dst, uint64_t high, uint64_t low)
floor(exp2(x/B)*B-B), B=2^128
Definition log2_exp2.c:409
void log2_fixed_128(uint64_t *dst, uint64_t high, uint64_t low)
floor(log2(1+x/B)*B), B=2^128
Definition log2_exp2.c:292

引用了 exp2_fixed_128(), LIMB_BITS, LIMB_MAX, lmmp_debug_assert, lmmp_div_1_(), lmmp_inc, lmmp_limb_bits_, lmmp_param_assert, log2_fixed_128(), n , 以及 t.

被这些函数引用 lmmp_cbrt_6_().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ lmmp_cube_()

static mp_size_t lmmp_cube_ ( mp_ptr restrict  dst,
mp_srcptr restrict  numa,
mp_size_t  na,
mp_ptr restrict  tp 
)
inlinestatic

计算 [numa, na] 的立方

参数
dst目标数组(3*na个limb)
numa源数组
na源数组的长度
tp临时数组(2*na个limb)
返回
返回结果的数组长度

在文件 cbrt.c98 行定义.

98 {
100 lmmp_mul_(dst, tp, 2 * na, numa, na);
101 na *= 3;
102 while (na > 1 && dst[na - 1] == 0) --na;
103 return na;
104}
#define lmmp_sqr_
Definition inlines.h:166
void lmmp_mul_(mp_ptr dst, mp_srcptr numa, mp_size_t na, mp_srcptr numb, mp_size_t nb)
不等长大数乘法操作 [dst,na+nb] = [numa,na] * [numb,nb]
#define tp

引用了 lmmp_mul_(), lmmp_sqr_, n , 以及 tp.

被这些函数引用 lmmp_cbrt_6_().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ lmmp_cube_3_()

static void lmmp_cube_3_ ( mp_ptr restrict  dst,
mp_limb_t  a 
)
inlinestatic

Copyright (C) 2026 HJimmyK(Jericho Knox)

This file is part of LAMMP.

LAMMP is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This program is distributed WITHOUT ANY WARRANTY.

See https://www.gnu.org/licenses/.

在文件 cbrt.c23 行定义.

23 {
24 mp_limb_t t[2];
25 lmmp_mullh_(a, a, t);
26 lmmp_mullh_(t[0], a, dst);
27 lmmp_mullh_(t[1], a, t);
28 dst[1] += t[0];
29 dst[2] = t[1] + (dst[1] < t[0] ? 1 : 0);
30}
#define lmmp_mullh_
Definition inlines.h:164

引用了 lmmp_mullh_, n , 以及 t.

被这些函数引用 lmmp_cbrt_3_().

+ 这是这个函数的调用关系图: