Changeset 468 for trunk

Show
Ignore:
Timestamp:
01/17/08 11:22:22 (9 months ago)
Author:
timo
Message:

added 'sig' and 'abs' function to the calc-modifier

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/patTemplate/Modifier/Calc.php

    r465 r468  
    1313/** 
    1414 * patTemplate modifier Calculator 
    15  *  
     15 * 
    1616 * Perfom simple mathematic operations like + - * / 
    17  *  
     17 * 
    1818 * Example: 
    19  *  
     19 * 
    2020 * Declare variable a with default value 10 and perform + operation. 
    21  * With the memory parameter you can specify diffrent buffers. If no memory  
     21 * With the memory parameter you can specify diffrent buffers. If no memory 
    2222 * parameter isset, the operation will be performend on default memory. 
    23  *  
     23 * 
    2424 * <patTemplate:var default="10" name="a" modifier="calc" operator="+" memory="axel"/> 
    2525 * <patTemplate:var default="5" name="b" modifier="calc" operator="+" memory="axel"/> 
    2626 * <patTemplate:var default="5" name="sum" modifier="calc" operator="=" memory="axel"/> 
    27  *  
    28  * If you dont specify a default value it is improtant that the variable is  
     27 * 
     28 * If you dont specify a default value it is improtant that the variable is 
    2929 * assigned in your php code like this: 
    3030 *           $tmpl->AddVar( 'page', 'a', 9 ) 
    31  *  
    32  * If you don't setup a default value and don't assign a variable the modifier  
     31 * 
     32 * If you don't setup a default value and don't assign a variable the modifier 
    3333 * wouldn't be called. 
    34  *  
     34 * 
    3535 * Available operators are: 
    36  *  
    37  * Addition         + 
    38  * Subtraction      - 
    39  * Multiplication   * 
    40  * Division         / 
    41  * Clear the buffer c 
     36 * 
     37 * +    Addition 
     38 * -    Subtraction 
     39 * *    Multiplication 
     40 * /    Division 
     41 * c    Clear the buffer 
     42 * sig  Return the sign (1 for positive values, 0 for 0, -1 for netagive nums) 
     43 * abs  Return the absolute value of the number 
    4244 * 
    4345 * @package     patTemplate 
     
    99101                return null; 
    100102                break; 
     103            case 'sig': 
     104                if( $buffer[$memory] > 0 ) { 
     105                     return 1; 
     106                } 
     107                if( $buffer[$memory] < 0 ) { 
     108                    return -1; 
     109                } 
     110                return 0; 
     111            case 'abs': 
     112                return abs( $buffer[$memory] ); 
    101113        } 
    102114