Next: , Previous: Integer library routines, Up: Libgcc


4.2 浮点模拟例程

软件浮点库用于不支持硬件浮点计算的机器上。也用于通过-msoft-float禁止生成浮点指令的场合。(并不是琐有的目标机都支持该开关选项。)

为了和其它编译器兼容,可以使用DECLARE_LIBRARY_RENAMES来重命名浮点模拟例程(参见Library Calls)。在这一章,使用了缺省的名字。

目前库不支持在一些机器上用于long doubleXFmode

4.2.1 算术函数

— Runtime Function: float __addsf3 (float a, float b)
— Runtime Function: double __adddf3 (double a, double b)
— Runtime Function: long double __addtf3 (long double a, long double b)
— Runtime Function: long double __addxf3 (long double a, long double b)

这些函数返回ab的和。

— Runtime Function: float __subsf3 (float a, float b)
— Runtime Function: double __subdf3 (double a, double b)
— Runtime Function: long double __subtf3 (long double a, long double b)
— Runtime Function: long double __subxf3 (long double a, long double b)

这些函数返回ba的差,也就是a - b

— Runtime Function: float __mulsf3 (float a, float b)
— Runtime Function: double __muldf3 (double a, double b)
— Runtime Function: long double __multf3 (long double a, long double b)
— Runtime Function: long double __mulxf3 (long double a, long double b)

这些函数返回ab的积。

— Runtime Function: float __divsf3 (float a, float b)
— Runtime Function: double __divdf3 (double a, double b)
— Runtime Function: long double __divtf3 (long double a, long double b)
— Runtime Function: long double __divxf3 (long double a, long double b)

这些函数返回ab的商,也就是a / b

— Runtime Function: float __negsf2 (float a)
— Runtime Function: double __negdf2 (double a)
— Runtime Function: long double __negtf2 (long double a)
— Runtime Function: long double __negxf2 (long double a)

这些函数返回a的负数。它们只是简单的反转符号位,因此能够产生负0和负NaN。

4.2.2 转换函数

— Runtime Function: double __extendsfdf2 (float a)
— Runtime Function: long double __extendsftf2 (float a)
— Runtime Function: long double __extendsfxf2 (float a)
— Runtime Function: long double __extenddftf2 (double a)
— Runtime Function: long double __extenddfxf2 (double a)

这些函数将a扩展为它们返回类型的模式。

— Runtime Function: double __truncxfdf2 (long double a)
— Runtime Function: double __trunctfdf2 (long double a)
— Runtime Function: float __truncxfsf2 (long double a)
— Runtime Function: float __trunctfsf2 (long double a)
— Runtime Function: float __truncdfsf2 (double a)

这些函数将a截短为它们返回类型的模式,并向0方向舍入。

— Runtime Function: int __fixsfsi (float a)
— Runtime Function: int __fixdfsi (double a)
— Runtime Function: int __fixtfsi (long double a)
— Runtime Function: int __fixxfsi (long double a)

这些函数将a转换为有符号整数,并向0方向舍入。

— Runtime Function: long __fixsfdi (float a)
— Runtime Function: long __fixdfdi (double a)
— Runtime Function: long __fixtfdi (long double a)
— Runtime Function: long __fixxfdi (long double a)

这些函数将a转换为有符号长整数,并向0方向舍入。

— Runtime Function: long long __fixsfti (float a)
— Runtime Function: long long __fixdfti (double a)
— Runtime Function: long long __fixtfti (long double a)
— Runtime Function: long long __fixxfti (long double a)

这些函数将a转换为有符号long long整数,并向0方向舍入。

— Runtime Function: unsigned int __fixunssfsi (float a)
— Runtime Function: unsigned int __fixunsdfsi (double a)
— Runtime Function: unsigned int __fixunstfsi (long double a)
— Runtime Function: unsigned int __fixunsxfsi (long double a)

这些函数将a转换为无符号整数,并向0方向舍入。将负值都变为0。

— Runtime Function: unsigned long __fixunssfdi (float a)
— Runtime Function: unsigned long __fixunsdfdi (double a)
— Runtime Function: unsigned long __fixunstfdi (long double a)
— Runtime Function: unsigned long __fixunsxfdi (long double a)

这些函数将a转换为无符号长整数,并向0方向舍入。将负值都变为0。

— Runtime Function: unsigned long long __fixunssfti (float a)
— Runtime Function: unsigned long long __fixunsdfti (double a)
— Runtime Function: unsigned long long __fixunstfti (long double a)
— Runtime Function: unsigned long long __fixunsxfti (long double a)

这些函数将a转换为无符号long long整数,并向0方向舍入。将负值都变为0。

— Runtime Function: float __floatsisf (int i)
— Runtime Function: double __floatsidf (int i)
— Runtime Function: long double __floatsitf (int i)
— Runtime Function: long double __floatsixf (int i)

这些函数将有符号整数i转换为浮点数。

— Runtime Function: float __floatdisf (long i)
— Runtime Function: double __floatdidf (long i)
— Runtime Function: long double __floatditf (long i)
— Runtime Function: long double __floatdixf (long i)

这些函数将有符号长整数i转换为浮点数。

