1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-18 11:29:55 +00:00
TiddlyWiki5/editions/tw5.com/tiddlers/filters/Mathematics Operators.tid
Mario Pietsch a49436160d
Improve Filter Syntax documentation (#7368)
* Improve Filter Syntax documentaion / navigation

* update links and missing diagrams

* rename legacy prefix to shortcut prefix

* Update editions/tw5.com/tiddlers/filters/Filter Operators.tid

Co-authored-by: yaisog <m@rcuswinter.de>

* Update editions/tw5.com/tiddlers/filters/syntax/And Filter Run Prefix.tid

Co-authored-by: yaisog <m@rcuswinter.de>

* Update editions/tw5.com/tiddlers/filters/syntax/Sort Filter Run Prefix.tid

Co-authored-by: yaisog <m@rcuswinter.de>

* Update editions/tw5.com/tiddlers/filters/syntax/Sort Filter Run Prefix.tid

Co-authored-by: yaisog <m@rcuswinter.de>

* Update editions/tw5.com/tiddlers/filters/syntax/Sort Filter Run Prefix.tid

Co-authored-by: yaisog <m@rcuswinter.de>

* Update editions/tw5.com/tiddlers/filters/syntax/Cascade Filter Run Prefix.tid

Co-authored-by: yaisog <m@rcuswinter.de>

* Update editions/tw5.com/tiddlers/filters/syntax/And Filter Run Prefix.tid

Co-authored-by: yaisog <m@rcuswinter.de>

* add most changes a suggested by yaisog

* fix copy / paste from-version

* replace operand with parameter in the docs

* fix typo

* fix typos and improve railroad diagrams consistency

* move "new from version" info for filter run prefixes below the table

* fix typo transclusion and substitution

* Move Filters tiddler to the top level in the TOC

* wip-breadcrumbs

* breadcrumbs & breadcrumbsList macro final

* remove files that do not belong to this PR

* restore release banner

* add simple / story mode to breadcrumbs

* .breadcrumbs macro update comments

* new breadcrumbs CSS, woks with small screens

* make CSS configurable using hidden-settings

* improve CSS fro small screens

* remove the initial: recursiveParentTag macro

* improve location info for breadcrumbs nav. add "alt-text" for Edge ::after element

* breadcrumbs add mode=field

* bc add initial docs

* breadcrumbsField will also respect the story ordering

* add configurable global filterMode setting

* improve arrow CSS for browser zooming

* add bc links use bc-caption if caption field is non-empty

* breadcrumbs improve comments

* breadcrumbs aria-lable uses caption if there is one

* breadcrumbs improve documentation

* breadcrumbs improve docs for sort param

* fix showArrows docs

* remove .bc-link aria-label .. it's not needed if caption is resolved properly

* use subfilter instead of enlist to evaluate the "excluded" variable. Be consistent with toc-macros

* remove breadcrumbs macros - they have their own PR now

* resolve conflict

* add back doc-macros tiddler

* integrate :then filter run prefix

* remove .breadcrumbs macros and their config tiddlers

* fix typos as requested

---------

Co-authored-by: yaisog <m@rcuswinter.de>
2024-02-14 17:20:32 +01:00

65 lines
2.8 KiB
Plaintext

created: 20190206140446821
modified: 20230321133008898
tags: Filters
title: Mathematics Operators
type: text/vnd.tiddlywiki
<<.from-version "5.1.20">>The mathematics filter operators allow numerical calculations to be performed within filters.
! Using mathematics operators
The mathematics operators interpret their arguments as numbers according to the following rules:
* Any non-numeric characters after a valid number are ignored (e.g. `28px` is interpreted as the number 28)
* If the argument cannot be interpreted as a number, the value 0 is used (e.g. `foo` is interpreted as the number 0)
* The special values `Infinity` and `-Infinity` can be used to represent positive and negative infinity respectively
<$macrocall $name=".warning" _="Some filter operators remove duplicate items which can cause unexpected results when using the mathematics operators. See [[Dominant Append]] for details."/>
The mathematics operators take three different forms:
* ''Unary operators'' apply an operation to each number in the input list (e.g. negate, truncate, sign)
** <<.inline-operator-example "=1 =2 =3 =4 +[negate[]]">>
** <<.inline-operator-example "=1.2 =2.4 =3.6 =4.8 +[trunc[]]">>
** <<.inline-operator-example "=1.2 =2.4 =3.6 =4.8 +[round[]]">>
* ''Binary operators'' apply an operation and parameter to each number in the input list (e.g. add, multiply, remainder)
** <<.inline-operator-example "=1 =2 =3 =4 +[add[3]]">>
** <<.inline-operator-example "=1 =2 =3 =4 +[multiply[8]]">>
* ''Reducing operators'' apply an operation to all of the numbers in the input list, returning a single result (e.g. sum, product)
** <<.inline-operator-example "=1 =2 =3 =4 +[sum[]]">>
** <<.inline-operator-example "=1 =2 =3 =4 +[product[]]">>
** <<.inline-operator-example "=1 =2 =3 =4 +[average[]]">>
! Operations Combination
Operations can be combined by concatenating them while merging the inner `][` characters.
* <<.inline-operator-example "[[355]divide[113]fixed[5]]">>
* <<.inline-operator-example "[range[100]sum[]divide[100]]">>
* <<.inline-operator-example "[tag[HelloThere]get[text]length[]sum[]]">>
Complex operations will sometimes need to be split up into separate filters. For example, to compute the average length of the text field of tiddlers tagged "~HelloThere":
<$macrocall $name='wikitext-example-without-html'
src="""<$set name="number-of-tiddlers" value={{{ [tag[HelloThere]count[]] }}}>
Average length of <$text text=<<number-of-tiddlers>>/> tiddlers tagged <<tag "HelloThere">>: <$text text={{{ [tag[HelloThere]get[text]length[]sum[]divide<number-of-tiddlers>fixed[3]] }}}/>
</$set>""" />
! Mathematics Operators list
<table>
<tr>
<th align="left">Operator</th>
<th align="left">Purpose</th>
</tr>
<$list filter="[tag[Mathematics Operators]sort[caption]]">
<tr>
<td><$link>{{!!caption}}</$link></td>
<td>{{!!op-purpose}}</td>
</tr>
</$list>
</table>