简体   繁体   中英

strange floating point exception

I've got a floating point exception in huge application after some changes. I tried to comment my changes and found that FPE happens when I enable one simple function call.

api::getMaxSize();

which simply returns value. looks like this

int api::getMaxSize() { return 536870912; };

This is static member function. When I move this to header file everything works fine. I'm confused, what can be the reson? Looks like API is in another module and linked as dynamic library, but how can this cause a problem?

added

There is function maxBox() which is template and implemented in api.h header file. This function calls getMaxSize()

template <typename T>
static rectangle<T> maxBox()
{
    return rectangle<T>(
        getMinSize(), getMinSize(),
        getMaxSize(), getMaxSize()
    );
}

here is the calling code

if (!api::maxBox<double>().contains(box * scale)) { /* api::getMaxSize(); */ }

If I enable getMaxSize() call the program starts throwing FPE, but getMaxSize() is actually never called.

added Found FPE in box * scale , can't understand why it was working without getMaxSize() call, but however the problem is solved. Thanks to everybody.

Thanks in advance.

Floating point exceptions (actually signals ) are raised for different reasons. The main ones are:

  • you divide an integer by zero
  • an operation on signed integers overflows (unsigned integers must wrap around silently in C and C++).

As you can see, they have nothing to do with floating point numbers ! The name is historical and cannot be changed without breaking a lot of source code (there is a SIGFPE constant in <signal.h> ).

It can be here that GetMaxSize returns a value which is not representable by a int .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM