Log in

View Full Version : Avisynth MulDiv question


hello_hello
6th September 2018, 10:26
I assumed the MulDiv output would be float, but when I tried to use it for the equation below I didn't get the expected result, so I started re-arranging the numbers, thinking I'd misunderstood the order in which they must be specified, but based on the result the output is always rounded up to the nearest integer.

2 * 3 / 4 = 1.5

MulDiv(2, 3, 4) = 2.0
MulDiv(2, 4, 3) = 3.0
MulDiv(3, 4, 2) = 6.0
MulDiv(3, 2, 4) = 2.0
MulDiv(4, 2, 3) = 3.0
MulDiv(4, 3, 2) = 6.0

So my questions are, am I missing something, and if the output of MultiDiv is rounded up to the nearest integer, what's the point of it?

StainlessS
6th September 2018, 12:28
From Docs

Multiplies two ints (m, n) and divides the product by a third (d) in a single operation, with 64 bit intermediate result.
The actual equation used is (m * n + d / 2) / d .


The stuff in blue is essentially rounding, for integer result. (instead of rounding afterwards as in Int((Float(m) * n / d) + 0.5).
[ie (+ d/2)/d term is equiv to 0.5]
EDIT: Rounds without a float intermediate result.

EDIT:
what's the point of it?
Fast and without overflow for (64 bit) intermediate result. [where m * n could be large number exceeding 32 bits prior to division]

EDIT: HH, add the MulDiv tag to your thread, so that others can find it.

hello_hello
6th September 2018, 12:48
Thanks.

How do I add a tag after a thread is posted? I can see where to add one when creating a thread (although I've never used that feature) but not when editing the opening post. I could be missing the obvious though.

StainlessS
6th September 2018, 12:51
Not sure, think you click at bottom of thread, where says "Tags" (below Post A Reply)

EDIT: On RHS of bottom of thread/last post says "Edit Tags".

EDIT: Actually, I just added Muldiv tag, thought only the OP could do it.

hello_hello
11th September 2018, 12:31
Well you can learn something new every day. I thought I'd have to edit the opening post and add tags from there somehow.
I think my brain must have decided to block the tags section as noise at some stage, so I didn't see it. :)

Cheers.