## Scaling and rounding in actual maths.

Jul 12, 2012 at 1:34pm

# Scaling and rounding in actual maths.

Hey, so recently i’ve been thinking about a lot of the the max objects would be made using mathematical expressions or code, since i’m starting to look into other languages a bit more. Since my maths knowledge is a little awful, I thought i’d ask you guys.

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!

#35943
Jul 12, 2012 at 1:54pm

Ah. I think i’ve figured it out.

– 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.

#123121
Jul 12, 2012 at 10:50pm

you could take a look into the helpfile of [mtof] to see what it does (but there are more than this one way how to calculate it)

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

[attachment=199243,4173]

###### Attachments:
#123122
Jul 17, 2012 at 2:36am

Cool, thats for that, very helpull.

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.

#123123
Jul 17, 2012 at 3:28am

comparison operators can not be put to a lower level or something, it is kinda the
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

#123124
Jul 17, 2012 at 11:23am

now the other way around! i mean, come on guys we should finally write the principia mathematica patch! :)

http://en.wikipedia.org/wiki/Principia_Mathematica

#123125
Jul 17, 2012 at 1:22pm

Integration and derivation are pretty simple in a sample-based system, so you’re on the way… (+= and current-previous)

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