战俘实施双 [英] Pow implementation for double
问题描述
我开发一个code将被用于运动控制和我有战俘功能的问题。
我使用VS2010为IDE。
下面是我的问题:
我有:
双P = 100.0000;
双D = 1000.0000;
T1 = POW((P /(8.0000 * D)1.00 / 4.000);
在评价这最后的功能,我没有得到更好的近似作为结果。我得到一个7位十进制数字正确,以及随之而来的数字都是垃圾。
我猜测战俘功能只投下任何输入变量为float和计算proceds。
- 我说得对不对?
- 如果是这样,没有任何code,我可以得到启发与重新实现战俘美好precision?
编辑:解决
毕竟,我是有其正在使用OGRE 3D框架FPU配置位,造成Direct3D的问题。
如果使用OGRE,在配置界面,只需设置浮点模式=一致。
如果使用原始的Direct3D,调用CreateDevice的时候,一定要通过D3DCREATE_FPU_ preSERVE标志吧。
原帖:
您可能正在使用正在改变默认的precision一个libray
FPU的单幅precision。然后,所有的浮点运算,甚至
在双打中,实际上将作为单precision操作执行。
作为一个测试,你可以尝试调用_controlfp(_CW_DEFAULT,0xfffff);
执行计算之前(您需要包括)
看看你是否得到正确的结果。这将重置浮点
控制字为默认值。请注意,它会重置其他设置
同时,这可能会导致问题。
这改变了浮点precision一个常见的库
9的Direct3D(也许其他版本太):默认情况下,它改变了
FPU创建一个设备时,单幅precision。如果你使用它,指定
创建设备到prevent当标志D3DCREATE_FPU_ preSERVE它
从改变FPU precision。
块引用>解决方案您可以使用正在改变FPU的默认precision单幅precision一个libray。然后,所有的浮点运算,甚至在
双击
S,实际上将作为单precision操作执行。作为一个测试,你可以尝试调用
_controlfp(_CW_DEFAULT,0xfffff);
(您需要包括< FLOAT.H> 进行计算,看看您是否得到正确的结果之前,code>)。这将重置浮点控制字为默认值。请注意,它会重置其他设置为好,这可能会导致问题。
这改变了浮点precision一个共同库的Direct3D 9(也许其他版本太):默认情况下,它改变了FPU创建一个设备时,单幅precision。如果你使用它,请指定标志创建设备prevent当
D3DCREATE_FPU_ preSERVE
从改变FPU precision。I am developing a code that will be used for motion control and I am having a issue with the pow function. I am using VS2010 as IDE.
Here is my issue: I have:
double p = 100.0000; double d = 1000.0000; t1 = pow((p/(8.0000*d),1.00/4.000);
When evaluating this last function, I don't get the better approximation as result. I am getting a 7 decimal digits correct, and the consequent digits are all trash. I am guessing that pow function only casts any input variable as float and proceds with calculation.
- Am I right?
- If so, is there any code I can get "inspired" with to reimplement pow for a better precision?
Edit: Solved.
After all, I was having problems with FPU config bits, caused by Direct3D which was being used by OGRE 3D framework.
If using OGRE, on the config GUI, just set "Floating-point mode=Consistent".
If using raw Direct3D, when calling CreateDevice, make sure to pass "D3DCREATE_FPU_PRESERVE" flag to it.
Original post:
You may be using a libray that is changing the default precision of the FPU to single-precision. Then all floating-point operations, even on doubles, will actually be performed as single-precision operations.
As a test, you can try calling _controlfp( _CW_DEFAULT, 0xfffff ); (you need to include ) before performing the calculation to see if you get the correct result. This will reset the floating-point control word to default values. Note that it will reset other settings as well, which may cause issues.
One common library that changes the floating-point precision is Direct3D 9 (and maybe other versions too): By default, it changes the FPU to single-precision when creating a device. If you use it, specify the flag D3DCREATE_FPU_PRESERVE when creating the device to prevent it from changing the FPU precision.
解决方案You may be using a libray that is changing the default precision of the FPU to single-precision. Then all floating-point operations, even on
double
s, will actually be performed as single-precision operations.As a test, you can try calling
_controlfp( _CW_DEFAULT, 0xfffff );
(you need to include<float.h>
) before performing the calculation to see if you get the correct result. This will reset the floating-point control word to default values. Note that it will reset other settings as well, which may cause issues.One common library that changes the floating-point precision is Direct3D 9 (and maybe other versions too): By default, it changes the FPU to single-precision when creating a device. If you use it, specify the flag
D3DCREATE_FPU_PRESERVE
when creating the device to prevent it from changing the FPU precision.这篇关于战俘实施双的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!