5

The following code produces an error: std::numeric_limits<double>::epsilon() undefined error.

Using numeric_limits<double>::epsilon also produces this error.

#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif // !_USE_MATH_DEFINES

#include <math.h>
#include <limits.h>

class plusCartesianPoly {

public:

    static bool isClose(double a, double b)
    {
        if (fabs(a-b) <= std::numeric_limits::epsilon())
            return true;

        return(false);
    }
};
4
  • 12
    std::numeric_limits is defined in <limits>, not <limits.h>. Commented Aug 19, 2016 at 13:29
  • 3
    General rule of thumb: never user *.h includes for things from std. Commented Aug 19, 2016 at 13:30
  • OT, It could be a better idea to scale epsilon somehow. See the example code in the reference page. Commented Aug 19, 2016 at 15:49
  • Thanks most kindly - very useful comments. Commented Aug 19, 2016 at 18:30

2 Answers 2

5

numeric_limits is declared in limits, not limits.h which is the C version of climits (by the way, math.h is the C version of cmath):

#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif // !_USE_MATH_DEFINES

#include <cmath>
#include <limits>

class plusCartesianPoly {

public:

    static bool isClose(double a, double b)
    {
        if (std::fabs(a-b) <= std::numeric_limits<double>::epsilon())
            return true;

        return(false);
    }
};
Sign up to request clarification or add additional context in comments.

Comments

4

<limits.h> contains the macro-type limits from the C standard library

You need <limits> to use the C++ standard library functions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.