小编ema*_*uts的帖子

C 语言中 CORDIC 对数的问题

为了开始使用 CORDIC for ,我实现了此 PDF 第 6 页log10中派生的算法:

\n
#include <stdio.h>\n#include <math.h>\n\n// https://www.mikrocontroller.net/attachment/31117/cordic1.pdf\nfloat logf_cordic (float x, int B)\n{\n    float z = 0.0f;\n\n    for (int i = 1; i <= B; i++)\n    {\n        if (x > 1.0f)\n        {\n            printf ("-");\n            x = x - ldexpf (x, -i);\n            z = z - log10f (1.0f - ldexpf (1.0f, -i));\n        }\n        else\n        {\n            printf ("+");\n            x = x + ldexpf (x, -i);\n            z = z - log10f (1.0f + ldexpf (1.0f, …
Run Code Online (Sandbox Code Playgroud)

c c99 numerical-methods

3
推荐指数
2
解决办法
244
查看次数

gcc:C23 中的 constexpr 函数?

在使用constexprGCC v14.0(应该接近即将发布的 GCC v13.1)时,我编译了以下模块:

constexpr int f (int x)
{
    return x + 2;
}

constexpr const int x[] = { f(1) };
Run Code Online (Sandbox Code Playgroud)

gcc -std=c2x -c foo.c -O2 GCC 会抛出:

foo.c:1:1: error: 'constexpr' requires an initialized data declaration
   1 | constexpr int f (int x)
     | ^~~~~~~~~
[...f'up errors due to the one above...]
Run Code Online (Sandbox Code Playgroud)

根据constexprC23 提案 (pdf),这应该是正确的语法。不过该 PDF 没有附带任何示例,那么我在这里缺少什么?

GCC 自 C++11 起就可以处理constexpr,因此在 C 前端实现它应该是已知且成熟的技术。

c gcc constexpr c23

2
推荐指数
1
解决办法
1380
查看次数

标签 统计

c ×2

c23 ×1

c99 ×1

constexpr ×1

gcc ×1

numerical-methods ×1