Can anyone explain why this would fail:

assert(cap >= 0);

But this passes?

if(cap < 0)
  {
  exit(-1);
  }

That is, the assert is triggered, but if I replace it with conditional, the exit() function is never called.

Thoughts?

Thanks,

David

Can you post your question a little more clearly with some context?

I don't know that this makes it much clearer, but stated another way:

double cap = some value...
assert(cap >= 0);

The assert is triggered.

double cap = same value as above

if(cap < 0)
  {
  exit(-1);
  }

I thought this would behave identically to the assert (it would quit if cap is < 0), but the assert fails at times when the if statement doesn't.

I think it maybe due to floating point conversion. Does cap necessarily need to be a double?

Bah, turns out cap was NAN! So annoying...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.