Oracle Solaris Studio 12.4 Man Pages

Exit Print View

Updated: January 2015
 
 

ieee_flags(3M)

Name

ieee_flags - 访问浮点舍入模式和异常标志

Synopsis

cc [ flag ... ] file ...  -lsunmath -lm [ library ... ]
#include <sunmath.h>

int ieee_flags(const char *action, const char *mode,
     const char *in, char **out);

Description

此函数提供对 ANSI/IEEE Std 754-1985 所需的浮点舍入模式和异常标志的访问。actionmodein 参数是指定要执行的操作的不区分大小写的字符串的指针。无效的参数字符串和无效参数组合会产生不确定的结果。out 参数是类型为 char * 的对象的指针。如果 action 为 “get”,则将 *out 设置为指向提供所请求信息的某个只读字符串。对于 action 的所有其他值,*out 没有变化。

action 有四个有效值:“get”、“set”、“clear” 和 “clearall”。如果 action 是 “clearall”,则 ieee_flags() 将恢复缺省舍入模式(舍入方向为最接近的值,舍入精度扩展),并清除所有已发生异常标志。忽略 modein

如果 action 是 “get”、“set” 或 “clear”,则 mode 可以是以下任何一项:

 
“direction”       ... current rounding direction mode
“precision”       ... current rounding precision mode
“exception”       ... accrued exception flag status

如果 action 是 “clear” 并且 mode 为 “direction”,则 ieee_flags() 将舍入方向设置为最接近的值。如果 action 是 “clear” 并且 mode 是 “precision”,则 ieee_flags() 将舍入精度设置为扩展。在这两种情况下,都忽略 in

如果 action 是 “clear” 并且 mode 是 “exception”,则 ieee_flags() 清除由 in 指定的已发生异常标志,这可以是以下项之一:

 
“inexact”
“underflow”
“overflow”
“invalid”         ... invalid operation exception
“division”        ... division by zero exception
“all”             ... all five exceptions above
“common”          ... invalid, overflow, and division exceptions

如果 action 是 “set” 并且 mode 是 “direction”,则 ieee_flags() 将舍入方向设置为 in 指定的模式,这可以是以下项之一:

 
“nearest”         ... round toward nearest
“tozero”          ... round toward zero
“negative”        ... round toward negative infinity
“positive”        ... round toward positive infinity

如果 action 是 “set” 并且 mode 是 “precision”,则 ieee_flags() 将舍入方向设置为 in 指定的模式,这可以是以下项之一:

 
“extended”
“double”
“single”
 

如果 action 是 “set” 并且 mode 是 “exception”,则 ieee_flags() 将设置 in 指定的已发生异常标志,这可以是上面列出的异常字符串之一。

如果 action 是 “get” 并且 mode 是 “direction”,则 ieee_flags() 将 *out 设置为上面列出的对应于当前舍入方向的舍入方向模式字符串。如果 action 是 “get” 并且 mode 是 “precision”,则 ieee_flags() 将 *out 设置为上面列出的对应于当前舍入精度的舍入精度模式字符串。在这两种情况下,都忽略 in

如果 action 是 “get” 并且 mode 是 “exception”,则 ieee_flags() 将 *out 设置为以下字符串之一:

 
(a) “not available” if accrued exception flags are not available,
(b) “” (the empty string) if there are no accrued exceptions,
(c) the accrued exception that has the highest priority according 
    to the list below

     (1) the exception named by in,
     (2) “invalid”,
     (3) “overflow”,
     (4) “division”,
     (5) “underflow”,
     (6) “inexact”.

返回值

返回值

如果 action 是 “get”,则返回值使用在 <sys/ieeefp.h> 中定义的各种 enum 类型的值对请求的信息进行编码。特别是,当 mode 是 “direction” 时,ieee_flags() 返回对应于当前舍入方向的 enum fp_direction_type 值。如果 mode 是 “precision”,则 ieee_flags() 返回对应于当前舍入精度的 enum fp_precision_type 值。如果 mode 是 “exception”,则 ieee_flags() 返回所有已发生异常标志的按位“或”,其中对应于每个异常的位位置由 enum fp_exception_type 定义。对于 mode 的其他值,ieee_flags() 返回 0。

如果 action 是 “set”,则 ieee_flags() 在无法设置请求的模式(例如,由于硬件不支持)时返回 1,否则返回 0。

对于 action 的所有其他值,ieee_flags() 返回 0。

Examples

 
#include <sunmath.h>

char *out;
int k;

/* report rounding precision */
(void) ieee_flags("get", "precision", "", &out);
printf("current rounding precision is %s\n", out);

/* set rounding direction to round toward zero */
k = ieee_flags("set", "direction", "tozero", &out);
if (k)
     printf("cannot set rounding direction\n");

/* clear all exception flags */
(void) ieee_flags("clear", "exception", "all", &out);

...
... (code that generates three exceptions: overflow, invalid, inexact)
...

/* restore default rounding direction */
(void) ieee_flags("clear", "direction", "", &out);

/* get accrued exceptions */
k = ieee_flags("get", "exception", "overflow", &out);

此时,out 指向字符串 “overflow”,在 SPARC 上,k = 25 = 0x19。

Attributes

有关下列属性的说明,请参见 attributes(5):

属性类型
属性值
接口稳定性
Committed(已确定)
MT 级别
MT-Safe(MT 安全)

See also

feclearexcept(3M)、fegetenv(3M)、fegetexceptflag(3M)、fegetprec(3M)、fegetround(3M)、feholdexcept(3M)、feraiseexcept(3M)、fetestexcept(3M)、feupdateenv(3M)、fex_merge_flags(3M)、fex_set_handling(3M)、ieee_handler(3M)、attributes(5)

Notes

在 SPARC 上,没有舍入精度模式。如果 mode 是 “precision”,则 ieee_flags() 不执行任何操作并返回 0。

在 x86 上,舍入精度模式仅影响基本 x87 浮点运算指令。它不影响 SSE 指令。