INTERACT FORUM
More => Old Versions => Media Center 17 => Topic started by: MrC on November 21, 2011, 11:50:55 pm
-
Here is the list of functions and operators I've been able to determine that are valid in the Math() expression:
+ - * / % ( )
abs(x)
atan(x)
cos(x), sin(x), tan(x)
log(x), log10(x)
min(x,y), max(x,y)
pow(x, y)
rand(seed)
If there are others you are aware of, or a reference of the complete list, post them here...
-
A few more:
log10
abscos
abssin
randn (random with range -x to x)
sign
equal
below
above
if
-
You can also save and use variables (and string of letters will be a variable).
Multiple equations can be run. Sub-equations should be separated by a semi-colon.
-
Thanks.
Is this the syntax of if ?
if(tcond,tval,fval)
eg:
if(2+1,5,2)
this seems to work, but functions in tcond part do not:
if(equal(2,1),5,2)
-
My current notes:
This Math() function provides the ability to perform mathematical calculations. It supports the standard arithmetic operators (e.g. addition, subtraction, etc.), provides some internal functions, and allows the use of variables and multiple statements.
Arithmetic Operators:
+ Addition
- Subtraction
* Multiplication
/ Division
^ Power
% Modulo
Boolean Operators
! NOT
& AND
| OR
Grouping Operators
( ) Precedence grouping
Comparitor Operators
} Absolute value maximum (i.e. x or y that is maximum distance from 0).
{ Absolute value minimum (i.e. x or y that is minimum distance from 0).
> Distance between x and y, positive when x greater than y, negative otherwise.
< Distance between x and y, positive when x less than y, negative otherwise.
Order of precedence is:
( )
!
^ (TBD - when bug fixed next release)
* / left to right
+ - left to right
| & left to right
Functions:
abs(x) Returns the absolute value of x.
sign(x) Returns the sign of x (1 when x >= 0, -1 when x < 0).
log(x) Returns the natural logarithm (base e) of x.
log10(x) Returns the common logarithm (base 10) of x.
pow(x, y) Returns x raised to the y-th power.
rand(x) Returns a random value ranging between 0 to x.
randn(x) Returns a random value ranging between -x and x.
Comparison Functions
min(x,y) Returns the minimum value of x and y.
max(x,y) Returns the maximum value of x and y.
equal(x,y) Returns 1 when x = y, 0 otherwise.
below(x,y) Returns 1 when x < y, 0 otherwise.
above(x,y) Returns 1 when x > y, 0 otherwise.
Trigonometric functions
atan(x) Returns the arctangent of x.
cos(x) Returns the cosine of x.
sin(x) Returns the sine of x.
tan(x) Returns the tangent of x.
abscos(x) Returns the absolute value of cosine(x).
abssin(x) Returns the absolute value of sin(x).
if() function.... TBD
Variables may be assigned and used by specifying a simple string of letters (e.g. val=2 or x=pow(2,3)).
Multiple equations may be specified, each separated by a semicolon. Expressions are evaluated left to right. The final value of the Math() function will be the result of the right-most equation.
-
A few more:
Power: x^y
Min: x<y
Max: x>y
Absolute value max: x}y
Absolute value min: x{y
Not: !x
And: x&y
Or: x|y
-
A few more:
Power: x^y
Min: x<y
Max: x>y
These seem more than described:
3^2 returns 1.4601391553878784
2^3 returns 1.4464412927627563
11>4 returns 7
11<4 returns -7
so it seems these are not min/max but rather abs. distance functions, with sign indicating if less than/greater than is true.
-
These seem more than described:
3^2 returns 1.4601391553878784
2^3 returns 1.4464412927627563
It was missing a break in a case statement, so you got an extra atan(...) as a bonus.
11>4 returns 7
11<4 returns -7
If(t,a,b) uses (t > 0) to evaluate conditionals, so functionally it should be the same.
-
Ok, the new build fixes the ^ operator.
I don't get how If() works:
math( if(0,5,2) ) returns 2, correct
math( if(1,5,2) ) returns 5, correct
math( if(1+1,5,2) ) returns 5, correct
math( if(1-1,5,2) ) returns 5, not so correct
-
The if statements are probably being evaluated by the expression language, not the math language. I suppose we'll need to special case this (or just not support it).
-
I was thinking that too. I'll ignore it in the docs for now. Surely if anyone finds a need in the future, they'll speak up.
-
Wiki updated: Math()... (http://wiki.jriver.com/index.php/Media_Center_expression_language#Math.28....29:_Evaluates_a_given_mathematical_formula)
-
Wiki updated: Math()... (http://wiki.jriver.com/index.php/Media_Center_expression_language#Math.28....29:_Evaluates_a_given_mathematical_formula)
Thank you.
-
Ditto on the thanks. I think we owe you the next pie.
-
Nice. But now I'm compelled to dream up uses for it. Maybe a Smartlist Smackdown: Math() Madness Edition would help. But for that, we need someone to submit a problem that doesn't seem to have solution. Maybe some examples would generate interest. In the spirit of Carnac, they could offered in the form, "Here's an expression. What does it do?" ;)
-
How to calculate the number of module?
For example,
math(% [Track #]) It gives 0
-
What are you trying to calculate? You're using the modulus operator (%), which calculates a remainder. For example:
10 % 3 = 1
10 % 2 = 0
10 % 4 = 2
It's the remainder, after division.
Brian.
-
What are you trying to calculate? You're using the modulus operator (%), which calculates a remainder. For example:
10 % 3 = 1
10 % 2 = 0
10 % 4 = 2
It's the remainder, after division.
Brian.
Yeah, I took over the function of the "abs" "module": in Russian "module" means abs.))
|x|.
-
Yeah, I took over the function of the "abs" "module": in Russian "module" means abs.))
|x|.
Wow, that's really confusing! I'm glad you figured it out. :)
Brian.