My app is written in Delphi5. I am using madExcept to track down bugs. I tracked down a “Floating point dvision by zero” exception, where it shouldn’t be. The code segment, where it is raised, goes as followed:
val:=100*Power(1.25,c);
where ‘c’ actually always has the value ‘1’.
The stack trace of the log:
main thread ($338f8):
00403504 +010 MyApp.exe System 1970 +5 @FRAC
00479148 +058 MyApp.exe Math Power
007ae8a6 +262 MyApp.exe MyClass 1962 +36 TMyClass.FormMouseWheel
I had another exception at one point, where a division did take place, however the divisor was a variable, which also had the value ‘1’ when the exception occured. That i was able to debug and reproduce.
My question: what am i missing? Are there some false positives about floating point division that i am not aware of?
Furthermore: I am not using any C++ DLLs at the exception points as they tend to handle FP divisions differently (returning NaN or +/-INF rather than raising an exception).
Any pointers appreciated.
I just tried the following code:
It just compiles and runs as expected in Delphi 5.
My guess is that the division per zero flag may be set outside your code (even if you do not link to C++ code, calling Direct X or such may have the same effect), but raised later, in
_Frac.The only call to
Fracin the standard implementation ofPower()is to testFrac(Exponent) = 0.0.There was a modification in the implementation of
Fracbetween Delphi 5 and Delphi 6.Here is the Delphi 5 version:
Here is the Delphi 6 version:
From the above code, you’ll find out that the following commands caused the delayed exceptions to be raised before Delphi 6 was released: Trunc, Frac, Ceil.
So I guess you faced an issue with Delphi 5, which has been fixed with Delphi 6. You may have to use your own version of Power, like this one: