gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 16:53:25 25 4
gpt4 key购买 nike

科学计数法是用明确的数量级来表示数字的常用方法。首先是非零数字,然后是小数点,然后是小数部分,最后是指数。在二进制中,只有一个可能的非零数字。

float 学涉及隐含的第一个数字等于 1,然后尾数位“跟随小数点”。

那么为什么 frexp() 将小数点放在隐含位的左侧,并返回 [0.5, 1) 中的数字而不是类似科学记数法的 [1, 2) ?是否有一些溢出需要注意?

实际上,它会比 IEEE 754/ISO 60559 指定的偏差值多减 1。在硬件中,这可能会用加法换取 XOR。考虑到在许多情况下恢复正常将需要另一个浮点运算,这似乎是一个非常弱的论据。

最佳答案

rationale说:

4.5.4.2 The frexp function

The functions frexp, ldexp, and modf are primitives used by the remainder of the library. 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. Their use is problematic: on nonbinary architectures ldexp may lose precision, and frexp may be inefficient.

可以推测“库的其余部分”用 frexp 的约定编写起来更方便,或者传统上已经针对此接口(interface)编写,尽管它没有提供任何好处。

我知道这并不能完全回答问题,但它不太适合评论。

我还应该指出,C 语言设计中的一些选择早于 IEEE 754。也许 frexp 返回的格式对 PDP-11 的 float 有意义-点格式,或首次引入函数frexp 的任何其他体系结构。编辑:另见 manual 的第 155 页对于一个 PDP-11 模型。

关于c - 为什么 frexp() 不产生科学记数法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24928833/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com