选项 -lquadmath
说明
此选项使用128位四精度浮点数库,请在需要使用四精度浮点数库的时候加上该链接选项进行编译。
使用方法
- 编译命令变更前:
1 2
gcc test.c -o test.out -lquadmath -DAARCH64_QUADMATH ./test.out
- 编译命令变更后:
无需显式指定 -DAARCH64_QUADMATH 宏,AArch64 平台下已默认启用 __aarch64__ 预定义宏。
1 2
gcc test.c -o test.out -lquadmath ./test.out
- 存量工程适配建议:
- 示例代码:test.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#include <stdio.h> #include <math.h> #include <quadmath.h> #define USE_FLOAT128 1 int main() { #ifdef USE_FLOAT128 typedef __float128 long_double_t; #else typedef long double long_double_t; #endif long_double_t ld=0.1; long_double_t res; int* i = (int*) &res; i[0] = i[1] = i[2] = i[3] = 0xdeadbeef; for(ld = 0.0000000000000001; ld < __LDBL_MAX__; ld += 0.0000000000000001) { res = tanq(ld); printf("%08x-%08x-%08x-%08x\r", i[0], i[1], i[2], i[3]); } return 0; }
结果
执行编译结果可见,全部128位输出均产生预期变化,该现象表明128位计算已使能。
父主题: 静态编译优化