Delphi "Invalid floating point operation." Wrong workaround (Use the SET8087CW function provided by the system unit to disable floating-point exceptions)

Source: Internet
Author: User

These two days write things with Webbrower, sometimes open SSL encryption site will appear "Invalid floating point operation." Error, the Internet search, the solution is affixed.

导致原因


在Delphi2011中需要通过浮点单位控制指令设置浮点运算单位。浮点单位控制指令控制着浮点运算的精度、四舍五入的方式以及特定的浮点运算是否触发异常。可以参阅Intel处理器的详细文档。


在Delphi2011中有函数可以直接访问处理器的控制指令。比如,可以使用Set8087CW函数改变8087CW控制指令的值,从而改变程序浮点计算的行为。编程人员需要自己负责在程序结束时重置这个指令。


solution, is to disable floating-point exceptions directly, by doing the following:
In Delphi2011, when using OpenGL for 3D rendering, it is recommended to use the SET8087CW function to disable floating-point exceptions. Can be written before the OpenGL function is called, such as in the MainForm OnCreate: SET8087CW (0x133f)
Instance code:
1. Declare global variables to save the original 8087CW settings
Var
Saved8087cw:word;
2. Change the value of 8087CW in the oncreate process of MainForm, save the default value before changing
SAVED8087CW: = DEFAULT8087CW;
SET8087CW ($133f); {Disable all FPU exceptions}
3. Reset the 8087CW instruction value using the default value before the program ends. In the onclose process of mainform
SET8087CW (SAVED8087CW);
4. It is also important to note that If you use Scenecontrol.loadsxfile to load a 3D document in your program, you must call Iscene's Clearlayers method to clear the layer before SET8087CW exits, or the program exits with an exception.
The reference code is:
SceneControl1.Scene.ClearLayers;
SET8087CW (SAVED8087CW);
5. There is also a need to call the following statement before the program exits
(Coaoinitialize.create as Iaoinitialize). Shutdown

http://blog.csdn.net/shuaihj/article/details/6406781

Delphi "Invalid floating point operation." Wrong workaround (Use the SET8087CW function provided by the system unit to disable floating-point exceptions)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.