安卓系统是否支持log2函数?

5

安卓支持log2吗?
我已经发现安卓不支持长双精度。

当我尝试编译cdce3.c时,我收到了以下错误:

g++.dg/cdce3.C: In function 'void mlog2f(int)':
g++.dg/cdce3.C:87: error: 'log2f' was not declared in this scope
g++.dg/cdce3.C: In function 'void mlog2(int)':
g++.dg/cdce3.C:87: error: 'log2' was not declared in this scope
g++.dg/cdce3.C: In function 'void olog2f(int)':
g++.dg/cdce3.C:108: error: 'log2f' was not declared in this scope
g++.dg/cdce3.C: In function 'void olog2(int)':
g++.dg/cdce3.C:108: error: 'log2' was not declared in this scope

cdce3.c源代码的一部分:

#define DEF_MATH_FUNC(prefix, name) NI void prefix##name##f (int x) \
{ \
  float yy = name##f ((float) x); \
  STORE_RESULT; \
} \
NI void prefix##name (int x) \
{ \
  double yy = name ((double)x); \
  STORE_RESULT; \
}
#endif
.........
DEF_MATH_FUNC (m,log2)
DEF_MATH_FUNC (o,log2)

在此处查找完整的源代码


5
log2(x) = log(x) / log(2),因此您可以轻松地自行计算(先计算log(2))。 - Alexandre C.
谢谢,我记得这是学校数学课程的内容。但我无法做到,因为我只能更改一些编译密钥或寻找另一种支持log2函数的神奇方法。我有兴趣在Android中默认支持log2。就像我之前说的,也许可以通过一些神奇的密钥实现。 - Laser
2个回答

8
你的神奇方法在这里。我已经测试过并且有效:
make CXXFLAGS="-Dlog2\(x\)=\(log\(x\)/log\(2\)\)"

更快的计算:
make CXXFLAGS="-Dlog2\(x\)=\(log\(x\)*1.4426950408889634\)"

1/log(2) 的值不应该是 3.32192809489 吗? - Miro Kropacek

4

看起来Android默认不支持log2函数。因为我在源代码中找不到这个函数的任何确定信息。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接