View Issue Details
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0019674||Lazarus||Widgetset||public||2011-07-03 13:38||2011-07-08 12:49|
|Reporter||Zoran Vučenović||Assigned To||Maxim Ganetsky|
|Status||closed||Resolution||no change required|
|Product Version||0.9.30.1 (SVN)|
|Summary||0019674: Problems with floating point operations (not raising exceptions)|
|Description||It is reported in forum (topic: http://www.lazarus.freepascal.org/index.php/topic,13460.0.html) that compiler behaves differently on Linux and Windows when dividing.|
It actually seems that lcl with gtk2 widgetset sets ExceptionMask variable to non-default value, which causes floating point exceptions not to be raised.
I believe that this floating point behavior should not depend on widgetset. The programmer should assume that if these exceptions are raised on one platform, they will be raised on another.
|Additional Information||The uploaded zip file contains two very simple examples to illustrate this - a gui application and a command line one.|
You can see that for inputs 5 and 0 command line application reports that EDivByZero was raised. For 0 and 0 EInvalidOp.
The GUI application, when compiled on Windows, reports the same. However, with gtk2 on Linux it gives +inf for 5 and 0, and NaN for 0 and 0. I haven't tested with Qt.
I believe that this behavior with floating point exceptions should not depend on widgetset. The default behavior should be same and known and the programmer should not be bothered with ExceptionMask unless (s)he wants non-default behavior.
|Tags||No tags attached.|
|Fixed in Revision|
TestDiv.zip (5,704 bytes)
If the Gtk2 widgetset adds this masking it is most likely because it was necessary, because someone in the past had trouble without this code. Gtk2 is a C library and depending on its version and compilation (or maybe always?), C libraries might crash if we throw exceptions to zero divizions.
So in general, I doubt that simply removing the code that does this will be a safe solution.
||GTK2 cannot be run with exceptions enabled because the C code assumes that exceptions are turned off. Windows gui libs does not make this assumption so exceptions can be left turned on. There is not much which can be done about this: so either use another gui library or turn on/off exceptions as your code needs them while not calling gui related stuff.|
Thank you. At least this should be documented.
I made a test:
The FPC default exception mask (without Gtk2):
[exDenormalized, exUnderflow, exPrecision]
When Gtk2 library is included, everything except exOverflow is masked:
[exInvalidOp, exDenormalized, exZeroDivide, exUnderflow, exPrecision]
Feel free to describe this behavior in the wiki.
Resolved as "no change required", because this is not a bug.
Please close if ok.
||Would changing the mask during gtk calls generate too much overhead?|
||I have written about this in the wiki: http://wiki.lazarus.freepascal.org/Multiplatform_Programming_Guide#Gtk2_and_masking_FPU_exceptions|
|2011-07-03 13:38||Zoran Vučenović||New Issue|
|2011-07-03 13:38||Zoran Vučenović||File Added: TestDiv.zip|
|2011-07-03 13:38||Zoran Vučenović||Widgetset||=> GTK 2|
|2011-07-03 14:19||Felipe Monteiro de Carvalho||Note Added: 0049606|
|2011-07-03 15:34||Florian||Note Added: 0049609|
|2011-07-03 21:02||Zoran Vučenović||Note Added: 0049626|
|2011-07-04 21:33||Maxim Ganetsky||LazTarget||=> -|
|2011-07-04 21:33||Maxim Ganetsky||Status||new => resolved|
|2011-07-04 21:33||Maxim Ganetsky||Resolution||open => no change required|
|2011-07-04 21:33||Maxim Ganetsky||Assigned To||=> Maxim Ganetsky|
|2011-07-04 21:33||Maxim Ganetsky||Note Added: 0049669|
|2011-07-04 21:35||Maxim Ganetsky||Note Edited: 0049669|
|2011-07-04 23:45||Flávio Etrusco||Note Added: 0049675|
|2011-07-06 12:09||Zoran Vučenović||Note Added: 0049724|
|2011-07-08 12:49||Zoran Vučenović||Status||resolved => closed|