[cgma-dev] Floating point exceptions in MOAB
Steve Jackson
sjackson at cae.wisc.edu
Wed Apr 28 13:15:17 CDT 2010
MOAB divides by zero sometimes. I discovered this because a CGM dependency enabled floating point exceptions without my knowledge, and that caused my program to abort when a zero division occurred inside MOAB.
The particular zero division I ran into occurs in GeomUtil.cpp, in the function segment_box_intersect(). (Only the KD tree code calls this function.) This zero division is not a bug: the result is checked using finite(), and discarded if infinite. Grepping the code for other occurrences of finite() suggests that this idiom exists in a handful of other places in MOAB. (Most of these places are geometry-related: KD trees, BSP trees, oriented boxes.) Code like this isn't inherently buggy, but it does lead to unexpected behavior when floating point exceptions are enabled.
The library that silently enabled floating point exceptions was CGM, or rather, one of CGM's dependencies. Specifically, in a CGM built against Cubit 10.2 (with ACIS 16.0), one of the Cubit/ACIS shared libraries that CGM links to enables floating point exceptions. (I'm not sure which library it is specifically.) This does not occur when I build CGM against ACIS 16.7.
So the situation is this: if I build CGM against Cubit 10.2, and then build MOAB against that CGM installation, certain MOAB functions may crash unless the calling program first disables floating point exceptions (e.g. by calling feholdexcept()). More generally, any program that enables floating point exceptions may encounter those exceptions when calling into MOAB. Is this mentioned in the MOAB documentation?
~S
More information about the cgma-dev
mailing list