关于fixed-point

今天又出现了shader的问题,编译到真机效果就没了,后来仔细还是因为浮点数精度的问题,后来仔细查找了些资料,才发现自己太粗心,没有看清楚 fixed-point 数据类型就乱用,这是个范围在 [-1,+1]或者[-1,+2]之间的浮点数,我却当做普通的浮点数用,导致很多数据溢出,所以才丢失原有的效果,得注意了!

不明白的就去看 http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter03.html 的3.3.2小节吧

重点:Continuous quantities are not limited to integer values. When programming a CPU, programmers typically use floating-point data types to represent continuous values because floating-point types can represent fractional values. Continuous values processed by GPUs, particularly at the fragment level, have been limited to narrow ranges such as [0, 1] or [-1, +1], rather than supporting the expansive range provided by floating-point. For example, colors are often limited to the [0, 1] range, and normalized vectors are, by definition, confined to the [-1, +1] range. These range-limited data types are known as "fixed-point," rather than floating-point.

 

转载于:https://www.cnblogs.com/yaukey/p/3416290.html

Fixed-point arithmetic in MATLAB is used to represent and manipulate numbers with a fixed number of integer and fractional bits. This can be useful in applications such as digital signal processing, control systems, and communication systems where hardware implementation requires fixed-point arithmetic. To use fixed-point arithmetic in MATLAB, you can define data types with a fixed number of bits and a scaling factor. The scaling factor determines the range and precision of the fixed-point number. For example, a fixed-point number with a scaling factor of 0.5 and 8 bits can represent numbers in the range of -64 to 63 with a precision of 0.5. Here is an example of how to define a fixed-point data type in MATLAB: ``` % Define a fixed-point data type with 8 bits and a scaling factor of 0.5 T = fixdt(1,8,0.5); % Create a fixed-point number with value 2.75 x = fi(2.75,T); % Perform some operations on the fixed-point number y = x * 3; z = sqrt(y); ``` In the above example, the `fixdt` function defines a fixed-point data type with 8 bits and a scaling factor of 0.5. The `fi` function creates a fixed-point number with value 2.75 and data type `T`. The `*` and `sqrt` operations are performed on the fixed-point number `x`, resulting in fixed-point numbers `y` and `z`. MATLAB also provides tools for fixed-point conversion and scaling of algorithms and models. The `fiaccel` function can be used to generate C code from MATLAB code that uses fixed-point arithmetic. The `fimath` object can be used to specify the rounding and overflow behavior of fixed-point arithmetic operations. Overall, fixed-point arithmetic in MATLAB can be a powerful tool for designing and implementing digital systems.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值