adi_calc – Calculator for TXP variables

This plugin does calculations using TXP variables.

Attributes

name="var name"

- the TXP variable to work with.

value="value"

- the initial value used for the calculation. Default = “” (i.e. if variable exists, use its value; else set to zero). Note that this will overwrite the value of an existing TXP variable.

display="boolean"

- display the variable’s value after the calculation has been performed. Default = “0” (do not display).

add="value"

- add “value”.

subtract="value"

- subtract “value”.

multiply="value"

- multiply by “value”.

div="value"

- divide by “value”. Note that this is integer division, e.g. 11 DIV 5 = 2.

mod="value"

- divide by “value” & return the remainder.

Notes

  • adi_calc assumes that supplied TXP variables contain numbers. No checks are made to verify this.
  • you can use either the standard <txp:variable /> tag to set the variable’s initial value or the value attribute.
  • if the supplied TXP variable is not set and the value attribute is not used, then adi_calc sets it to zero before the calculation is performed.
  • use smd_if to test the variable’s value.

Examples

<txp:variable name="test" value="2" />
set a variable called test to 2

<txp:adi_calc name="test" add="5" />
adds 5 to test (result = 7)

<txp:adi_calc name="test" subtract="3" />
subtracts 3 from test (result = 4)

<txp:adi_calc name="test" multiply="9" />
multiplies test by 9 (result = 36)

<txp:adi_calc name="test" div="5" />
is integer division by 5 (result = 7)

<txp:adi_calc name="test" mod="2" />
is the remainder when divided by 2 (result = 1)

In the above sequence of calculations the setting of the variable and the first calculation can be combined using the value attribute:

<txp:adi_calc name="test" value="2" add="5" />
sets test to 2 and adds 5 to it (result = 7)

Use display="1" to display the result of the calculation:

There are <txp:adi_calc name="total" value="60" multiply="24" display="1" /> minutes in a day.

Additional information

Support and further information can be obtained from the Textpattern support forum. A copy of this help is also available online. More adi_plugins can be found here.

Version 0.2 - Download Support