Test condition 0< var <1

JMB_13's icon

Hello,

I tried using the [if...] fonction to test if a value is between 0 and 1 this way :

[if $f1 > 0. || $f1 < 1. then $f1 else 0.]

and it doesn't work

[if $f1 > 0. || $f2 < 1. then $f1 else 0.] works

But I can't find out how to make two test on the same $f1

Thanks )

double_UG's icon
Max Patch
Copy patch and select New From Clipboard in Max.

JMB_13's icon

Thanks I tried it but didn't work, I guess I made a syntax error elsewhare, works now. Great !

Roman Thilenius's icon

processingwise even faster is [expr ( ($f1>0.) && ($f1<) ) * $f1]

make sure wether you really need < and >, or rather >= and <=.

if you do not need "else 0" then [split] does it, too (but you probably know that.)

JMB_13's icon

Thanks, works great ! Very simple way know wether one or several entries are non zero.

Roman Thilenius's icon

zero or nonzero can found by [if $f1] :)

while i personally would not write that... for readability.

TFL's icon

zero or nonzero can found by [if $f1] :)

I wanted to try [if $f1] but it throws an error (missing then). So you need to do [if $f1 then 1 else 0]. But the shorter version is [!= 0.]

About [expr ( ($f1>0) && ($f1<1) ) * $f1], another much less readable version is [expr (abs($f1) - int($f1) == $f1) * $f1]. For the sake of the exercice, I tried to know which one is faster by repeating each operation a million times, but the result is... not consistent? Actually it seems to depend on position in patch, which makes no sense to me.

Max Patch
Copy patch and select New From Clipboard in Max.

But we don't really care at that scale.

Roman Thilenius's icon

the [if] in max 4 is more tolerant. it interprets the missing condition as "if true/false" (which is the same as != 0 ) and the missing "then" as "then $f1".
sorry, i should have known that it stopped working long ago.

glad you tested it a million times at different positions in the patch.