You are here:

C++/I did it by my own


But the problem is about Epsilon now ...I am not able its giving error ... I have to include it in driving sample file also ...

am i rite?

Sir i am today doing very much hardwork on these. I am sure at the end of the day i will come with senseible doubts ..

Thank you, Whenever i will stuck i will mail you please help me out

Slight variations in rounding can change the outcome of exact floating-point comparisons. leading to unexpected or incorrect behavior.

Tests for equality of floating-point quantities should be made within some tolerance (epsilon in this case) related to the expected precision of the calculation

A floating point number N may be as close to 2.0 as can be possible (in the floating point representation that the implementation uses) without actually exactly matching 2.0. Well behaved code uses an inexact or fuzzy comparison to test a value to within a certain tolerance, for example:

epsilon = 0.0000001

if( std::abs( N - 2.0 ) <= epsilon ) // the absolute difference between N and 2.0 is less than epsilon

For more information, see the first part of

The next question is how do we access epsilon which is defined in one file from another file. This is the basic structure:

epsilon.h - contains the declaration of epsilon, we need the declaration to use it

extern const float epsilon ;

epsilon.cpp - contains the definition of epsilon

const float epsilon = 0.00000001f ;    

use_epsilon.cpp - file where we want to use epsilon

#include "epsilon.h" // bring in the declaration of epsilon
#include <cmath> // for std::abs

// now we can use epsilon; for example:

bool is_equal( float a, float b )
       return std::abs( a - b ) <= epsilon ;

While building, compile epsilon.cpp, compile use_epsilon.cpp, compile the other .cpp files, and link the object files together.

For example, using g++

g++ epsilon.cpp use_epsilon.cpp main.cpp -o myprogram


All Answers

Answers by Expert:

Ask Experts




my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++11. i would not answer questions about gui and web programming.


about 15 years or so

post graduate engineer

©2017 All rights reserved.