下一个较高/较低的IEEE双精度数字 [英] next higher/lower IEEE double precision number
问题描述
困难在于IEEE格式不完全统一。如果使用低级代码,并且实际上将一个添加到最低有效位,则生成的格式可能不是下一个可用的双精度。例如,它可能是一个特殊的案例编号,如PositiveInfinity或NaN。还有一些非正常值,我不声称理解,但似乎具有与正常模式不同的特定位模式。
epsilon值是可用的,但我从来没有理解它的定义。由于双重值不是均匀的间隔,所以没有一个值可以添加到双精度值以产生下一个较高的值。
我真的不明白为什么IEEE hasn' t指定一个函数来获取下一个更高或更低的值。我不能是唯一需要它的人。
有没有办法获取下一个值(没有某种循环,试图添加越来越小的值)。
有可用于完成这些功能的功能,但它们可以依赖于您使用的语言。两个例子:
-
如果您可以访问一个体面的C99数学库,可以使用
nextafter
(及其浮动和长双倍变体,nextafterf
和nextafterl
);或nexttoward
家庭(这需要长双倍的第二个参数)。 -
如果你写Fortran您的
最近
内在可用
如果您无法直接从您的语言访问这些,您还可以查看他们的可以免费获得,例如这一个。
I am doing high precision scientific computations. In looking for the best representation of various effects, I keep coming up with reasons to want to get the next higher (or lower) double precision number available. Essentially, what I want to do is add one to the least significant bit in the internal representation of a double.
The difficulty is that the IEEE format is not totally uniform. If one were to use low-level code and actually add one to the least significant bit, the resulting format might not be the next available double. It might, for instance, be a special case number such as PositiveInfinity or NaN. There are also the sub-normal values, which I don't claim to understand, but which seem to have specific bit patterns different from the "normal" pattern.
An "epsilon" value is available, but I have never understood its definition. Since double values are not evenly spaced, no single value can be added to a double to result in the next higher value.
I really don't understand why IEEE hasn't specified a function to get the next higher or lower value. I can't be the only one who needs it.
Is there a way to get the next value (without some sort of a loop which tries to add smaller and smaller values).
There are functions available for doing exactly that, but they can depend on what language you use. Two examples:
if you have access to a decent C99 math library, you can use
nextafter
(and its float and long double variants,nextafterf
andnextafterl
); or thenexttoward
family (which take a long double as second argument).if you write Fortran, you have the
nearest
intrinsic available
If you can't access these directly from your language, you can also look at how they're implemented in freely available, such as this one.
这篇关于下一个较高/较低的IEEE双精度数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!