math operators and floats

jamesson's icon
Max Patch
Copy patch and select New From Clipboard in Max.

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

to be floats throughout?

big_pause's icon

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

jamesson's icon

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.

big_pause's icon

the ref says otherwise

Roman Thilenius's icon

it is not sad, it simply saves CPU.

where needed, you can always do

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

broc's icon

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

Roman Thilenius's icon

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

Roman Thilenius's icon

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

broc's icon

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.

Roman Thilenius's icon

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

Chris Muir's icon

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.

seejayjames's icon

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?