min, max with vexpr? correct syntaxe help!
hello,
how do use min and max with vexpr (or expr)? please
i've an incoming list of two numbers with a range of -1. 1 in vexpr. and i want a maximum range of -1. 0. to the output of vexpr.
thanks by advance.
sorry for my english :)
ok it's done! :)
[vexpr min(0, $f1) @scalarmode 1]
Nice. Don't forget a decimal point for all float args.
Yeah ok thanks but $f1 act as decimal number? Even if is an integer in input no?
right, the whole expr object "performs in float" if there are $f variables in it.
in the given case i am not sure if "0." would really make a difference.
but if you do /3 somewhere it might be relevant to know that it will _not automatically be converted to / 3. only because the expr object is in float mode.
last but not least it is just good practice to always write what you mean, it will make things better readable.
thanks for information. yes generally if i want float number i add decimal point by precaution.
Also keep in mind, even if the output is correct, any input element >0, will result in integer output (the value set as the minimum). That can cause data type bugs in certain routing contexts. ... or it might be a useful routing hack...
Hi!
Glad I found this post, I'm looking for the same solution.
I have a list of floats coming into vexpr and I wish to do calculations based on the maximum number in that list.
Your solution: [vexpr max(0., $f1) @scalarmode 1]
outputs exactly the inputted list. I don't understand why.
I looked in the reference, but I didn't find any information.
What exactly the meaning of the first argument (0.) ? initialization?
Thank you
vexpr does the expression on a element by element basis so the way you have this it will replace each element with the maximum of 0. or the element. since all elements are above zero the list passes through as is. if you are looking to sum all the elements in a list I would use the [zl sum] instead.
the maximum in an array of numbers is what the good old [maximum] already gives you.
the two operators of expr max() are the two numbers you are going to compare with each other. ;)
roman is right - I don't know what I was thinking with zl sum.
of course if the list is smaller than 8 you can do expr (max(max(max(max(max($f1, $f2),$f3),$f4),$f5),$f6),$f7) - because expr will distribute the list across inlets.
so if you like to type "max" as often as possible this is for you.
(and mimimimi for finding the smallest value)
Thank you all for answering! I know about the good old [maximum], but I was wondering if it was possible to use this function inside [vexpr] just to avoid things like more cables and keep the patch cleaner. Sounds like I'm pursuing the wheel again... :P
Anyways, in my stubbornness of trying to answer questions like: how can I use this (now/or in the future)? Is this useful for me? how does this work? what's the logic behind?
I was unsuccessful @Roman. I tried your nested/recursive syntax, but doesn't give the results I was expecting. Those questions remain open...
works only in expr not vexpr.
you have no chance mixing list operations with number operations in one object i guess.
same with iterations. where in OOL you would use variables, in max you have to - literally - build it around the expr object.
