gameprogcpp / code

Game Programming in C++ Code
Other
1.03k stars 355 forks source link

Concise NearZero function #50

Open LeeTeng2001 opened 2 years ago

LeeTeng2001 commented 2 years ago

In math library, the extra branching statement for NearZero function is redundant Original

    inline bool NearZero(float val, float epsilon = 0.001f)
    {
        if (fabs(val) <= epsilon)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

Suggested:

    inline bool NearZero(float val, float epsilon = 0.001f)
    {
        return fabs(val) <= epsilon);
    }
chalonverse commented 2 years ago

Yes, that is a good point.