math operators and floats

Apr 7, 2012 at 9:04pm

math operators and floats

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?

#62835
Apr 7, 2012 at 10:06pm

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

#226833
Apr 7, 2012 at 10:22pm

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.

#226834
Apr 7, 2012 at 10:47pm

the ref says otherwise

#226835
Apr 8, 2012 at 4:18am

it is not sad, it simply saves CPU.

where needed, you can always do

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

#226836
Apr 8, 2012 at 11:47am

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

#226837
Apr 8, 2012 at 8:30pm

it is a feature not an issue. :)

that would be very strange if

7.0
|
[/ 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.

-110

#226838
Apr 8, 2012 at 8:52pm

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.

 -110

#226839
Apr 9, 2012 at 10:16am

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.

#226840
Apr 9, 2012 at 3:23pm

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.

-110

#226841
Apr 9, 2012 at 5:31pm

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.

#226842
Apr 9, 2012 at 5:54pm

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?

#226843

You must be logged in to reply to this topic.