In the code below "Max_Lot_Diff" is a positive extern.. eg 0.25. I need to test -0.25 in this snippet. Is there a better/correct way?
Code: Select all
if(s==0 && Net_Position > -Max_Lot_Diff)Jon
Code: Select all
if(s==0 && Net_Position > -Max_Lot_Diff)Code: Select all
if (MaxLossAllowed > 0)
MaxLossAllowed*= -1;
Just for your interest, there was a time when either mine or your method did not work. I am not sure which one it was, but I think it was mine and that yours was the only one to adopt back then. I have this vague folk-memory of trying my method again recently because it makes sense to me, and being pleased to find it works.pascalx » Thu Mar 31, 2016 12:08 pm wrote:For simplicity, I would just write
a = 5;
a = -a;
However, Steve's approach can be better, because on some compilers you might save 1 instruction. However, we talk about 2-3 instructions here, so it should be of no concern in real use case.