我一直在寻找 GNU C 的选项,这样我的浮点程序可以生成比默认 gnu 设置生成的代码运行速度更快但精度更低的代码。
假设我有一个程序 my_fp_prog.c
double sqrt_two(return sqrt(2));
虽然准确答案应该是 1.414....,但我只需要答案 1.4,甚至 1.5 或 1.3 对我来说都可以,但我需要一个更快的程序。当然,我们案例使用更便宜的 sqrt 算法,但我正在寻找的是一个可以完成这项工作的编译器选项。希望存在这样的选择。
最佳答案
来自 GCC 的手册页:
-ffast-math
Sets
-fno-math-errno
,-funsafe-math-optimizations
,-ffinite-math-only
,-fno-rounding-math
,-fno-signaling-nans
and-fcx-limited-range
.This option causes the preprocessor macro
__FAST_MATH__
to be defined.This option is not turned on by any
-O
option besides-Ofast
since it can result in incorrect output for programs that depend on an exact implementation of IEEE or ISO rules/specifications for math functions. It may, however, yield faster code for programs that do not require the guarantees of these specifications.
关于c++ - 是否有一个 GNU C 编译器选项可以生成运行速度比默认设置更快但精度更低的浮点程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27336321/