LMMP
4.3.0
Lamina High-Precision Arithmetic Library
Toggle main menu visibility
载入中...
搜索中...
未找到
log2_exp2.h
浏览该文件的文档.
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
#ifndef __LMMP_LOG2_EXP2_H__
24
#define __LMMP_LOG2_EXP2_H__
25
26
#include <stdint.h>
27
28
/**
29
* @brief 计算 floor(log2(1+x/B)*B), B=2^64
30
* @param x 输入的小数部分
31
* @return floor(log2(1+x/B)*B) + e,|e| <= 2
32
* @note 表驱动 + 短泰勒级数实现,返回契约允许 +-2 ulp 的误差
33
* (实测 |e| <= 2,主要来自各级 floor 舍入)。主要供 cbrt/nthroot
34
* 等内部使用,配合外部单调修正即可得到精确整值结果。
35
*/
36
uint64_t
log2_fixed_64
(uint64_t x);
37
38
/**
39
* @brief 计算 floor(exp2(x/B)*B-B), B=2^64
40
* @param x 输入的小数部分
41
* @return floor(exp2(x/B)*B-B) + e,|e| <= 2
42
* @note 同 log2_fixed_64,返回契约允许 +-2 ulp 的误差。
43
*/
44
uint64_t
exp2_fixed_64
(uint64_t x);
45
46
/**
47
* @brief 计算 floor(log2(1+x/B)*B), B=2^128
48
* @param high 输入的小数部分高64位
49
* @param low 输入的小数部分低64位
50
* @param dst 输出数组(2个元素):dst[0] 为低64位,dst[1] 为高64位
51
* @note x = high * 2^64 + low,结果误差 |e| <= 2(128bit ulp)
52
*/
53
void
log2_fixed_128
(uint64_t* dst, uint64_t high, uint64_t low);
54
55
/**
56
* @brief 计算 floor(exp2(x/B)*B-B), B=2^128
57
* @param high 输入的小数部分高64位
58
* @param low 输入的小数部分低64位
59
* @param dst 输出数组(2个元素):dst[0] 为低64位,dst[1] 为高64位
60
* @note x = high * 2^64 + low,结果误差 |e| <= 2(128bit ulp)
61
*/
62
void
exp2_fixed_128
(uint64_t* dst, uint64_t high, uint64_t low);
63
64
#endif
// __LMMP_LOG2_EXP2_H__
exp2_fixed_128
void exp2_fixed_128(uint64_t *dst, uint64_t high, uint64_t low)
计算 floor(exp2(x/B)*B-B), B=2^128
定义
log2_exp2.c:461
log2_fixed_128
void log2_fixed_128(uint64_t *dst, uint64_t high, uint64_t low)
计算 floor(log2(1+x/B)*B), B=2^128
定义
log2_exp2.c:392
exp2_fixed_64
uint64_t exp2_fixed_64(uint64_t x)
计算 floor(exp2(x/B)*B-B), B=2^64
定义
log2_exp2.c:345
log2_fixed_64
uint64_t log2_fixed_64(uint64_t x)
Copyright (C) 2026 HJimmyK (Jericho Knox)
定义
log2_exp2.c:281
src
lmmp
numth
log2_exp2.h
生成于
, 为 LMMP使用
1.18.0