Page 2 of 2

Re: Allow floating-point division by zero in ZScript

PostPosted: Sat Jul 28, 2018 6:04 pm
by AFADoomer
You are correct. I started with a different example, and ended up putting the max in the wrong place when I changed it up...

Re: Allow floating-point division by zero in ZScript

PostPosted: Sat Jul 28, 2018 6:19 pm
by argv
AFADoomer wrote:For brevity's sake, I usually end up putting in a "max([divisor that might end up as zero], [arbitrary small number]);" call in cases like this...

e.g.:
Code: Select allExpand view
TweenChange = 1. / (max(time, 0.0001) * TICRATE);


Not sure if that slows things down internally any more/less than using if statements to the same effect, but I haven't noticed any issues so far.

Good idea. As Graf confirmed, that's faster than if branches.

I've replaced the if with similar code:
Code: Select allExpand view
TweenChange = 1. / (max(time, double.epsilon) * TICRATE);

Thanks for the idea. :)