Tasker Tip Tuesdays

Tasker Tip Tuesdays: How To Use Variable Maths

How To Use Variable Maths

Welcome to Tasker Tip Tuesdays​, quick tips to help grow your Tasker knowledge.  This week I will show you how to use Variable Maths.  If you have Tasks containing simple or calculus level math, this tip is for you.

 

Variable Maths Locations




Found in the userguide section under maths, there are three locations to use variable maths.  Once recognized, they are easy to spot in the future.  The first location is in the “Variable Set” Action, by checking the box “Do Maths”.  The second is in the “If”/”Else” Action, when comparing a variable to another.  And finally, variable maths are found in individual Action conditions, when a mathematical comparison is used.

Constants and Functions

Besides just using the simple expresses, Tasker includes various mathematical expressions in it’s maths library.  These constants are the following:

  • E – the base of the natural logarithms (2.718)
  • EUL – Euler’s Constant (0.577)
  • LN2 – log of 2 base e (0.693)
  • LN10 – log of 10 base e (2.303)
  • LOG2E – log of e base 2 (1.443)
  • LOG10E – log of e base 10 (0.434)
  • PHI – the golden ratio (1.618)
  • PI – the ratio of the circumference of a circle to its diameter (3.142)

Aside from constants, Tasker also includes various functions.  See the userguide linked above and see below for some of the functions Tasker supports:

  • abs – absolute value
  • cbrt – cube root
  • ceil – smallest value that is greater than or equal to the argument and is an integer
  • cos – trigonometric cosine
  • floor – largest value that is less than or equal to the argument and is an integer
  • log10 – base 10 logarithm
  • nextup – floating-point value adjacent to val in the direction of positive infinity
  • round – closest 64 bit integer to the argument
  • sin – trigonometric sine
  • sqrt – correctly rounded positive square root
  • tan – trigonometric tangent
  • todeg – converts an angle measured in radians to an approximately equivalent angle measured in degrees
  • torad – converts an angle measured in degrees to an approximately equivalent angle measured in radians
  • NOTE that in the Tasker userguide it states that “Functions take their argument in parenthesis” so make sure to use them.  My examples below illustrate this.

Written Examples

Just looking at the functions, constants, and operators isn’t as exciting as it sounds but using them is the fun part.  Some example problems and solutions are below to showcase Variable Maths.  Try these functions on your own in Tasker Tasks, then throw in some variables and watch the magic happen!

  1. Volume of a sphere: “4 / 3 * PI * [%radius] ^ 3”
    1. Set a value to “%radius” beforehand
  2. Converting degrees to radians : “torad(%degrees)”
    1. Set a value to “%degrees” beforehand
  3. Sin of a cube root of the product of the base of natural logarithms and the absolute value of the difference between two values: “sin( cbrt( E * abs( %first_val – %second_val ) ) )”
    1. Set values to “first_val ” and “%second_val” beforehand
  4. Note: thank you to reddit user /u/false_precision for corrections!

Video Examples

See my video example below for how Variable Maths look in practice.

Conclusion




Whether your Tasker Tasks are simple or advanced, there will be some maths involved at some point.  Now that you know Tasker supports math, place variables in the above examples to see what the outcome bring.

Further Reading

To catch up on previous posts in this series, visit the Tasker Tip Tuesdays page.  As always, enjoy and keep learning!  Until the next Tasker Tip Tuesday…

What did you think???