浮点数的按位运算(对于图形)?
可能的重复:
如何对浮点数执行按位运算 < /p>
, 每个人!
背景:
我知道可以对图形应用按位运算(例如异或)。我还知道,在图形程序中,图形数据通常以浮点数据类型存储(例如能够将数据“乘以”1.05)。所以一定可以对浮点数据执行按位运算,对吧?
我需要能够对浮点数据执行按位运算。我不想想要将数据转换为长整型,按位操作它,然后转换回浮点数。
我认为,存在一种数学方法可以实现这一点,它更优雅(?)和/或更快(?)。
我已经看到了一些答案,但他们无济于事,包括这个。
编辑:
另一个问题涉及空指针转换,这将依赖于更深层次的数据表示。所以它不是“完全重复”。
Possible Duplicate:
how to perform bitwise operation on floating point numbers
Hello, everyone!
Background:
I know that it is possible to apply bitwise operation on graphics (for example XOR). I also know, that in graphic programs, graphic data is often stored in floating point data types (to be able for example to "multiply" the data with 1.05). So it must be possible to perform bitwise operations on floating point data, right?
I need to be able to perform bitwise operations on floating point data. I do not want to cast the data to long, bitwise manipulate it, and cast back to float.
I assume, there exist a mathematical way to achieve this, which is more elegant (?) and/or faster (?).
I've seen some answers but they could not help, including this one.
EDIT:
That other question involves void-pointer casting, which would rely on deeper-level data representation. So it's not such an "exact duplicate".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当“图形数据”到达屏幕时,它都不是浮点的。位运算实际上是对位串进行的。由于编码方案与二进制一致,位运算仅对数字有意义。除了提取指数或尾数之外,尝试对浮点数进行任何类型的逻辑按位运算都是一条通往地狱的道路。
基本上,您可能不想这样做。你认为你为什么这样做?
By the time the "graphics data" hits the screen, none of it is floating point. Bitwise operations are really done on bit strings. Bitwise operations only make sense on numbers because of consistent encoding scheme to binary. Trying to get any kind of logical bitwise operations on floats other than extracting the exponent or mantissa is a road to hell.
Basically, you probably don't want to do this. Why do you think you do?
浮点数只是内存中二进制的另一种表示形式,因此您可以:
这应该至少适用于非负值,并且应该没有相当大的计算开销,至少在像 C++ 这样的非托管上下文。也许您在执行操作时必须屏蔽一些位,并且 - 根据类型 - 您可能必须单独处理指数和基数。
A floating point number is just another representation of a binary in memory, so you could:
This should at least work with non-negative values and should have no considerable calculative overhead, at least in an unmanaged context like C++. Maybe you have to mask out some bits when doing your operation, and - depending of the type - you may have to treat exponent and base separately.