Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::numeric_limits<double>::epsilon() undefined in Visual C++ 2015

Tags:

c++

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);
    }
};
like image 786
Doug Kimzey Avatar asked Aug 19 '16 13:08

Doug Kimzey


People also ask

How do I get epsilon in C++?

The preferred way in C++ is to use std::numeric_limits::epsilon( ) – specified in the standard header . In Java, it is referred to as ULP (unit in last place). You can find it by using the java. lang.

What is epsilon C++?

std::numeric_limits::epsilon(): This function returns the difference between one and the smallest value greater than one that is representable.

What is std :: Numeric_limits?

std::numeric_limits ::digits in C++ with Example The std::numeric_limits ::digits function is used to find the number of radix digits that the data type can represent without loss of precision. Header File: #include<limits>

Which of the following data types is accepted by the Numeric_limits function?

Data types that supports std::numeric_limits() in C++ std::numeric_limits<int>::max() gives the maximum possible value we can store in type int. std::numeric_limits<unsigned int>::max()) gives the maximum possible value we can store in type unsigned int.


2 Answers

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);
    }
};
like image 156
rgmt Avatar answered Oct 22 '22 03:10

rgmt


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

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

like image 4
Bathsheba Avatar answered Oct 22 '22 05:10

Bathsheba