rounding

Nov 6, 2008 at 6:09pm

rounding

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)

#40709
Nov 6, 2008 at 6:16pm

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

#144303
Nov 6, 2008 at 6:17pm

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

#144304
Nov 6, 2008 at 7:20pm

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

#144305
Nov 6, 2008 at 7:42pm

bloody round object!

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

anyway, fanks.

#144306
Nov 6, 2008 at 8:10pm

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. –
#144307
Nov 6, 2008 at 8:13pm

bloody round object!

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

anyway, fanks.

#144308
Nov 6, 2008 at 8:42pm

patcherargs is well useful

#144309

You must be logged in to reply to this topic.