Gigan 1 Posted May 2, 2010 Hi, I have one question about mod command. I am performing fraction processing with the following formulas in script creation. 0 < X <= 360 Actual scripts are the following touch. _dir1 = getdir _obj1;_dir2 = getdir _obj2; _dir3 = _dir1 + _dir2; if ( _dir3 <= 0 ) then { _dir3 = _dir3 + 360 }; if ( _dir3 > 360 ) then { _dir3 = _dir3 - 360 }; ... There is an intention which this is storing a variable value into 0 to 360, and makes calculation of the future intelligible. However, it is not smart to put in the fraction processing which used the above IF sentences of two lines at every variable calculation. Then, I thought of the method of performing fraction processing using the mod command. _dir3 = _dir3 mod 360; It is the method of dividing a variable value by 360 and drawing the remainder. If it is this method, since a conditional sentence is not used and it ends with a single line, it is smart. I used the calc function of google and confirmed whether the calculation would be right. x = 30 mod 360 Answer 30, the result desired. x = 560 mod 360 Answer 200, the result desired. x = (-10) mod 360 Answer 350, the result desired. x = (-370) mod 360 Answer 350, the result desired. It is a result as all were assumed :) Then, I adopted this with my script. A result does not work :( When changes of a variable value were pursued, and a negative value was given, it turned out that results differ. x = (-10) mod 360 ...Answer is -10 x = (-370) mod 360 ...Answer is -10 The script described by the check of a result is the following. player sidechat format["%1",-10 mod 360]; As for these, a result differs from google calc. Does a difference appear in the result of a calculation function by the difference in program language? Or is this a mistake in BI script? The result of google calc regards me as right. I desire is there. Share this post Link to post Share on other sites
f2k sel 164 Posted May 2, 2010 As far as I can tell there two types of MOD, one works like the Google version and the the other as found in Arma2. The difference only shows in how they handle negative numbers. To get the correct answer in Arma2 you could try the following. If the answer is negative then simply add it to the Modulus by the answer, I think that should work. Share this post Link to post Share on other sites
Bon 12 Posted May 2, 2010 -10 equals 350 as well as -370 in this case. So all results are correct. Share this post Link to post Share on other sites
Gigan 1 Posted May 3, 2010 Thanks for the responds :) I had recognition that two mod commands exist. They are a mod operator and a mod function. In google calc, it is a mod function, a negative number is not treated, but, in BI script, it is a mod operator, a negative number is treated. Both of they are right. @F2k Sel It is likely to become somewhat complicated if it describes as a script. The result which I desire will not be obtained by a mod operator. I consider another method. Thanks for the proposal. Share this post Link to post Share on other sites