multiplying negative number

I have these formula

long fadeSpan = (durationTime - eventTime) * 1000L;
long currentMillis = millis();
long pwmDif = pwmValue[i] - initPWM; // can be + -

int currentVal = pwmDif * (currentMillis-initMillis)/fadeSpan

Every thing is fine if pwmDif is positive but if it's negative the formula currentVal blows up.
I tested with these values.

long pwmDif = -2498;
long currentMillis = 191517;
long initMillis = 181000;
long fadeSpan = 56000;

currentVal = 76226; // it should be -469

I rechecked the datatype. Is there some mismatch? Maybe currentVal should be a long too?

From the tiny bit of code you've posted, there is absolutely no way anyone can tell you what the problem is. My guess is you may be simply printing it wrong....

One thing I can promise you - Addition and subtraction work just fine.

Ray L.

Ah, I found it. I inadvertently assigned a unsigned long to one of the variable (initMillis). This prevented the currentVal from becoming a proper negative number. I didn't know.

long currentMillis = millis();

note millis() returns an unsigned long so the above statement is semantically wrong.