选项 -lquadmath

说明

此选项使用128位四精度浮点数库,请在需要使用四精度浮点数库的时候加上该链接选项进行编译。

使用方法

用例:test.c

变更前编译命令:

1
2
gcc test.c -o test.out -lquadmath -DAARCH64_QUADMATH
./test.out

变更后编译命令:不再需要 -DAARCH64_QUADMATH 编译宏,变更为 __aarch64__ 编译宏,并且 AArch64 平台下默认使能该宏

存量工程适配接口变更建议:无需修改文件,已添加的 -DAARCH64_QUADMATH 宏将作为无效宏而无影响

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位计算已使能。