INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Math() : available functions list...  (Read 9281 times)

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Math() : available functions list...
« 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...
Logged
The opinions I express represent my own folly.

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42442
  • Shoes gone again!
Re: Math() : available functions list...
« Reply #1 on: November 22, 2011, 08:38:15 am »

A few more:
log10
abscos
abssin
randn (random with range -x to x)
sign
equal
below
above
if
Logged
Matt Ashland, JRiver Media Center

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42442
  • Shoes gone again!
Re: Math() : available functions list...
« Reply #2 on: November 22, 2011, 08:39:28 am »

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.
Logged
Matt Ashland, JRiver Media Center

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Math() : available functions list...
« Reply #3 on: November 22, 2011, 11:38:17 am »

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)
Logged
The opinions I express represent my own folly.

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Math() : available functions list...
« Reply #4 on: November 22, 2011, 12:45:04 pm »

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.
Logged
The opinions I express represent my own folly.

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42442
  • Shoes gone again!
Re: Math() : available functions list...
« Reply #5 on: November 22, 2011, 12:53:04 pm »

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
Logged
Matt Ashland, JRiver Media Center

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Math() : available functions list...
« Reply #6 on: November 22, 2011, 01:19:40 pm »

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.
Logged
The opinions I express represent my own folly.

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42442
  • Shoes gone again!
Re: Math() : available functions list...
« Reply #7 on: November 22, 2011, 01:34:48 pm »

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.

Quote
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.
Logged
Matt Ashland, JRiver Media Center

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Math() : available functions list...
« Reply #8 on: November 22, 2011, 06:01:47 pm »

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
Logged
The opinions I express represent my own folly.

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42442
  • Shoes gone again!
Re: Math() : available functions list...
« Reply #9 on: November 22, 2011, 06:30:16 pm »

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).
Logged
Matt Ashland, JRiver Media Center

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Math() : available functions list...
« Reply #10 on: November 22, 2011, 06:46:04 pm »

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.
Logged
The opinions I express represent my own folly.

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Math() : available functions list...
« Reply #11 on: November 22, 2011, 09:03:18 pm »

Wiki updated: Math()...
Logged
The opinions I express represent my own folly.

JimH

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 72538
  • Where did I put my teeth?
Re: Math() : available functions list...
« Reply #12 on: November 23, 2011, 07:01:51 am »

Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42442
  • Shoes gone again!
Re: Math() : available functions list...
« Reply #13 on: November 23, 2011, 09:01:37 am »

Ditto on the thanks.  I think we owe you the next pie.
Logged
Matt Ashland, JRiver Media Center

rick.ca

  • Citizen of the Universe
  • *****
  • Posts: 3729
Re: Math() : available functions list...
« Reply #14 on: November 23, 2011, 05:01:53 pm »

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?" ;)
Logged

kroser8

  • Recent member
  • *
  • Posts: 20
Re: Math() : available functions list...
« Reply #15 on: November 03, 2015, 11:14:27 am »

How to calculate the number of module?
For example,
math(% [Track #])         It gives 0
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: Math() : available functions list...
« Reply #16 on: November 03, 2015, 11:36:59 am »

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.
Logged

kroser8

  • Recent member
  • *
  • Posts: 20
Re: Math() : available functions list...
« Reply #17 on: November 04, 2015, 09:58:00 am »

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|.
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: Math() : available functions list...
« Reply #18 on: November 04, 2015, 10:07:23 am »

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.
Logged
Pages: [1]   Go Up