-2

Hey all, I need to compare a double inside an if statement. If the double has no value/is equal to zero, it should do nothing. Otherwise it should do something.

My if statement if (doubleNameHere > 0) doesn't work.

Obviously I'm missing something fundamental here, any ideas?

Joshua Nozzi
  • 60,946
  • 14
  • 140
  • 135
Daniel G. Wilson
  • 14,955
  • 2
  • 32
  • 39
  • What does this have to do with the Xcode IDE? This is an Objective-C (and therefore also C) question. The IDE used to write/manage code is not the same thing as the language in which the code is written. Retagged. – Joshua Nozzi Nov 25 '10 at 03:23
  • Also: What do you mean "it doesn't work"? Have you verified with the debugger that the value of doubleNameHere is what you think it is at runtime? Have you tried adding a decimal to the literal zero: (doubleNameHere > 0.)? – Joshua Nozzi Nov 25 '10 at 03:25
  • It is not possible for a double to have no value. – Matthew Flaschen Nov 25 '10 at 03:27
  • 2
    Comparing doubles is tricky. The internal representation of floating point numbers is not what most people expect. See for example here: http://stackoverflow.com/questions/2743718/when-is-aa-true/2743780#2743780. Also floats can take on all kinds of wonderful values such as NaN and negative and positive infinities. You might try to rewrite the code that doesn't use the double directly. – martineno Nov 25 '10 at 03:38

1 Answers1

0

Sorry all, it turns out that it wasn't set to zero, it was equal to another blank double value. I started it at zero and it was fine.

Daniel G. Wilson
  • 14,955
  • 2
  • 32
  • 39