为什么没有无符号浮点类型? [英] Why no unsigned floating point types?

查看:272
本文介绍了为什么没有无符号浮点类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

为什么C没有未签名的浮动广告?


这个问题可能是非常基本的,可能早些时候回答了,但我想了解为什么C ++没有无符号浮点类型,即使浮点文字可以是有符号或无符号。


$ 3.9.1 / 8-有三个浮点
点类型:float,double和long
double。

$ b $无符号整数类型有两个重要的属性,它们区别于有符号整数类型:移位范围(没有负子范围,无负整数,但是正的子范围是宽的两倍)和模运算。对于整数类型,这些属性足够重要,足以证明存在无符号类型。



对于浮动类型,这些属性都不能立即适用。对于浮点类型,主要问题不在它们的范围内(对于许多目的,它可以被认为是无限的),而是精度。模数算术自然不适用于非整数类型。出于这个原因,引入无符号浮点类型没有多大意义,也就是说,它对浮点表示中只有一个位的作用没有多大意义。



还应当注意,上述推理应当被用作在流行的硬件和相应的硬件派生标准中引入无符号整数类型(并且不引入无符号浮点类型)的理论依据。我们在C和C ++中拥有的基本上是继承自硬件功能和这些标准。



当然,从概念的角度来看,无符号浮点类型的语言,只是为了一致性。但是,唉,他们不在那里。


Possible Duplicate:
Why doesn't C have unsigned floats?

The question is probably very basic and probably answered many time earlier, but I want to understand why C++ does not have unsigned floating point types, even though floating point literals can be signed or unsigned.

$3.9.1/8- "There are three floating point types: float, double, and long double."

解决方案

Unsigned integer types have two important properties that differentiate them from signed integer types: "shifted" range (no negative subrange, but positive subrange twice as wide) and modulo arithmetic. For integer types these properties are important enough to justify the existence of unsigned types.

With floating-types neither of these properties are immediately applicable. With floating-point types the main issue is not in their range (for many purposes it can be thought of as virtually infinite), but rather in precision. And modulo arithmetic is not naturally applicable to non-integer types. For this reason, it didn't make much sense to introduce unsigned floating-point types, i.e. it didn't make much sense to flip-flop the role of just one bit in the floating-point representation.

It should also be noted that the above reasoning should probably be used as rationale behind introducing unsigned integer types (and not introducing unsigned floating-point types) in popular hardware and corresponding hardware-derived standards. What we have in C and C++ was essentially inherited from the hardware capabilities and these standards.

Of course, from the conceptual point if view, it would be quite logical to have unsigned floating-point types in the language, just for the sake of consistency. But, alas they are not there.

这篇关于为什么没有无符号浮点类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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