Seeing as integers in ZScript aren't true integers, I can't see an obvious way of truncating values to integers.
I saw in ZScript.txt that that Pow(int base, int exp); function truncates to an integer, so what I'd been doing was Pow(value to be truncated, 1);, which works fine, I was just wondering if there was a less round-about way of doing it?
Ooo, 1100 posts.
If you want to truncate, use Pow. If you want to round, add .5 and use Pow. Although, you could wrap it in a global function:
int Int(int v) { //too many ints O_o
return Pow(v, 1);
}int Round(int v) {
return Pow(v+.5,1);
}
Actually, Round is bugged with negative integers. I'll leave it as an exercise to the reader to improve it >_>''
...do the Ceiling and Floor functions in std.zh do what you're trying to do?
The following snippet of code...
Trace(1.445);
Trace(Ceiling(1.4455));
Trace(Floor(1.4455));
...produced the following in allegro.log...
1.4450
2.0000
1.0000
Or am I misunderstanding your intent?
PS: Those functions in std.zh are easy to overlook. I didn't even know they were there until just the other day...😃
<_< Do they look very similar to the functions I, er, hand crafted?
*looks*
Why, yes they do. Except, they use shifting to do the same thing... x << 0 Hmm, I wonder which is faster? Probably the shift.
😱
I've used those before and everything.
Oops.
Thanks.