[expr] ??

Feb 14, 2013 at 10:17am

[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

#66508
Feb 14, 2013 at 10:59am

Hi,

I do not know how “% 0.01″ is intepreted in Javascript but AFAIK with [expr] it is parsed as “% 0″ and that always crashes any application. EXC_I386_DIV (divide by zero)

#239372
Feb 14, 2013 at 1:04pm

… actually it shouldn’t… ;)

– Pasted Max Patch, click to expand. –
#239373
Feb 14, 2013 at 2:34pm

Hi,

“… that always crashes any application.” I should say that it is implementation dependent ;-) Sorry i don’t have [bach] currently installed on my computer… what is the result of your external in case of % zero ?

#239374
Feb 14, 2013 at 5:09pm

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

#239375
Feb 14, 2013 at 9:27pm

@emmanuel: lucky you. Here both 6.0.8 and beta-6.1.0 (osx.7.5) crash every time.

#239376
Feb 14, 2013 at 10:02pm

I am quite new i programing, but I think that it is standart procedure. I tried with python and lua and it works. I have searched for it and found a topic i book about lua.

I am with max 6.0.8, OSX 10.7.5.

[attachment=214854,5029] [attachment=214854,5030]

Attachments:
  1. ScreenShot20130214at11.41.08PM.png
#239377
Feb 14, 2013 at 11:08pm

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

#239378
Feb 14, 2013 at 11:47pm

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

#239379
Feb 15, 2013 at 7:00am

Hi,

With [expr $f1 % 0.01] and max 5.1.9 / Os X.4.11.

Exception:  EXC_ARITHMETIC (0x0003)
Codes:      EXC_I386_DIV (divide by zero)

Thread 0 Crashed:
0   com.cycling74.MaxMSP           	0x00034348 ex_eval + 2240
1   com.cycling74.MaxMSP           	0x00037e5e expr_bang(expr*) + 32
2   com.cycling74.MaxMSP           	0x00064d9a outlet_float + 776
3   com.cycling74.MaxAPI           	0x02cba387 outlet_float + 54
Attachments:
  1. crash.txt
#239380
Feb 15, 2013 at 8:02am

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

#239381
Feb 15, 2013 at 9:32am

looks like the same.

Attachments:
  1. crash.txt
#239382
Feb 15, 2013 at 2:11pm

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.

#239383
Feb 15, 2013 at 7:15pm

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.

#239384
Feb 17, 2013 at 8:34am

Thanks a lot for all replays!

#239385

You must be logged in to reply to this topic.