什么是“字符序列"? NaN生成函数的参数? [英] What is the "char-sequence" argument to NaN generating functions for?

查看:169
本文介绍了什么是“字符序列"? NaN生成函数的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了NAN宏外,C99还有两种生成浮点数的NaN值的方法,即nanf(const char *tagp)函数和strtof("NAN(char-sequence)").

Aside from the NAN macro, C99 has two ways to generate a NaN value for a floating point number, the nanf(const char *tagp) function and strtof("NAN(char-sequence)").

这两种生成NaN的方法都采用可选的字符串参数(nanf()中的* tagp和strtof方法中的char-sequence).这个字符串参数究竟是做什么的?我还没有找到任何有关如何使用它的具体示例.在 cppreference.com 中,我们拥有:

Both of these methods of generating a NaN take an optional string argument (*tagp in nanf() and the char-sequence in the strtof method). What exactly does this string argument do? I haven't been able to find any concrete examples of how you'd use it. From cppreference.com we have:

调用nan("string")等效于调用strtod("NAN(string)",(char **)NULL);

The call nan("string") is equivalent to the call strtod("NAN(string)", (char**)NULL);

调用nan(")等效于调用strtod("NAN()",(char **)NULL);

The call nan("") is equivalent to the call strtod("NAN()", (char**)NULL);

调用nan(NULL)等效于调用strtod("NAN",(char **)NULL);

The call nan(NULL) is equivalent to the call strtod("NAN", (char**)NULL);

nan(3)说:

这些函数返回安静的NaN的表示形式(由tagp确定). [片段] 参数tagp的使用方式不确定.在IEEE 754系统上,有许多NaN表示,并且 tagp选择一个.

These functions return a representation (determined by tagp) of a quiet NaN. [snip] The argument tagp is used in an unspecified manner. On IEEE 754 systems, there are many representations of NaN, and tagp selects one.

这并不能真正告诉我可以为tagp字符串使用什么或为什么要使用它.在该标签字符串的任何有效选项的任何地方都有列表,并且原因是在默认的nanf(NULL)上使用一个吗?

This doesn't really tell me what I can use for the tagp string or why I'd ever want to use it. Is there a list anywhere of the valid options for this tag string, and what would the reason be to use one over the default nanf(NULL)?

推荐答案

Tl; Dr:tagp参数使您能够具有不同的NAN值.

Tl;Dr : tagp argument gives you the ability to have different NAN values.

这来自nan(3)的手册页,其中提供了有关tagp的更多信息.

This is from man page for nan(3) which gives a little more information on tagp.

主要是:

nan()函数返回一个安静的NaN,其尾随分数字段 包含转换结果 将tagp转换为无符号整数.

The nan() functions return a quiet NaN, whose trailing fraction field contains the result of converting tagp to an unsigned integer.

这使您能够具有不同的 NAN值.

This gives you the ability to have different NAN values.

特别是根据C99基本原理 doc :

Specifically from the C99 Rationale doc:

NaN的其他应用可能证明是有用的. NaN的可用部分 已用于编码辅助信息,例如有关 NaN的来历.用信号通知NaN可能是填充的候选者 未初始化的存储;他们可用的部分可以区分 未初始化的浮动对象. IEC 60559信号NaN和陷阱 处理程序可能会提供用于维护诊断的挂钩 信息或实现特殊算术.

Other applications of NaNs may prove useful. Available parts of NaNs have been used to encode auxiliary information, for example about the NaN’s origin. Signaling NaNs might be candidates for filling uninitialized storage; and their available parts could distinguish uninitialized floating objects. IEC 60559 signaling NaNs and trap handlers potentially provide hooks for maintaining diagnostic information or for implementing special arithmetics.

有一个实现这里.请注意,这可能符合或可能不符合标准,如评论中所述.但是,它应该使您了解tagp的用途.

There is an implementation of it here. Mind you, this may or may not be standard conforming, as noted in comments. However, it should give you an idea of what tagp is used for.

与手册页一样,您可以看到上面提到的替换内容:

As in the man page, you can see the replacement mentioned above:

nan("1") = nan (7ff8000000000001)
nan("2") = nan (7ff8000000000002)

完整的手册页:

NAN(3)BSD库功能手册
NAN(3)

NAN(3) BSD Library Functions Manual
NAN(3)

NAME nan-生成一个安静的NaN

NAME nan -- generate a quiet NaN

简介 #include

SYNOPSIS #include

 double
 nan(const char *tagp);

 long double
 nanl(const char *tagp);

 float
 nanf(const char *tagp);

说明 nan()函数返回一个安静的NaN,其尾随分数字段包含转换后的结果 tagp为无符号整数.如果tagp太大而无法包含在 NaN,则使用由tagp表示的整数的最低有效位.

DESCRIPTION The nan() functions return a quiet NaN, whose trailing fraction field contains the result of converting tagp to an unsigned integer. If tagp is too large to be contained in the trailing fraction field of the NaN, then the least significant bits of the integer represented by tagp are used.

特殊值 如果tagp包含任何非数字字符,则该函数返回NaN whos尾随分数字段为 零.

SPECIAL VALUES If tagp contains any non-numeric characters, the function returns a NaN whos trailing fraction field is zero.

如果tagp为空,则该函数返回NaN whos的尾随分数字段为零.

If tagp is empty, the function returns a NaN whos trailing fraction field is zero.

标准 nan()函数符合ISO/IEC 9899:2011.

STANDARDS The nan() functions conform to ISO/IEC 9899:2011.

BSD 2008年7月1日

BSD July 01, 2008

这篇关于什么是“字符序列"? NaN生成函数的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