DiscusWare, LLC.
Download Purchase Contact Us
Home
Support Home Documentation Knowledge Base Support Forums Support Request Advanced Services
Discus Template Language :: Mathematical operations

This document describes how to use mathematical operations with variables. Unless you hold a support contract that includes support for customization, DiscusWare does not provide support for the procedures in this section.
Support Site Search
 
Manuals and Docs
  Installation
  Upgrade
  Administration - 4.0
  Administration - 3.1
  Customization
    Skin Primer
    Skin Editing
    Interface Customization
    Templates: Variables
    Templates: Substitution
    Templates: IF-THEN
    Templates: FOREACH
    Templates: FOR
    Templates: DEFINE
    Templates: Arrays
    Templates: Skins
    Templates: Text Ops
    Templates: Subroutines
    Templates: Flow Control
    Templates: Math
    Templates: Global Options
    Templates: Colors
    Templates: Language Files
Synopsis

During the process and rendering of a subtopic, it is possible to perform mathematical operations on variables. This is most useful when iterating through an array or performing some other repetitive function.

Available Operations

<#math: $variable += $x#> ## Adds $x to $variable
<#math: $variable -= $x#> ## Subtracts $x from $variable
<#math: $variable *= $x#> ## Multiplies $x by $variable
<#math: $variable /= $x#> ## Divides $variable by $x
<#math: $variable %= $x#> ## Takes $variable mod $x

To perform a mathematical operation, the variable you are operating upon (in the above example, $variable) must be an entirely alphanumeric variable, or it can be a variable of the form $hash->{key}. The argument (in the above example, $x) can be a constant or any kind of variable recognized by the Discus Template Language. When a mathematical operation takes place, the result is placed back into the variable you are operating upon.

If you attempt to divide by zero, or take the modulus by zero, nothing happens (your command is ignored).

Mathematical statements such as these must be placed on a line of their own (they cannot be used within an in-line IF-THEN-ELSE block). You are limited to one operation per line. At times, it may be more efficient to use the mathdefine command, especially if many successive mathematical operations must be carried out.

An Example

<#define: $i = 3#> ## $i = 3 (duh)
<#math: $i += 4#> ## $i is now 3+4=7
<#math: $i -= 1#> ## $i is now 7-1=6
<#math: $i *= 2#> ## $i is now 6*2=12
<#math: $i /= 3#> ## $i is now 12/3=4
<#math: $i %= 0#> ## $i is still 4; this illegal math operation ignored
$i ## Prints 4


Download Purchase Contact Us
Privacy Policy
Copyright © 2005, DiscusWare, LLC, All Rights Reserved