Re: One more technical FAQ a

Tom Schwengler (tschwen@advtech.uswest.com)
19 Mar 1997 10:05:50 -0700

Reply to: RE>One more technical FAQ about MHEG-5 IS

Emmanuel,
We had discussed the modulo issue for a while, and the conclusion was that
the following equation:
(a DIV b) * b + (a MOD b) = a
is ALWAYS true.
The reason was mainly that it is the way most software or languages define
it, including for instance Java.
So indeed the result of modulo is sometimes negative. It may seem strange in
some cases, but as Xavier mentioned, modulo is not the same as the Euclidian
remainder of the division.

Tom

--------------------------------------
Date: 3/19/97 7:34 AM
To: Tom Schwengler
From: Emmanuel BEUQUE
Hi all,

I'm coming back with one more tech FAQ while implementing some interesting
listGroup autoscrolling features for my MHEG-5 authoring tool.

It's about the definition of the modulo action that shall be targeted to
IntegerVariable.

The MHEG-5 standard says that it should work "as defined by usual integer
arithmetic rules" and then provides an equality to satisfy :
"(a DIV b) * b + (a MOD b) = a"

Well, that's OK for positive integers but my question concerns the case
where a is a negative integer. (b shall be a strictly positive integer but
a normally has no constraints).

Suppose the case where a = -5 and b = 3

If I remember well what I learned at school and what is returned by my
scientific calculator (HP28S), the result shall be 1.
I think that arithmetics specify that :
(a MOD b) shall be within the range [0, (b-1)]

but if we follow the equality, we got :
a DIV b = -1 so -1 * 3 + (a MOD b) = -5
that means that (a MOD b) = -2
I know that Macromedia Director 5 also gives this result but that doesn't
seem correct to me.

I would like to have the feeling of the MHEG community about what is correct.
Is the equality erroneous in the standard or should it work like that in
all MHEG engines ?
In fact, I need to have the standard modulo (always positive) in order to
set the tokenPosition of a listGroup. I would like to know if I have to
make a patch like the one below or if engines you use usually don't take
care of this equality.

Suppose that a has an object id = 1
and b has an object id = 2

:SetVariable (1 :GInteger -5)
:SetVariable (2 :GInteger 3)
:Modulo (1 :IndirectRef 2)
:TestVariable (1 3 0) // This is the patch

And the patch would also need the next link

{:Link 3
:InitiallyActive true
:EventSource 1
:EventType TestEvent
:EventData true
:LinkEffect (
:Add (1 :IndirectRef 2)
)
}

Is all this really necessary or not ?

Please reply to my personal E-mail, not to the list since I don't get it.

By the way, if the MHEG User Group list is opened to everyone interested
in, could the administrator add me to the list or if someone could tell me
how to subscribe...

Many thanks for your interest.

Regards,
Emmanuel

__________________________________________________________________
Emmanuel BEUQUE Email: ebeuque@pratique.fr
mediaServ tel: +33 (0) 2 99 64 36 64
Multimedia consultant & developer fax: +33 (0) 2 99 64 36 65
__________________________________________________________________

----------------