Search code examples
delphifiredac

Floating point inexact result exception in TFDTable Component in Delphi


I am using TFDTable component in Delphi Seattle. I have kept this table component at design time.

While executing TFDTable(Compo).Open

I get error while debugging (Ctrl +F7) "Floating point inexact result at 0042F353"

I googled, but got the reason but didn't get exactly what it is.

Any suggestions?

Reference URL:

http://www.delphigroups.info/2/e8/524771.html

Floating Point inexact result

This exception suggests that you have the "loss of precision" mask bit in the FPU turned OFF. It is normally ON. Look for the $0020 bit in the system variable Default8087CW and try ORing in $0020 into the control word with a Set8087CW(Default8087CW or $0020) statement.

http://www.umiacs.umd.edu/~resnik/ling645_sp2002/cmu_manual/node19.html


Solution

  • There is a well known issue that Default8087CW as a global variable can be misused by libraries or even your own code and be changed at any time in ways that cause unexpected results of FP calculations or unexpected exceptions to occur. The six lowest bits of the 8087 FPU Control word are the exception mask bits, meaning that if a bit is set, corresponding exception is masked, that is prevented from being raised.

    The "loss of precision" mask bit that John Herbster is talking about is one of those bits, in Delphis TArithmeticException enum called exPrecision. Further he suggests to assure this bit is set by calling the Set8087CW(Default8087CW or $0020). Since you are using Delphi 10 Seattle, it is recommended to use the SetExceptionMask() function (from the System.Math unit) instead, since it handles equally also the corresponding SSE mask on 64 bit hw:

    var
      OldExceptionMask: TArithmeticExceptionMask;
    ...
    OldExceptionMask := SetExceptionMask(GetExceptionMask + [exPrecision]);
    

    Calling the above before TFDTable(Compo).Open should solve your problem.

    The function takes and returns a TArithmeticExceptionMask (set of TArithmeticException). All other exception enums and FPU/SSE related functions are in the documentation.