Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] c++ comparison with tolerance

Status
Not open for further replies.

bmandl

Full Member level 4
Joined
Feb 26, 2010
Messages
207
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
Slovenia
Activity points
2,965
Hello,
I was wondering if there is some way in c++, to compare one integer value to another, but allow tolerance? Something like this:

if (val1 > (val2±x)){...}

else if (val1<(val2±x)){...}

Thank you for your answers!

- - - Updated - - -

Ok, I solved the problem this way:

if (val1 > val2 && abs(val1-val2)>x){...}

else if (val1 < val2 && abs(val1-val2)>x){...}
 

Looks like a method to generate dummy code.

The actually performed comparison is val1 > val2+x respectively val1 < val2 - x.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top