Forums > MaxMSP

rounding

November 6, 2008 | 6:09 pm

is it me, or surely 0.99999 should round to 1, not 0?

why is rounding a pain in max?

can you round stuff (in the way i would expect) inside the expr object?

i don’t like having to come out and into [sprintf %.f] (and by-the-way, where does that come from? not the max docs)


November 6, 2008 | 6:16 pm

Rounding doesn’t exist in Max (just like many other programming languages), but you can invent it: add 0.5 and convert to int.

_
johan


November 6, 2008 | 6:17 pm

to get around max "rounding" (e.g. truncating) add 0.5 to the values beforehand.


November 6, 2008 | 7:20 pm

On 6 nov. 08, at 19:09, jimdrake wrote:

> is it me, or surely 0.99999 should round to 1, not 0?

if you’re talking about rounding, yes it should round to 1. But Max
doesn’t do any rounding by default.

> why is rounding a pain in max?

How about using the round object?

> can you round stuff (in the way i would expect) inside the expr
> object?

sure you can. You need to add 0.5 or substract 0.5 depending on the
sign of the number, and truncate it. My favorite solution:

expr "int($f1 + ($f1 > 0.) – 0.5)"

unless you want to use the round object ;-)

> i don’t like having to come out and into [sprintf %.f] (and by-the-
> way, where does that come from? not the max docs)

sprintf is to generate strings (concatenation, leading zeros and that
kind of stuff).

HTH,
ej


November 6, 2008 | 7:42 pm

bloody round object!

i’m sure max5 docs are much harder to navigate than 4.

anyway, fanks.


November 6, 2008 | 8:10 pm

It’s also possible to make a patch that rounds to an increment other than one; for instance, the nearest hundredth, or multiple of ten, or multiple of two (useful if you only want even numbers). My version is below. Set the increment with an argument or in the right inlet (default 1).

– Pasted Max Patch, click to expand. –

November 6, 2008 | 8:13 pm

bloody round object!

i’m sure max5 docs are much harder to navigate than 4.

anyway, fanks.


November 6, 2008 | 8:42 pm

patcherargs is well useful


Viewing 8 posts - 1 through 8 (of 8 total)