View Full Version : I want +=, -=, *=, /= and div
See topic title. The first four would be helpful keystroke-savers, and the latter is useful when trying to work out how many 16s are in a sprite's y value.
DarkDragon
09-17-2006, 01:07 PM
What does "div" do?
DarkDragon
09-17-2006, 03:36 PM
Well in any case the following have been added to the ZScript language in b14:
+=
-=
*=
/=
&&=
||=
&=
|=
^=
<<=
>>=
%=
Div is integer division. Think of it as the counterpart to mod.
Alternatively, you could add floor() (and ceiling()).
DarkDragon
09-18-2006, 02:28 AM
I don't think adding those to the language itself is necessary, but I will add the following functions to std.zh, the ZScript standard header that will be included in b14:
//some utility routines
int Floor(int x) {
if(x < 0)
return (x-.9999)<<0;
return x<<0;
}
int Ceiling(int x) {
if(x < 0)
return x<<0;
return (x+.9999)<<0;
}
std.zh will also include constants like SFX_STAIRS for sound effects and item classes.
Cloral
09-18-2006, 04:27 PM
Actually div() would be a really useful function. Div would essentially be the equivalent of:
result = x / y;
if(result > 0)
{
result = Floor(result);
}
else
{
result = Ceiling(result);
}
DarkDragon
09-18-2006, 10:46 PM
Added.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.