浮点与定点:哪些优点/缺点? [英] Floating point versus fixed point: what are the pros/cons?

查看:329
本文介绍了浮点与定点:哪些优点/缺点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

浮点型重$ P $通过分别存储在不同的二进制字的显著数字和它的指数,因此在16,32,64或128位符合psents一个数字。

Floating point type represents a number by storing its significant digits and its exponent separately on separate binary words so it fits in 16, 32, 64 or 128 bits.

定点类型存储数字与2个字,人们重新presenting整数部分,另一重presenting过去的基数的部分,在负指数,2 ^ -1,2 ^ -2,2 ^ -3等。

Fixed point type stores numbers with 2 words, one representing the integer part, another representing the part past the radix, in negative exponents, 2^-1, 2^-2, 2^-3, etc.

浮球更好,因为它们在一个指数意义更广范围内,但如果一个人想不与更precision存储数为一定的范围内,例如仅使用从-16到16的整数,因而使用较多的位持有位数过去的基数。

Float are better because they have wider range in an exponent sense, but not if one wants to store number with more precision for a certain range, for example only using integer from -16 to 16, thus using more bits to hold digits past the radix.

在表演方面,其中一个具有最佳性能,还是有情况下,一些比其他的快?

In terms of performances, which one has the best performance, or are there cases where some is faster than the other ?

在视频游戏编程,每个人都不会使用浮点因为FPU使得它速度更快,或者因为业绩下滑只是微不足道的,还是他们自己做固定式?

In video game programming, does everybody use floating point because the FPU makes it faster, or because the performance drop is just negligible, or do they make their own fixed type ?

为什么没有在任何C固定式/ C ++?

Why isn't there any fixed type in C/C++ ?

推荐答案

这定义涵盖定点实现非常有限的子集。

That definition covers a very limited subset of fixed point implementations.

这将是更正确地说,在固定点只有尾数存储和指数是一个常数确定的先验。没有为二进制点下跌尾数里面没有要求,绝对没有要求它落在一个字边界。例如,下面所有的都是定点:

It would be more correct to say that in fixed point only the mantissa is stored and the exponent is a constant determined a-priori. There is no requirement for the binary point to fall inside the mantissa, and definitely no requirement that it fall on a word boundary. For example, all of the following are "fixed point":


  • 64位尾数,由2 -32 (这符合中的问题列出的定义)
  • 缩放
  • 64位尾数,由2 -33 (现为整数和小数部分不能由一个八位组边界分开)
  • 缩放
  • 32位尾数,由2 4 (现在还没有小数部分)
  • 缩放
  • 32位尾数,由缩放2 -40 (现在有没有整数部分)

  • 64 bit mantissa, scaled by 2-32 (this fits the definition listed in the question)
  • 64 bit mantissa, scaled by 2-33 (now the integer and fractional parts cannot be separated by an octet boundary)
  • 32 bit mantissa, scaled by 24 (now there is no fractional part)
  • 32 bit mantissa, scaled by 2-40 (now there is no integer part)

的GPU倾向于使用固定点没有整数部分(通常为32位尾数2 -32 缩放)。因此,如API的OpenGL和Direct3D经常使用这是能够保持这些数值浮点类型。然而,操纵整数尾数往往是更有效的让这些API允许指定坐标(纹理空间,色彩空间等),这种方式为好。

GPUs tend to use fixed point with no integer part (typically 32-bit mantissa scaled by 2-32). Therefore APIs such as OpenGL and Direct3D often use floating-point types which are capable of holding these values. However, manipulating the integer mantissa is often more efficient so these APIs allow specifying coordinates (in texture space, color space, etc) this way as well.

至于你宣称C ++没有一个固定的点式,我不同意。在C ++中所有的整数类型定点类型。该指数通常被认为是零,但是这不是必需的,我有相当多的在C ++中这种方式实现定点DSP code的。

As for your claim that C++ doesn't have a fixed point type, I disagree. All integer types in C++ are fixed point types. The exponent is often assumed to be zero, but this isn't required and I have quite a bit of fixed-point DSP code implemented in C++ this way.

这篇关于浮点与定点:哪些优点/缺点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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