### [expr] ??

hello

I am trying to cut out some digits from decimal number with simple expresion. For example if I have 4.33333 and I want to cut out last 3 digits with [expr $f1 - $f1 % 0.01], when I tried this max crashes. After that I tried with JS object

inlets = 1;

outlets = 1;

function msg_float( incoming ){

x = incoming;

y = x – x % 0.01;

outlet(0, y);

}

and it works fine. I know that there is a lot of ways to make this, but can anyone tell me why max crashes in this situation.

thanks

… actually it shouldn’t… ;)

**all**of the following text. Then, in Max, select

*New From Clipboard*.

```
----------begin_max5_patcher----------
354.3ocyS00SBCCE84teEMM5aSxJCPhOo+NLFR21EVIi1k1BNkv+cauaiODh
gnFiuzs6Wmyomc21HBKS2.VF8A5yTBYaDgfoBIHcwD1JQSdkvhswlWoUqWwh
aK4eUpp.GVi2kbtV4rx2AL2vAIG5Uu1027vtr0BWdoTsXlAxcsBgmN0ODkee
XV53jv4P+I8k8yXDq.GXlAJQVERTOKsT3dqFZAKHXgiESYYB0B1dLjE30Qms
7twriDtxiLV4IiTTwBE1EEENh+G4PiPSYZxeiAk96ZPJ3UOp8X5fF7V4oOub
.zTan2LmSuklPezqUp6m6j7uZWKE205dLZxYd4Y90EsH90YQ3nrJo5y+zgRK
j+TeypWax6ItiG5AsU.VmTIbRs5ndFeROkxhBPc7FPgzFVJPwmbwueWqZRuB
0v+lpo0pD00a.isCRTH9kokZSHbRLFJUsgHhLCrQ12+zn.Z6h9.eVXRL
-----------end_max5_patcher-----------
```

FWIW neither **expr** nor **js** crash on my machine. bach doesn’t crash either ;-)

Please send an example and more information like max version, crash log… to support.

independent from the question wether modulo float works in the expression object or not … if you use expr anyway, you could just calculate the modulo yourself instead of using the % symbol.

that is not an answer to the question, i know, but a solution.

as far as i know % is not officially supported anyway and can be considered a second order undocumented feature, so if you want to be 100% safe you should make your own formula. :)

ust to give a hint, in prior versions of maxmsp the [%] object also was doing the integral job only.

-110

Same here, Max 6.0.8, OSX 10.6.8

Exception Type: EXC_ARITHMETIC (SIGFPE)

Exception Codes: EXC_I386_DIV (divide by zero)

Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Thread 0 Crashed: Dispatch queue: com.apple.main-thread

0 com.cycling74.Max 0x0003debf ex_eval + 2594

1 com.cycling74.Max 0x0004061e expr_bang + 32

2 com.cycling74.Max 0x0006bb21 outlet_float + 851

3 com.cycling74.MaxAPI 0×02902687 outlet_float + 55

4 com.cycling74.number 0x1c0e9802 jflonum_mousedragdelta + 351

- btw, bach.expr’s % operator is the integer remainder as in expr, so $i1 % 0 returns 0 (it’s wrong, but better than crashing Max…), as $i1 % 0.01

aa

Ok cool, I was just testing with 0.… not 0.01. I can reproduce now. We’ll have a look at it, but FWIW floating point modulo isn’t supported in **expr** anyway.

Aside from the fact that trying to round to decimal digits when your computer is calculating in binary–a problem that has been discussed on multiple threads (for instance, this one–you would probably be better off using fmod() rather than % for floating-point modulo.

I’d need to check if [expr] support fmod. I think it does but I haven’t looked for a while. Otherwise, the calculation out of [expr] and use the [%] object, which started supporting floating-point mod quite a while back.

Thanks a lot for all replays!

Forums > MaxMSP