how to "round" numbers to decimal ?

Aug 17, 2006 at 9:36am

how to "round" numbers to decimal ?

How to make all numbers in, i.e, a range of n0 to n9, be only n ? (25 ->
20, 17 -> 10…)

thanks in advance

f.e

f.e chanfrault | aka | personal computer music
> >>>>>> http://www.personal-computer-music.com
> >>>>>> |sublime music for a desperate people|

#27202
Aug 17, 2006 at 9:50am

>How to make all numbers in, i.e, a range of n0 to n9, be only n ?
>(25 -> 20, 17 -> 10…)
>
>thanks in advance

#P window setfont “Sans Serif” 9.;
#P number 100 237 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 93 203 27 196617 – 0;
#P number 134 168 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 126 114 34 196617 % 10;
#P number 93 62 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P connect 3 0 4 0;
#P connect 0 0 3 0;
#P connect 0 0 1 0;
#P connect 2 0 3 1;
#P connect 1 0 2 0;
#P window clipboard copycount 5;

best

kasper

#82110
Aug 17, 2006 at 9:51am

Is this what you mean?

#P number 43 175 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 43 119 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 43 156 32 196617 * 10;
#P newex 43 136 31 196617 / 10;
#P connect 1 0 3 0;
#P connect 0 0 1 0;
#P connect 2 0 0 0;

Mattijs

#82111
Aug 17, 2006 at 10:19am

Hey, great ! Thanks to both of you for these two different ways to do
it. That’s supercool.

cheers

f.e

f.e chanfrault | aka | personal computer music
> >>>>>> http://www.personal-computer-music.com
> >>>>>> |sublime music for a desperate people|

Mattijs Kneppers wrote:
> Is this what you mean?
>
> #P number 43 175 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P number 43 119 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 43 156 32 196617 * 10;
> #P newex 43 136 31 196617 / 10;
> #P connect 1 0 3 0;
> #P connect 0 0 1 0;
> #P connect 2 0 0 0;
>
> Mattijs
>
>
>

#82112
Aug 17, 2006 at 10:36am

>Hey, great ! Thanks to both of you for these two different ways to do it.

you could also use expr – for some reason %$i1 does not work in
expr, but there must be some logic to it (probably because expr is
C-like expression in which modulo is done in a totally different
way….)

best

kasper

Kasper T. Toeplitz
noise, composition, bass, computer

http://www.sleazeArt.com

#82113
Aug 17, 2006 at 5:29pm

> you could also use expr – for some reason %$i1 does not work in expr,
> but there must be some logic to it (probably because expr is C-like
> expression in which modulo is done in a totally different way….)

correct, use the function rather than the operator. i think it’s in the
expr help/ref somewhere but i don’t have it in front of me (i’m not a C
programmer, just an expr user). from memory, i think it’s
mod($i1,10)

#82114
Aug 17, 2006 at 5:54pm

I use this method Mattijs suggests all the time, but with a secondary input hooked up, for variable quantization of the signal. This is by far the most useful little abstraction in my arsenal.

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 273 111 87 9109513 expr $i1 / $i2 * $i2;
#P number 350 76 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 273 141 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 273 76 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P connect 3 0 1 0;
#P connect 2 0 3 1;
#P connect 0 0 3 0;
#P window clipboard copycount 4;

Quote: f.e wrote on Thu, 17 August 2006 12:19
—————————————————-
> Hey, great ! Thanks to both of you for these two different ways to do
> it. That’s supercool.
>
> cheers
>
> f.e
>
> f.e chanfrault | aka | personal computer music
> > >>>>>> http://www.personal-computer-music.com
> > >>>>>> |sublime music for a desperate people|
>
>
> Mattijs Kneppers wrote:
> > Is this what you mean?
> >
> > #P number 43 175 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> > #P number 43 119 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> > #P newex 43 156 32 196617 * 10;
> > #P newex 43 136 31 196617 / 10;
> > #P connect 1 0 3 0;
> > #P connect 0 0 1 0;
> > #P connect 2 0 0 0;
> >
> > Mattijs
> >
> >
> >
>
—————————————————-

#82115
Aug 17, 2006 at 6:56pm

>>you could also use expr – for some reason %$i1 does not work in
>>expr, but there must be some logic to it (probably because expr is
>>C-like expression in which modulo is done in a totally different
>>way….)
>
>correct, use the function rather than the operator. i think it’s in
>the expr help/ref somewhere but i don’t have it in front of me (i’m
>not a C programmer, just an expr user). from memory, i think it’s
> mod($i1,10)
>

actually it was
($i1 %10)

which gives

