4 Replies Latest reply on Apr 7, 2016 8:47 AM by czigany

# Can't reverse engineer director math algorithm (myCalculation=1&myFinalNumber*6727714)

I'm trying to rewrite several old director movies into modern software applications, but have hit a roadblock in trying to rewrite various algorithms because the math in Director isn't making any sense.

The problem comes about with this line:

myCalculation=1&myFinalNumber*6727714

For example, when myFinalNumber = 1258, I am expecting that myCalculation will result in "18463464212", but instead it comes out as "1-126470380". Watching the expression myFinalNumber*6727714 shows the result -126470380.

How can multiplying two positive numbers result in a negative answer?

I've tried to work backwards to see if there's any consistency to the results, and haven't been able to find a pattern of what math it is actually performing when it is supposed to be solving 1258*6727714.

I've tried separating the line out into multiple lines, thinking perhaps the string concatenation was effecting things, but there was no change by doing myFinalNumber*6727714 and then concatenating the 1 in front.

Is there something stupidly obvious I'm not seeing here? Surely there's some sort of rhyme and reason to how Director handles math equations like this.

Any insights would be appreciated.

• ###### 1. Re: Can't reverse engineer director math algorithm (myCalculation=1&myFinalNumber*6727714)

There are limits to the size of an integer that Director can represent. Specifically:

put the maxinteger

2147483647

If you add 1 to the maximum integer that Director can represent then the value will roll over to the largest negative number that Director can represent.

put the maxinteger + 1

-2147483648

If you need to work with numbers above two billion then you need to use floating point numbers. In your case:

put 1258 * 6727714.0

8463464212.0000

• ###### 2. Re: Can't reverse engineer director math algorithm (myCalculation=1&myFinalNumber*6727714)

Thank you, I knew there had to be some rational explanation for what it was doing.

Too bad what I need to do is create algorithms to duplicate the results that come from this. Would be much easier just to switch them to floating point. Unfortunately we've got too much software in the wild that is dependent on the results that came from multiplying oversized integers.

At least I know what's going on now, and where to look to figure out how to replicate this odd behavior. Thanks again!

• ###### 3. Re: Can't reverse engineer director math algorithm (myCalculation=1&myFinalNumber*6727714)

Replicating Director's behavior should be straight forward. Here is an example in Python.

def doDirectorMath(val):

val = val % 4294967294

return val if val - 2147483647 < 0 else val - 4294967294

x = doDirectorMath(1258 * 6727714)

print(x)

What language are you working in?

• ###### 4. Re: Can't reverse engineer director math algorithm (myCalculation=1&myFinalNumber*6727714)

Working in javascript for this project.

var doDirectorMath = function(val) {

val = val % 4294967294;

if(val - 2147483647 < 0) {

return val;

} else {

return val - 4294967294;

}

};

var x = doDirectorMath(1258 * 6727714);

console.log(x);

Works perfectly, thanks for your time!