Forums > MaxMSP

[BUG] expr doesn't like floats with modulo

October 12, 2008 | 4:58 pm

Hello.

I just realized that [expr] doesn’t deal with float arguments and %.
For example, [expr $f1%1.2] will output the same as [expr $f1%1].
I would call this a bug because [%] deals with float arguments but maybe
it’s an expected result ?
Example patch below.

Ciao

– Pasted Max Patch, click to expand. –

October 12, 2008 | 10:09 pm

The operator % in C only applies to integers, although of course the idea of a "remainder" is apparently simple to apply to floats.

Presumably the % object implements a workaround to simulate a % operation on floats (if it existed in C).

[ expr (($f1 / $f2) - int($f1 / $f2)) * $f2 ]

works in expr, for example.

Beware, though using this expression or the % object due to the floating point representation accuracy:

Output from % object:

1.2 % 1.2 = 0.0
2.4 % 1.2 = 0.0
3.6 % 1.2 = 1.2
4.8 % 1.2 = 0.0
6.0 % 1.2 = 1.2

You’d expect the results to be zero.


October 13, 2008 | 7:11 am

Thanx for the explanations.
I thought that the same kind of "workaround" was used in [expr] though.

Ciao


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