Monodevelop c # script runtime error

I have a very simple if statement that doesn't work as expected.

My main problem is that the immediate window evaluates the if statement differently than executing the code:

   if( FreeProductStorageVolume < product.Volume * quantity )
      Debug.Log( FreeProductStorageVolume );
      Debug.Log( product.Volume );
      Debug.Log( quantity );
      Debug.Log( product.Volume * quantity );
      canProduce = false;


all variables are floats

enter image description here

everything assumes that the breakpoint at line 824 should not be removed.

even the Immediate window evaluates the if () statement as false.

did something similar happen to someone else?


source to share

1 answer

It looks like a floating point issue. This expression:

FreeProductStorageVolume - quantity * product.Volume.


seems to be evaluated positive, but a very small number such as 1E-20



All Articles