Like I finally found out what [%] does and that it is the whole basis around the [counter] object.

So looking into [scale], I figured out that you take the input number, divide it by the high input value, and times it by the high output value, you get the same effect.

The only feature I can’t seem to replicate is the rounding used in the scale or round object – I can’t figure out what the raw maths equivalent os for

[round 1 @nearest 0] is.

I mean, in lots of code languages there is a round object/function/whatever, but I just want to know what is actually happening in the object.

Thanks guys!

Iyad.

– Pasted Max Patch, click to expand. –

I was being stupid again.

ALTHOUGH, i’d love to know how any of the other max objects actually function through the land of maths if you guys have any examples.

This intrigues me.

Thanks.

]]>here are a few other examples out of my abstractions (110.map is zmap or scale)

[attachment=199243,4173]

]]>I was also wondering if [==], [< =] and [>=] could somehow be put into maths speak?

Perhaps the [>= 4] object would be along these lines?

[expr ($i1/4)/($i1/4)]

Thanks.

]]>smallest possible part, almost machine language.

but expr can use these guys, too.

in expr it will take up more CPU than with the >= object, but of course, several of

them can be combined in one object that way, which can, otoh, also save some

CPU, at least when run in high priority (==when the input comes a from a metro or line)

[expr $i1>=4] will return 0 or 1, just like the >= operator external.

you can combine several comparisons using * as logical-and:

[expr ($i1>=4) * (($i1%12)==1)] will return true only if both conditions are met.

and of course you can combine it with any other functions.

use addition for the true and false version of the calculation, and multiplication

to bind them to the condition (==comparison operator).

[expr ($i1+5) * ($i1>=4) + ($i1) * ($i1<4)]

“take input and add five, but only when the input is greater or equal to 4, else output is input”:

not even [if] can do that in one line.

-110

]]>One C-style math that’s not available in expr (though it is in gen~) is floor/ceil. Floor always rounds towards negative infinity, and ceil always rounds up towards positive infinity. They’re handy for rounding algorithms because weird things happen with negative numbers. (Test your rounding code with negative numbers and you’ll see)

One other math that’s really good to know about is Horner’s rule for evaluating polynomials:

It’s way more efficient to do:

d + x*(c + x*(b + x*a)) // 3 multiplies, 3 adds

instead of:

a*x^3 + b*x^2 + c*x + d // 8 multiplies(!), 3 adds

On a practical note, it means that the number of operations to compute a polynomial grows linearly rather than exponentially, so you can compute a 10th order Chebyshev polynomial using 10 multiply-add operations, which is a good thing.

]]>