Forums > MaxMSP

math operators and floats

Apr 07 2012 | 9:04 pm

It seems my math operators change floats to ints kinda arbitratily. How can I constrain this, for example

-- Pasted Max Patch, click to expand. --

to be floats throughout?

Apr 07 2012 | 10:06 pm

is that not just a case of giving an initial value with a decimal in i.e. [- 0.0] and [/ 1.0] ?

Apr 07 2012 | 10:22 pm

I could do that, but my iunderstanding was that this was not necessary – ie it would default to input.

Now I think about it, I may have run into this before, still, it is very sad that it cannot look at input and use it to decide.

Apr 07 2012 | 10:47 pm

the ref says otherwise

Apr 08 2012 | 4:18 am

it is not sad, it simply saves CPU.

where needed, you can always do

[route int float]
[* 0] [* 0.]

Apr 08 2012 | 11:47 am

I’ve read somewhere that’s a legacy issue as Max was originally designed for handling integers only.

Apr 08 2012 | 8:30 pm

it is a feature not an issue. :)

that would be very strange if

[/ 2]

would return 3.5, dont you think.

the normal case is that you want to calculate only int OR float and not both.

and if objects would do a typcheck in [/ 2] they would not only need more CPU,
but they would also not know what to do when you send "7.0" into the left inlet
after you sent a new divisor of "3" before – or which of the inlets would like to
set the objects´ mode? 7/2.5 = 3 and 7.0/2 = 3.0 ? …

furthermore, imagine how your patch would read when [/ 2 ] would return the
same type as [/2.7] is doing.

dont forget that any float argumented object also takes ints and converts them,
and every float object takes ints and truncates them.

so you can use [/ 2.] at any time to do 8/2=4.0 when you need 4 (int) at the
output, because 4.0 will work with the next int object just fine (except [umenu]
or [vst~] mabye)

after 17 edits i am now finished 110ing this post together.


Apr 08 2012 | 8:52 pm

i just noticed that there is a contradiction in my post.

of course [* ] has to do a typecheck anyway, so i have to pull my "save CPU" propaganda.


Apr 09 2012 | 10:16 am

The "save CPU" aspect is still valid to some extent because the format [* ] vs. [* 1.] determines which type of operation (integer vs. float) will be used. So it’s not necessary to derive the operation type at runtime from the input types which may save some CPU cycles. But from the users view, I find it rather inconvenient.

Apr 09 2012 | 3:23 pm

yeah what is used, but they _take both. i am probably not a programmer enough
to have the right picture about how much of a difference it makes to do typecheck
vs "just taking" two different types and route them to different processes.


Apr 09 2012 | 5:31 pm

When Max was young, there was a huge performance difference between integer math and floating point math. As processors have gotten better, this difference has at least been reduced, and perhaps has largely gone away. The trouble is that at this point, it couldn’t really be changed without potentially breaking thousands of patches.

Apr 09 2012 | 5:54 pm

I for one think it’s best to have to be explicit. Yes, I’ve been stung by this too (or stung myself, more accurately), and spent considerable time trying to figure out the problem, only to discover a truncation somewhere. But I wouldn’t change it for anything, because all you need to do is be specific everywhere you need to be. It also makes you be really sure about what you’re doing mathematically and why.

@jamesson: There should be no objects that change them "arbitrarily" from floats to ints etc. They do what their arguments or their incoming values tell them to do, and if they don’t, it’s a bug. Is this what you found?

Viewing 12 posts - 1 through 12 (of 12 total)

Forums > MaxMSP