C ++标准在哪里定义浮点类型的值范围? [英] Where does C++ standard define the value range of float types?

查看:98
本文介绍了C ++标准在哪里定义浮点类型的值范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,浮点值的形式为n * 2 ^ e,




  • 浮点范围为n = (2 ^ 23-1) - (2 ^ 23-1)和e = -126-127,

  • 双范围是n = - (2 ^ 52-1) - 2 ^ 52-1)和e = -1022 - 1023



我正在浏览C ++标准,但找不到标准规定的位置,或者强制float,double和long double类型与其他(IEEE)标准中定义的范围的关联。我在3.9.1.8中发现的唯一相关的事情是:


有三种浮点类型:float,double和long double。 double类型提供的精度至少与float类似,long类型的double类型提供至少与double类似的精度。 float类型的值的集合是double类型的值的集合的子集;类型double的值的集合是类型long double的值的集合的子集。浮点类型的值表示是实现定义的。


没有提到类型提供的最小范围。 p>

标准如何指定浮点类型的(最小?)值范围?

解决方案

就像整数数字限制一样,从C标准导入code> float , double long double 。常数 FLT_MAX DBL_MAX LDBL_MAX 的最小值为 1E + 37 。对于 * _ MIN 变体,最大值为 1E-37


As far as I know floating point values are of the form n * 2^e, with

  • float range being n = -(2^23-1) - (2^23-1), and e = -126 - 127,
  • double range being n = -(2^52-1) - (2^52-1), and e = -1022 - 1023

I was looking through the C++ standard, but failed to find the place where the standard specifies this, or mandates the association of the float, double and long double types with ranges defined in other (IEEE) standards. The only related thing I found in 3.9.1.8 is:

There are three floating point types: float, double, and long double. The type double provides at least as much precision as float, and the type long double provides at least as much precision as double. The set of values of the type float is a subset of the set of values of the type double; the set of values of the type double is a subset of the set of values of the type long double. The value representation of floating-point types is implementation-defined.

And no mention of the minimum range provided by the type.

Where/how does the standard specify the (minimum?) value range of the floating point types? Or can a compiler freely choose any value range and still be standard compliant?

解决方案

Just like integer numberic limits, the limits for float, double and long double are imported from the C standard. The minimum value for constants FLT_MAX, DBL_MAX and LDBL_MAX is 1E+37. For their *_MIN variants the maximum value is 1E-37.

这篇关于C ++标准在哪里定义浮点类型的值范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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