#P window setfont “Sans Serif” 9.;
#P number 148 207 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 159 122 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 155 168 107 196617 expr $i1 – ($i1 %10);
#P connect 1 0 0 0;
#P connect 0 0 2 0;
#P window clipboard copycount 3;

OR

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 309 63 66 196617 loadmess 10;
#P number 263 119 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 148 207 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 159 122 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 155 168 110 196617 expr $i1 – ($i1 %$i2);
#P connect 4 0 3 0;
#P connect 3 0 0 1;
#P connect 0 0 2 0;
#P connect 1 0 0 0;
#P window clipboard copycount 5;

#82116
Aug 17, 2006 at 7:51pm

Or you could do:

expr ($i1/10)*10

Since everything is expressed in int math, you’ll only get 10′s.
Below is an abstraction that will round to arbitrary decimals/tens,
etc. and also handles negative numbers.

Peter McCulloch

#P window setfont “Arial Black” 24.;
#P window linecount 1;
#P comment 332 31 141 791478296 PM.Round;
#P window setfont “Sans Serif” 9.;
#P comment 14 78 32 196617 Input;
#P comment 62 40 220 196617 Set amount to round to. (1′s , 10′s ,
0.1′s , etc.);
#P newex 60 85 19 196617 t f;
#N vpatcher 20 74 620 474;
#P window setfont “Sans Serif” 9.;
#P newex 50 98 24 196617 t 1.;
#P newex 50 76 32 196617 sel 0;
#P newex 50 50 67 196617 loadmess $1;
#P outlet 50 126 15 0;
#P connect 1 0 2 0;
#P connect 2 0 3 0;
#P connect 3 0 0 0;
#P fasten 2 1 0 0 77 119 55 119;
#P pop;
#P newobj 80 59 70 196617 p SafeDefault;
#P comment 173 279 158 196617 peter.mcculloch@gmail.com;
#N comlet Amount to round to. (1 = normal rounding , 10 = round to
nearest 10);
#P inlet 60 59 15 0;
#P newex 16 134 79 196617 vexpr $f1/$f2;
#P outlet 16 273 15 0;
#P inlet 16 101 15 0;
#P window linecount 2;
#P newex 16 180 259 196617 vexpr
[($f1>=0)*(int(int($f1)+($f1-int($f1)>=0.5)))+($f1<0)*(int(int($f1)-
($f1-int($f1)< -0.5)))]*$f2;
#P window linecount 1;
#P comment 333 73 158 196617 Rounding that also works on lists;
#P newex 60 108 35 196617 sel 0.;
#P connect 3 0 5 0;
#P connect 5 0 2 0;
#P connect 2 0 4 0;
#P connect 8 0 9 0;
#P connect 6 0 9 0;
#P connect 9 0 0 0;
#P connect 0 1 5 1;
#P fasten 0 1 2 1 90 129 270 129;
#P window clipboard copycount 13;

#82117
Aug 17, 2006 at 9:39pm

On 17-Aug-2006, at 11:36, f.e wrote:

> How to make all numbers in, i.e, a range of n0 to n9, be only n ?
> (25 -> 20, 17 -> 10…)

Lots of helpful abstractions.

maxobjects.com lists f0.round, running on Classic Mac OS, OS X, Pd,
and Windows. There may be others (the word “round” matches a lot of
items). In case you wanted an external.

– P.

————– http://www.bek.no/~pcastine/Litter/ ————-
Peter Castine +–> Litter Power & Litter Bundle for Jitter
Universal Binaries on the way
iCE: Sequencing, Recording &
Interface Building for |home | chez nous|
Max/MSP Extremely cool |bei uns | i nostri|
http://www.dspaudio.com/ http://www.castine.de

#82118
Aug 18, 2006 at 12:51am

#82119
Aug 18, 2006 at 11:20pm

lround from the lobjects is my favourite, can round to any power of
ten..

ciao,

Joost.

On 17 Aug 2006, at 22:39, Peter Castine wrote:

> On 17-Aug-2006, at 11:36, f.e wrote:
>
>> How to make all numbers in, i.e, a range of n0 to n9, be only n ?
>> (25 -> 20, 17 -> 10…)
>
> Lots of helpful abstractions.
>
> maxobjects.com lists f0.round, running on Classic Mac OS, OS X, Pd,
> and Windows. There may be others (the word “round” matches a lot of
> items). In case you wanted an external.
>
> — P.
>
> ————– http://www.bek.no/~pcastine/Litter/ ————-
> Peter Castine +–> Litter Power & Litter Bundle for Jitter
> Universal Binaries on the way
> iCE: Sequencing, Recording &
> Interface Building for |home | chez nous|
> Max/MSP Extremely cool |bei uns | i nostri|
> http://www.dspaudio.com/ http://www.castine.de
>
>

#82120

You must be logged in to reply to this topic.