Next:
Text::Wigwam::Library::Procedure
Previous:
Text::Wigwam::Library::Iterators
 [Table of Contents][Text::Wigwam Index]

Text::Wigwam::Library::Math



NAME

Text::Wigwam::Library::Math #abs, #add, #dec, #decr, #div, #inc, #incr, #int, #mod, #mult, #random, #sub

Description

This library provides directives which are useful for calculating values.

Usage

The directives within this library can be imported into specific branches of the directive tree (which transcends from Text::Wigwam::Directives) via plug-ins or modules using one of the following techniques.

 package Text::Wigwam::Directives::some::arbitrary::branch;
 # import everything
 use Text::Wigwam::Library::Math qw/:all/;

 package Text::Wigwam::Directives::another::arbitrary::branch;
 # import selectively
 use Text::Wigwam::Library::Math(
  qw/ :abs :add :dec :decr :div :inc :incr :int :mod :mult :random :sub /
 );

Directives

#abs num

Returns the absolute (positive) form of numeric value num.

 [!! #abs -123 /* output: 123 */ !!]

#add num1 num2

Returns the sum of numeric values num1 and num2.

 [!! #add 1 2 /* output: 3 */ !!]

#dec var

Decrements a variable's value by 1 and returns nothing.

 [!!
  #define var 5
  #dec var
  "var is " var
  /* output:
   var is 4
  */
 !!]

#decr var

Decrements a variable's value by 1 and returns the new value.

#div num1 num2

Returns the result of num1 divided by num2.

 [!! #div 27 9 /* output: 3 */ !!]

The #div directive is susceptible to divide by zero exceptions. If num2 is zero, this will halt global processing of all templates.

#inc var

Increments the value of var by 1 and returns nothing.

 [!!
  #define var 1
  #inc var
  "var is " var
  /* output:
   var is 2
  */
 !!]

#incr var

Increments the value of var and returns the new value.

#int num

Returns the integer value of num.

 [!! #int 12.99 /* output: 12 */ !!]

#mod num1 num2

Returns the modulus of num1 and num2.

 [!! #mod 9 7 /* output: 2 */ !!]

If num2 is zero, a divide by zero exception will be thrown.

#mult num1 num2

Returns the product of num1 and num2.

 [!! #mult 25 4 /* output: 100 */ !!]

#random num1 num2

Returns a random integer ranging from num1 to num2.

 [!!
  #define die1 #random 1 6
  #define die2 #random 1 6
  "You rolled " #add die1 die2 " (" die1 " & " die2 ")"
 !!]

#sub num1 num2

Returns the resulting value of num1 minus num2.

 [!! #sub 27 9 /* output: 18 */ !!]