— Runtime Function: float __floattisf (long long i)
— Runtime Function: double __floattidf (long long i)
— Runtime Function: long double __floattitf (long long i)
— Runtime Function: long double __floattixf (long long i)

这些函数将有符号long long整数i转换为浮点数。

— Runtime Function: float __floatunsisf (unsigned int i)
— Runtime Function: double __floatunsidf (unsigned int i)
— Runtime Function: long double __floatunsitf (unsigned int i)
— Runtime Function: long double __floatunsixf (unsigned int i)

这些函数将无符号整数i转换为浮点数。

— Runtime Function: float __floatundisf (unsigned long i)
— Runtime Function: double __floatundidf (unsigned long i)
— Runtime Function: long double __floatunditf (unsigned long i)
— Runtime Function: long double __floatundixf (unsigned long i)

这些函数将无符号长整数i转换为浮点数。

— Runtime Function: float __floatuntisf (unsigned long long i)
— Runtime Function: double __floatuntidf (unsigned long long i)
— Runtime Function: long double __floatuntitf (unsigned long long i)
— Runtime Function: long double __floatuntixf (unsigned long long i)

这些函数将无符号long long整数i转换为浮点数。

4.2.3 比较函数

有两组基本的比较函数。

— Runtime Function: int __cmpsf2 (float a, float b)
— Runtime Function: int __cmpdf2 (double a, double b)
— Runtime Function: int __cmptf2 (long double a, long double b)

这些函数计算a <=> b。也就是,如果a小于b,则返回-1;如果a大于b,则返回1;如果ab相等,则返回0。如果有任一参数为NaN,则返回1,但你不要依赖于这点;如果可以出现NaN,则使用高级的比较函数。

— Runtime Function: int __unordsf2 (float a, float b)
— Runtime Function: int __unorddf2 (double a, double b)
— Runtime Function: int __unordtf2 (long double a, long double b)

这些函数返回一个非0值,如果任一参数为NaN,否则返回0。

还有一个直接对应于比较运算符的高级别函数的完备群。它们实现了浮点运算的ISO C语义,将NaN考虑了进来。要仔细注意每组的返回值定义。(Under the hood),所有这些函数都被实现为:

       if (__unordXf2 (a, b))
         return E;
       return __cmpXf2 (a, b);

其中E是一个常数,被选来给出对于NaN的合适行为。因此,返回值的意义对于每组都不同。不要依赖于这些实现;只有在下面被说明的语义才有担保。

— Runtime Function: int __eqsf2 (float a, float b)
— Runtime Function: int __eqdf2 (double a, double b)
— Runtime Function: int __eqtf2 (long double a, long double b)

如果参数都不为NaN,并且ab相等,则这些函数返回0。

— Runtime Function: int __nesf2 (float a, float b)
— Runtime Function: int __nedf2 (double a, double b)
— Runtime Function: int __netf2 (long double a, long double b)

如果有任一参数为NaN,或者ab不相等,则这些函数返回非0。

— Runtime Function: int __gesf2 (float a, float b)
— Runtime Function: int __gedf2 (double a, double b)
— Runtime Function: int __getf2 (long double a, long double b)

如果参数都不为NaN,并且a大于或等于b,则这些函数返回一个大于或等于0的值。

— Runtime Function: int __ltsf2 (float a, float b)
— Runtime Function: int __ltdf2 (double a, double b)
— Runtime Function: int __lttf2 (long double a, long double b)

如果参数都不为NaN,并且a严格小于b,则这些函数返回一个小于0的值。

— Runtime Function: int __lesf2 (float a, float b)
— Runtime Function: int __ledf2 (double a, double b)
— Runtime Function: int __letf2 (long double a, long double b)

如果参数都不为NaN,并且a小于或等于b,则这些函数返回一个小于或等于0的值。

— Runtime Function: int __gtsf2 (float a, float b)
— Runtime Function: int __gtdf2 (double a, double b)
— Runtime Function: int __gttf2 (long double a, long double b)

如果参数都不为NaN,并且a严格大于b,则这些函数返回一个大于0的值。

4.2.4 其它浮点函数

— Runtime Function: float __powisf2 (float a, int b)
— Runtime Function: double __powidf2 (double a, int b)
— Runtime Function: long double __powitf2 (long double a, int b)
— Runtime Function: long double __powixf2 (long double a, int b)

这些函数求得ab次幂。

— Runtime Function: complex float __mulsc3 (float a, float b, float c, float d)
— Runtime Function: complex double __muldc3 (double a, double b, double c, double d)
— Runtime Function: complex long double __multc3 (long double a, long double b, long double c, long double d)
— Runtime Function: complex long double __mulxc3 (long double a, long double b, long double c, long double d)

这些函数返回a + ibc + id的乘积,遵从C99附录G的规则。

— Runtime Function: complex float __divsc3 (float a, float b, float c, float d)
— Runtime Function: complex double __divdc3 (double a, double b, double c, double d)
— Runtime Function: complex long double __divtc3 (long double a, long double b, long double c, long double d)
— Runtime Function: complex long double __divxc3 (long double a, long double b, long double c, long double d)

这些函数返回a + ibc + id的商(即 (a + ib) / (c + id)),遵从C99附录G的规则。