Compiler warnings: division by zero

Compiler warnings: division by zero

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
Tronic
Posts: 75
Joined: 30 Nov 2006, 03:21

Compiler warnings: division by zero

Post by Tronic »

Math.cpp uses some hacks to generate certain special floating point values:

Code: Select all

    // Constants

    const Simple SimplePositiveInfinity = Simple(1.0f) / Simple(0.0f);
    const Simple SimpleNegativeInfinity = Simple(-1.0f) / Simple(0.0f);
    // TODO: non-signaling version
    const Simple SimpleNaN = SimplePositiveInfinity + SimpleNegativeInfinity;

    const Double DoublePositiveInfinity = Double(1.0f) / Double(0.0f);
    const Double DoubleNegativeInfinity = Double(-1.0f) / Double(0.0f);
    // TODO: non-signaling version
    const Double DoubleNaN = DoublePositiveInfinity + DoubleNegativeInfinity;
Instead of these, <limits> of the standard library should be used. std::numeric_limits<double>::quiet_NaN() gives a NaN and std::numeric_limits<double>::infinity() gives an inf. See http://www.dinkumware.com/manuals/?manu ... mits2.html for a full list of available options.

Also, using special typedefs for Double etc. seems strange, as the standard library already provides double that should be good for all purposes where Double would be used. Obviously, using the numeric_limits as instructed above may also be done where needed instead of a special header (granted, though, that they are a bit ugly).
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: Compiler warnings: division by zero

Post by Tobi »

Tronic wrote:Also, using special typedefs for Double etc. seems strange, as the standard library already provides double that should be good for all purposes where Double would be used. Obviously, using the numeric_limits as instructed above may also be done where needed instead of a special header (granted, though, that they are a bit ugly).
It's because streflop can be configured to use softfloat, or to use a denormal-squasher helper class.
Post Reply

Return to “Engine”