Forums > MaxMSP

exponent & expr

September 4, 2013 | 8:12 am

hi

how to write exponent with expr ???

my operation is like this :
2.04 x 10^(-5) // = 2.04*0.00001 = 0.0000204

thanks for your help

o-O


September 4, 2013 | 9:31 am

That’d be expr 2.04*pow(10.,-5)

i.e. exponents in expr are written like pow(a,b), as in ‘a’ to the power of ‘b’. Make sure that ‘.’ is after the 10 so that the exponent will be processed as a float.

Hope that helps


September 4, 2013 | 1:05 pm

Don’t forget that you have to escape special characters like the comma:

[expr 20.4*pow(10\,-5)]

Note that exponentiation is relatively CPU-costly; if either or both parts of the pow() function are constant, it may be worth the effort of using a precalculated value. There are also some special cases (for instance, non-negative integer exponents) where there are simpler functions you might want to use.


September 4, 2013 | 3:43 pm

no need to backslash escape the comma anymore these days. it is 2013 after all.


September 4, 2013 | 5:33 pm

hi

Thanks for your reply and explanation.
In fact I have a big list from ocean sensor, with lot of various number and exponential values…
7.3439156e+005 6.6591366e+000 -8.8263154e-001
7.3439156e+005 6.6961372e+000 -5.6900889e-001
7.3439156e+005 6.6881377e+000 -9.6660798e-001

1st I used "regexp" to "unpack" it
and Now I can make a new list with "real" value… using expr…

best
0-0


September 4, 2013 | 6:45 pm

hi

I find a problem on my tree !
I used regexp for "unpack" my value : 7.3439156e+005
if function is positive i have a list : 7.34… e +005
but if function is negative (7.3439156e-005) i find : 7.34… e -5 ( zero disappear ???)

next for formatted exponent (+005) i used a another regexp to have 5.
but with the expression I used -5 become also 5

For expr I need 5 (if positive) and -5 (if negative) ( he don’t like +5)

If you can help me to solve my problem…

o-O

<pre>

– Pasted Max Patch, click to expand. –

</code></pre>


September 5, 2013 | 12:14 am

if there occurs something like a*a in your expression, but you also might want negative output, then this expression simsply isnt finished.

a typical situation where one runs into this problem is when using pythagoras to find points in a system.

you will have to split the expression into one "version" for negative and one for positive.

example:

[expr pow($f1\,2.) * ($f1>=0.) + (pow($f1\,2.)*-1) * ($f1<0.)]


September 5, 2013 | 1:26 am

oh i am off track. you are on the regexp layer.

well, try to get the exponents as symbols first or something like that?


September 5, 2013 | 3:46 am

hi

Yes! I have solve my problem.
I used Jash object "strfilt" & "strcut" to first look if exponent is + or -
then I route it on 2 different way…

I think is not the most efficient, but make what i need…

<pre>

– Pasted Max Patch, click to expand. –

</code></pre>


September 5, 2013 | 8:26 am

no need to backslash escape the comma anymore these days

Old habits die hard. Particularly those you’ve been using for over two decades. Leaving out the backslash used to cause tserious tsuris.


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