Problem with simple if-comparison

 Register Blogs Members List Search Today's Posts Mark Forums Read

 September 7, 2009, 16:09 Problem with simple if-comparison #1 Senior Member     Sebastian Gatzka Join Date: Mar 2009 Location: Frankfurt, Germany Posts: 729 Rep Power: 18 Hello World. I'm completely confused ... This is really embarrassing as it's about a simple if condition ... Have a look at the code-(sniped): Don't mind what it's actually doing, concentrate on the bold red if-condition. Code: ```int main(int argc, char *argv[]) { faceSet facesSet(mesh, setName); labelList faces(facesSet.toc()); vectorField faceCenterCoordinates(facesSet.size()); for (label i=startTime; i

 September 7, 2009, 16:17 #2 Senior Member     Matvey Kraposhin Join Date: Mar 2009 Location: Moscow, Russian Federation Posts: 355 Rep Power: 19 Values displayed with some tolerance (it means, that difference could be after 6 or N digits after dot) Try to calculate and output difference between two values, or refomulate condition like inequality: if ( mag(faceCenterCoordinates[1].component(2) - faceCenterCoordinates[2].component(2)) < VSMALL ) { /// do something }

 September 8, 2009, 08:06 #3 Senior Member     Sebastian Gatzka Join Date: Mar 2009 Location: Frankfurt, Germany Posts: 729 Rep Power: 18 Yes this worked! The output from Code: `mag(faceCenterCoordinates[1].component(2) - faceCenterCoordinates[2].component(2))` was 2.22045e-16 in my case and I had to use SMALL instead of VSMALL to make the comparison work. By the way: What is the difference between SMALL and VSMALL and where is it defined? __________________ Schrödingers wife: "What did you do to the cat? It's half dead!"

 September 8, 2009, 08:21 #4 Senior Member     Matvey Kraposhin Join Date: Mar 2009 Location: Moscow, Russian Federation Posts: 355 Rep Power: 19 VSMALL - means Very SMALL. For single precision: SMALL = 1e-6, VSMALL = 1e-37 For double precision: SMALL = 1e-15, VSMALL = 1e-300 this definitions are related with machine word length, and, i think, it's done for independence of platform type for more information, see file scalar.H