LMMP 4.3.0
Lamina High-Precision Arithmetic Library
载入中...
搜索中...
未找到
to_chars.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 "lmmp/lmmpn.h"
24
25
27 for (mp_size_t i = 0; i < n; i++)
28 dst[i] = (mp_byte_t)(dst[i] + (mp_byte_t)'0');
29}
30
31void lmmp_b36_to_chars_(mp_byte_t* dst, mp_size_t n, bool upper) {
32 // x>=10 时 c = x + '0' + adj, adj = 'a'-'0'-10 = 39 (小写) / 'A'-'0'-10 = 7 (大写)
33 // -(x>9) 生成全0/全1掩码,与 adj 按位与实现无分支选择
34 const int adj = upper ? 7 : 39;
35 for (mp_size_t i = 0; i < n; i++) {
36 int x = dst[i];
37 dst[i] = (mp_byte_t)(x + '0' + (-(x > 9) & adj));
38 }
39}
uint8_t mp_byte_t
定义 lmmp.h:91
uint64_t mp_size_t
定义 lmmp.h:93
void lmmp_b36_to_chars_(mp_byte_t *dst, mp_size_t n, bool upper)
36进制数字字节原地转字符 [dst,n]: [0,35] -> ['0'-'9','a'-'z']或['0'-'9','A'-'Z']
void lmmp_dec_to_chars_(mp_byte_t *dst, mp_size_t n)
十进制数字字节原地转字符 [dst,n]: [0,9] -> ['0','9']
#define n