[PD] split number into digits

Joseph Larralde joseph.larralde at gmail.com
Sun Jan 17 20:47:44 CET 2021


Hi list,

To elaborate on Claude's answer, here is how I would do it in vanilla :

#N canvas 355 282 450 300 12;
#X obj 214 124 % 10;
#X obj 96 126 / 10;
#X obj 182 91 t f f;
#X floatatom 182 32 5 0 0 0 - - -;
#X obj 96 148 i;
#X obj 96 172 sel 0;
#X obj 214 147 list append;
#X obj 214 170 t a a;
#X obj 182 54 t f b;
#X obj 96 214 list store;
#X obj 96 239 print;
#X connect 0 0 6 0;
#X connect 1 0 4 0;
#X connect 2 0 1 0;
#X connect 2 1 0 0;
#X connect 3 0 8 0;
#X connect 4 0 5 0;
#X connect 5 0 9 0;
#X connect 5 1 2 0;
#X connect 6 0 7 0;
#X connect 7 0 9 1;
#X connect 7 1 6 1;
#X connect 8 0 2 0;
#X connect 8 1 6 1;
#X connect 9 0 10 0;

The inconvenient is that your number cannot start with extra zeros, but 
I guess this is not an issue here.
Also, I have no idea how to perform this in other bases ... but it works 
just fine in base 10 for positive numbers.

Cheers,
Joseph

Le 17/01/2021 à 20:24, pd-list-request at lists.iem.at a écrit :
> Hi Antoine,
>
> On 17/01/2021 18:15, Antoine Rousseau wrote:
>> - transform "float 512" into "symbol 512" using [makefilename %d]
> I would not recommend this, because symbols stick around forever and Pd
> gets slower the more symbols there are.  AKA "symbol table pollution".
>
> Instead, better to use [mod 10] to get the least significant digit, and
> [div 10] to get the most significant digits (then repeat until you have
> all the digits).  This approach also works for bases other than 10.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20210117/d768a7c8/attachment-0001.html>


More information about the Pd-list mailing list