如何确定浮点数的上限和下限? [英] How are upper and lower bounds for floating point numbers determined?

查看:598
本文介绍了如何确定浮点数的上限和下限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对下面的引文(N3797,3.9.1/8)有疑问:

I have a question about the quote below (N3797, 3.9.1/8):

浮点类型的值表示形式是实现定义的.

The value representation of floating-point types is implementation-defined.

据我所知,它为实施提供了完全的自由来定义浮点数的边界.它们在 template<class T> class numeric_format 中指定.例如,

As far as I understand it gives the implementation complete freedom in defining boundaries of floating point numbers. They are specified in template<class T> class numeric_format. For instance,

#include <iostream>
#include <limits>

int main()
{
    std::cout << "double_max = " << std::numeric_limits<double>().max() << std::endl;
    std::cout << "double_min = " << std::numeric_limits<double>().min() << std::endl;
    std::cout << "float_max = " << std::numeric_limits<float>().max() << std::endl;
    std::cout << "float_min = " << std::numeric_limits<float>().min() << std::endl;
}

演示

我的问题是:浮点数的上限和下限可以任意高还是低,或者有限制吗? 纯C 是否也为浮点数提供实现定义的一组值?

My question is: Can upper and lower boundaries for floating point numbers be arbitrarily high or low, or are there restrictions? Does pure C also provide an implementation defined set of values for floating point numbers?

我怀疑这取决于我们正在使用的体系结构.

I suspect it depends on the architecture we're working with.

推荐答案

内置类型的限制主要受硬件限制的约束. x64 CPU通常使用 IEEE 754 表示其FPA标准(硬件协处理器)中定义的浮点数据.

The limits for built-in types are mostly constrained by the hardware limits. x64 CPUs usually use IEEE 754 representations for their floating point data as defined in the FPA standard (hardware coprocessor).

无论如何,内部表示和处理事物的方式可能会有所不同

Anyway how things are internally represented and handled might vary as you noted

浮点类型的值表示形式是实现定义的

The value representation of floating-point types is implementation-defined

编译器通常具有底层目标系统的知识(特别是指进行代码生成的后端),因此可以在出现fp-arithmetic提示时选择正确的指令集.

a compiler usually has knowledge (especially referring to the back-end which does the code generation) of the underlying target system and can therefore choose the right set of instructions when prompted with fp-arithmetic.

您始终可以定义一个自定义数据类型来自行管理物理资源.您所指的术语可能是任意精度算术(如果数据适合硬件,通常速度要慢得多)报价,你应该去买.)

You can always define a custom datatype that manages physical resources yourself. The term you're referring might be Arbitrary precision arithmetic (usually considerably slower, if your data fits in what the hardware offers, you should go for it).

在特定情况下(例如某些嵌入式单元,其中没有FPU可用或无法执行浮点操作),可以使用仿真.尽管更慢,但它更便宜(晶体管更少).

In particular cases (e.g. some embedded units where no FPU is available or a floating point operation cannot be performed) emulation might be used. This is cheaper (less transistors) although slower.

这篇关于如何确定浮点数的上限和下限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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