• ### I'm not sure how to do the math in this patch.

Hello community!

I need some guidance in building this little device.
I want to be able to add, subtract, multiply and divide numbers through bangs to these object boxes; plus receive the result in a number box.

I plan to do this in real time, for example: if I start with 0, and press the bang of + 1 I would get 1 in the number box. If I then press the bang of * 5 I would get 5 in the same number box. So with any operation.

I know it may be a bit silly to ask for a solution for this, but I have some time without understanding how to do it.
I would appreciate any help.

• | Posts 9 | Views 862
• you could make a simple abstraction that just outputs a certain number when banged:
multi-math.zip

• what you are thinking of is an accumulator - this is from Desigining Sound's free intro http://aspress.co.uk/ds/pdf/pd_intro.pdf - (More about the book at) http://aspress.co.uk/ds/about_book.html

so here is a more complicated one that can do addition and subtraction as well as multiplication and division - doing that involves using two steps to turn off the addition/subtraction or the multiplication/division depending on what you are doing - also the way you had [/ 4] and [* 4] - wont work unless you bang a 1 into them.. its like sending 0 into /4 or *4

complicatedAccumulator.pd

• @Carambolooo Objects like [- 2] and [/ 4] are ultimately just lists and things get easier if we treat them as such and just stuck them in messages. Once we do this we can just route things as needed and this also means you are not limited to bangs, you can send the appropriate list. I also added the ability to switch the operators, if you send [2 /( and the current value is 6 you get 0.333, but if you send [2 /( you will get 3.
accumulate.pd

• I didn't imagine you all would bring so many systems to the table. Seriously, thank you, I appreciate it very much.

• @oid Oh, by the way I don't quite understand what I should do to get 3 as a result of dividing 6 by 2, as in your example. I get only 0.333

• @Carambolooo Float before operator like in the rightmost message [2 /(

• @oid Maybe you could use messages like [ / ( .... [ + ( ...etc. and use [add2( or [list prepend] and [list append] to complete the list for calculation, and so use the messages much in the same way as you would press buttons on a calculator.
That might make the interface much more intuitive.
David.

• @whale-av If it were me I would just use a list box and type it all in but I assumed OP has a reason for doing it this way, possibly not a good reason but we all chase our tails at times. I would go with [list append/prepend] over {add2( for your way, having to {set( the message to clear it every go around seems an unnecessary step which is why I made everything a list in mine instead of making everything an any. One downside to the calculator interface is you either have preset numbers to select from or need an enter button, will be at least two clicks and could be half a dozen which is not great if you are trying to keep in time with a beat. List box has this same issue, OP might be on the right track.