View Issue Details

IDProjectCategoryView StatusLast Update
0019674LazarusWidgetsetpublic2011-07-08 12:49
ReporterZoran VučenovićAssigned ToMaxim Ganetsky 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionno change required 
Product Version0.9.30.1 (SVN)Product Build 
Target VersionFixed in Version 
Summary0019674: Problems with floating point operations (not raising exceptions)
DescriptionIt 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 InformationThe 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.
TagsNo tags attached.
Fixed in Revision
LazTarget-
WidgetsetGTK 2
Attached Files

Activities

2011-07-03 13:38

 

TestDiv.zip (5,704 bytes)

Felipe Monteiro de Carvalho

2011-07-03 14:19

developer   ~0049606

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.

Florian

2011-07-03 15:34

administrator   ~0049609

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.

Zoran Vučenović

2011-07-03 21:02

developer   ~0049626

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]

Maxim Ganetsky

2011-07-04 21:33

developer   ~0049669

Last edited: 2011-07-04 21:35

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?

Zoran Vučenović

2011-07-06 12:09

developer   ~0049724

I have written about this in the wiki: http://wiki.lazarus.freepascal.org/Multiplatform_Programming_Guide#Gtk2_and_masking_FPU_exceptions

Issue History

Date Modified Username Field Change
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 (notifications not working) 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