github.com/coveo/gotemplate@v2.7.7+incompatible/docs/doc_test/arithmetic.rendered (about)

     1  {% include navigation.html %}
     2  {% raw %}
     3  # Basic mathematic operations
     4  
     5  ## Operators mixin
     6  
     7  Note that you cannot combine razor extended expression (+, -,  /, *, etc.) with go template expression such as in:
     8  
     9  | Razor expression                | Go Template                          | Result | Note
    10  | ------------------------------- | ------------------------------------ | -----: | ----
    11  | @(2 + (2 | mul(4)));   | {{ add 2 (bor 2 (mul 4)) }}     | 8      | In this statement, | is interpreted as bitwise or between 2 and 4
    12  | @(sum 2 (2 | mul 4));  | {{ sum 2 (2 | mul 4) }}    | 10     | While in this statement (no binary operator), | is interpreted as go template piping operator
    13  
    14  ## Addition
    15  
    16  | Razor expression       | Go Template                 | Result | Note
    17  | ---------------------- | --------------------------- | -----: | ----
    18  | 3              | 3               | 3      | **Addition**
    19  | 9            | 9               | 9      | *or add*
    20  | 13             | 13               | 13     | *or sum*
    21  | 5                | 5               | 5      | Spaces are optional
    22  | 17        | 17               | 17     | You can insert an arbitrary number of spaces in expressions
    23  | 4.6        | 4.6           | 4.6    | It also works with floating point numbers
    24  | 10      | 10           | 10     | It is possible to supply multiple arguments to addition operation
    25  | 10   | 10    | 10     | this is useful on this line since there is ambiguity on where the expression finish
    26  
    27  ## Subtraction
    28  
    29  | Razor expression       | Go Template                 | Result | Note
    30  | ---------------------- | --------------------------- | -----: | ----
    31  | 2              | 2               | 2      | **Subtraction**
    32  | 2            | 2               | 2      | *or sub*
    33  | 2       | 2          | 2      | *or subtract*
    34  
    35  ## Negative values
    36  
    37  | Razor expression       | Go Template                 | Result | Note
    38  | ---------------------- | --------------------------- | -----: | ----
    39  | -23                | -23                   | -23    | Negative value
    40  | -21            | -21             | -21    | Operation with negative value
    41  | -13       | -13 | -13  | Operation with negative expression
    42  
    43  ## Product
    44  
    45  | Razor expression       | Go Template                 | Result | Note
    46  | ---------------------- | --------------------------- | -----: | ----
    47  | 6              | 6               | 6      | **Multiplication**
    48  | 20            | 20               | 20     | *or mul*
    49  | 42       | 42          | 42     | *or multiply*
    50  | 72           | 72              | 42     | *or prod*
    51  | 110      | 110         | 110    | *or product*
    52  | 24      | 24           | 24     | It is possible to supply multiple arguments to multiplication operation
    53  | 1680   | 1680    | 1680   | or even an array
    54  
    55  ## Division
    56  
    57  | Razor expression       | Go Template                 | Result | Note
    58  | ---------------------- | --------------------------- | -----: | ----
    59  | 2              | 2               | 2      | **Division**
    60  | 4.333333333333333             | 4.333333333333333              | 4.333333333333333 | *you can use the รท character instead of /*
    61  | 5           | 5              | 5      | *or div*
    62  | 2.5        | 2.5           | 2.5    | *or divide*
    63  | 2.2     | 2.2        | 2.2    | *or quotient*
    64  
    65  ## modulo
    66  
    67  | Razor expression       | Go Template                 | Result | Note
    68  | ---------------------- | --------------------------- | -----: | ----
    69  | 1              | 1               | 1      | **Modulo**
    70  | 2           | 2              | 2      | *or mod*
    71  | 2         | 2           | 2      | *or modulo*
    72  
    73  ## Power
    74  
    75  | Razor expression       | Go Template                 | Result | Note
    76  | ---------------------- | --------------------------- | -----: | ----
    77  | 64             | 64               | 64     | **Power**
    78  | 248832           | 248832              | 248832 | *or pow*
    79  | 6561          | 6561             | 6561   | *or power*
    80  | 1000             | 1000               | 1000   | **Power 10**
    81  | 100000           | 100000             | 100000 | *or power10*
    82  | 100000               | 100000                  | 100000 | Scientific notation (positive)
    83  | 0.002               | 0.002                  | 0.002  | Scientific notation (negative)
    84  
    85  ## Bit operators
    86  
    87  | Razor expression         | Go Template                 | Result | Note
    88  | ------------------------ | --------------------------- | -----: | ----
    89  | 256               | 256            | 256    | **Left shift**
    90  | 96           | 96            | 96     | *or lshift*
    91  | 64        | 64         | 64     | *or leftShift*
    92  | 64            | 64         | 64     | **Right shift**
    93  | 57         | 57          | 57     | *or rshift*
    94  | 36      | 36       | 36     | *or rightShift*
    95  | 512          | 512        | 512    | **Bitwise AND**
    96  | 32       | 32        | 32     | *or band*
    97  | 78   | 78    | 78     | *or bitwiseAND*
    98  | @(1 | 2 | 4); | 7       | 7      | **Bitwise OR**
    99  | 492     | 492       | 492    | *or bor*
   100  | 324  | 324    | 324    | *or bitwiseOR
   101  | 7            | 7     | 7      | **Bitwise XOR**
   102  | 384    | 384      | 384    | *or bxor*
   103  | 324 | 324   | 324    | *or bitwiseXOR
   104  | 251             | 251          | -      | **Bitwise Clear**
   105  | 244     | 244       | -    | *or bclear*
   106  | 8   | 8    | -    | *or bitwiseClear
   107  
   108  ## Other mathematic functions
   109  
   110  ### Special cases
   111  
   112  There are special behavior for certain operators depending of the arguments:
   113  
   114  #### String multiplication
   115  
   116  **************************************************************************************************** will result in **************************************************************************************************** which result in:
   117  
   118  ****************************************************************************************************
   119  
   120  #### Math operation on array
   121  {% endraw %}