简体   繁体   English

为什么frexp()不能产生科学记数法?

[英]Why does frexp() not yield scientific notation?

Scientific notation is the common way to express a number with an explicit order of magnitude. 科学记数法是表达具有明确数量级的数字的常用方法。 First a nonzero digit, then a radix point, then a fractional part, and the exponent. 首先是非零数字,然后是小数点,然后是小数部分和指数。 In binary, there is only one possible nonzero digit. 在二进制中,只有一个可能的非零数字。

Floating-point math involves an implicit first digit equal to one, then the mantissa bits "follow the radix point." 浮点数学涉及隐含的第一个数字等于1,然后尾数位“跟随小数点”。

So why does frexp() put the radix point to the left of the implicit bit, and return a number in [0.5, 1) instead of scientific-notation-like [1, 2)? 那么为什么frexp()将小数点放在隐含位的左边,并返回[ frexp()的数字而不是像科学符号那样的[1,2]? Is there some overflow to beware of? 是否有一些溢出要小心?

Effectively it subtracts one more than the bias value specified by IEEE 754/ISO 60559. In hardware, this potentially trades an addition for an XOR. 实际上,它比IEEE 754 / ISO 60559规定的偏差值减去一个以上。在硬件中,这可能会增加XOR的附加值。 Alone, that seems like a pretty weak argument, considering that in many cases getting back to normal will require another floating-point operation. 考虑到在许多情况下恢复正常将需要另一个浮点运算,这似乎是一个相当弱的论点。

The rationale says: 理由说:

4.5.4.2 The frexp function 4.5.4.2 frexp函数

The functions frexp, ldexp, and modf are primitives used by the remainder of the library. 函数frexp,ldexp和modf是库的其余部分使用的基元。 There was some sentiment for dropping them for the same reasons that ecvt, fcvt, and gcvt were dropped, but their adherents rescued them for general use. 由于ecvt,fcvt和gcvt被丢弃的原因相同,因此放弃了他们的一些情绪,但是他们的追随者将它们拯救出来以供一般使用。 Their use is problematic: on nonbinary architectures ldexp may lose precision, and frexp may be inefficient. 它们的使用是有问题的:在非二进制体系结构上,ldexp可能会失去精度,而frexp可能效率低下。

One can speculate that the “remainder of the library” was more convenient to write with frexp 's convention, or was already traditionally written against this interface although it did not provide any benefit. 可以推测,使用frexp的约定来编写“库的其余部分”更方便,或者传统上已经针对此接口编写,尽管它没有提供任何好处。

I know that this does not fully answer the question, but it did not quite fit inside a comment. 我知道这并没有完全回答这个问题,但它并不适合评论。

I should also point out that some of the choices made in the design of the C language predate IEEE 754. Perhaps the format returned by frexp made sense with the PDP-11's floating-point format(s) , or any other architecture on which a function frexp was first introduced. 我还应该指出,在C语言设计中做出的一些选择早于IEEE 754. 也许frexp返回的格式与PDP-11的浮点格式或任何其他架构有关。函数frexp是介绍的。 EDIT: See also page 155 of the manual for one PDP-11 model. 编辑:另请参阅手册的第155页,了解一个PDP-11型号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM