XWOS API
4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
div64.c
浏览该文件的文档.
1
13
#include <
xwos/standard.h
>
14
#include <
xwos/lib/div64.h
>
15
16
static
__xwlib_code
17
xwu32_t
xwdiv64_32
(
xwu64_t
* dividend,
xwu32_t
divisor);
18
27
__xwlib_code
28
xwu32_t
xwdiv64
(
xwu64_t
* n,
xwu32_t
divisor)
29
{
30
xwu32_t
rem;
31
if
(((*n) >> (
xwu32_t
)32) == (
xwu32_t
)0) {
32
rem = (
xwu32_t
)(*n) % divisor;
33
*n = (*n) / (
xwu64_t
)divisor;
34
}
else
{
35
rem =
xwdiv64_32
(n, divisor);
36
}
37
return
rem;
38
}
39
48
static
__xwlib_code
49
xwu32_t
xwdiv64_32
(
xwu64_t
* n,
xwu32_t
divisor)
50
{
51
xwu64_t
rem = *n;
52
xwu64_t
b = divisor;
53
xwu64_t
res;
54
xwu64_t
d = (
xwu64_t
)1;
55
xwu32_t
high = (
xwu32_t
)(rem >> (
xwu32_t
)32);
56
57
res = 0;
58
if
(high >= divisor) {
59
high /= divisor;
60
res = (
xwu64_t
)high << (
xwu64_t
)32;
61
rem -= (((
xwu64_t
)high * (
xwu64_t
)divisor) << (
xwu64_t
)32);
62
}
63
64
while
(((
xws64_t
)b > (
xws64_t
)0) && (b < rem)) {
65
b = b + b;
66
d = d + d;
67
}
68
69
do
{
70
if
(rem >= b) {
71
rem -= b;
72
res += d;
73
}
74
b >>= (
xwu64_t
)1;
75
d >>= (
xwu64_t
)1;
76
}
while
((
xwu64_t
)0 != d);
77
78
*n = res;
79
return
(
xwu32_t
)rem;
80
}
xwdiv64_32
static xwu32_t xwdiv64_32(xwu64_t *dividend, xwu32_t divisor)
用一个32位无符号整数除以一个64位无符号整数
Definition
div64.c:49
div64.h
XWOS通用库:64位除法
__xwlib_code
#define __xwlib_code
Definition
compiler.h:199
xwdiv64
xwu32_t xwdiv64(xwu64_t *n, xwu32_t divisor)
64位除法运算
Definition
div64.c:28
xws64_t
int64_t xws64_t
Definition
type.h:319
xwu64_t
uint64_t xwu64_t
Definition
type.h:303
xwu32_t
uint32_t xwu32_t
Definition
type.h:266
standard.h
XWOS的标准头文件
xwos
lib
div64.c
制作者
1.9.7