Difference between revisions of "User:Trang Oul/Sandbox/Template:Range"

From Basin Wiki
Jump to navigation Jump to search
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
<noinclude>
 
<noinclude>
−
Usage: <code><nowiki>{{Range|[value]|[min]|[max]|[signed=0]}}</nowiki></code>
+
== Usage ==
  
−
Examples:
+
<code><nowiki>{{Range|value|min|max|left=|right=|signed=0}}</nowiki></code>
−
<code>value</code> param:
 
−
* + us: {{User:Trang Oul/Sandbox/Template:Range|1||}}
 
−
* 0 us: {{User:Trang Oul/Sandbox/Template:Range|0||}}
 
−
* us: {{User:Trang Oul/Sandbox/Template:Range|-1||}}
 
  
−
<code>min</code> and <code>max</code> params, equal:
+
The template displays a number or a range of numbers, with optional arithmetic transformations and signed formatting.
−
* + us: {{User:Trang Oul/Sandbox/Template:Range||1|1}}
 
−
* 0 us: {{User:Trang Oul/Sandbox/Template:Range||0|0}}
 
−
* us: {{User:Trang Oul/Sandbox/Template:Range||-1|-1}}
 
  
 +
== Parameters ==
  
−
* + s: {{User:Trang Oul/Sandbox/Template:Range||1|1|signed=1}}
+
{| class="wikitable"
−
* 0 s: {{User:Trang Oul/Sandbox/Template:Range||0|0|signed=1}}
+
! Parameter
−
* s: {{User:Trang Oul/Sandbox/Template:Range||-1|-1|signed=1}}
+
! Description
 +
! Default
 +
|-
 +
| <code>1</code> (<code>value</code>)
 +
| A single value to display. Takes precedence over <code>min</code> and <code>max</code> when provided.
 +
|
 +
|-
 +
| <code>2</code> (<code>min</code>)
 +
| The lower bound of the range.
 +
|
 +
|-
 +
| <code>3</code> (<code>max</code>)
 +
| The upper bound of the range.
 +
|
 +
|-
 +
| <code>left</code>
 +
| An optional arithmetic expression placed before each value. Uses the syntax supported by <code>#expr</code>.
 +
|
 +
|-
 +
| <code>right</code>
 +
| An optional arithmetic expression placed after each value. Uses the syntax supported by <code>#expr</code>.
 +
|
 +
|-
 +
| <code>signed</code>
 +
| Set to <code>1</code> to display explicit positive signs and use signed range formatting.
 +
| <code>0</code>
 +
|}
  
 +
== Behavior ==
  
−
* ++ us: {{User:Trang Oul/Sandbox/Template:Range||1|2}}
+
* When <code>value</code> is provided, the template displays a single value.
−
* 0+ us: {{User:Trang Oul/Sandbox/Template:Range|||0|2}}
+
* Otherwise, <code>min</code> and <code>max</code> define the range.
−
* -+ us: {{User:Trang Oul/Sandbox/Template:Range|-1|2}}
+
* When <code>min</code> and <code>max</code> are equal, the template displays a single value instead of a range.
−
* -0 us: {{User:Trang Oul/Sandbox/Template:Range||-1|0}}
+
* When either <code>left</code> or <code>right</code> is provided, the resulting arithmetic expression is evaluated for the value or for both range boundaries.
−
* -- us {{User:Trang Oul/Sandbox/Template:Range||-2|-1}}
+
* When <code>signed=1</code>, positive values are displayed with an explicit <code>+</code> sign.
  
 +
== Examples ==
  
−
* ++ s: {{User:Trang Oul/Sandbox/Template:Range||1|2|signed=1}}
+
=== Single values ===
−
* 0+ s: {{User:Trang Oul/Sandbox/Template:Range||0|2|signed=1}}
+
 
−
* -+ s: {{User:Trang Oul/Sandbox/Template:Range||-1|2|signed=1}}
+
The first positional parameter specifies a single value.
−
* -0 s: {{User:Trang Oul/Sandbox/Template:Range||-1|0|signed=1}}
+
 
−
* -- s {{User:Trang Oul/Sandbox/Template:Range||-2|-1|signed=1}}
+
{| class="wikitable"
−
</noinclude><includeonly>{{#ifexpr: 0{{{1|0}}} != 0
+
! Input
 +
! Unsigned
 +
! Signed
 +
|-
 +
| <code><nowiki>{{Range|1}}</nowiki></code>
 +
| {{User:Trang Oul/Sandbox/Template:Range|1}}
 +
| {{User:Trang Oul/Sandbox/Template:Range|1|signed=1}}
 +
|-
 +
| <code><nowiki>{{Range|0}}</nowiki></code>
 +
| {{User:Trang Oul/Sandbox/Template:Range|0}}
 +
| {{User:Trang Oul/Sandbox/Template:Range|0|signed=1}}
 +
|-
 +
| <code><nowiki>{{Range|-1}}</nowiki></code>
 +
| {{User:Trang Oul/Sandbox/Template:Range|-1}}
 +
| {{User:Trang Oul/Sandbox/Template:Range|-1|signed=1}}
 +
|}
 +
 
 +
=== Ranges ===
 +
 
 +
The second and third positional parameters specify the minimum and maximum values, respectively.
 +
 
 +
==== Equal boundaries ====
 +
 
 +
When both boundaries are equal, a single value is displayed.
 +
 
 +
{| class="wikitable"
 +
! Input
 +
! Unsigned
 +
! Signed
 +
|-
 +
| <code><nowiki>{{Range||1|1}}</nowiki></code>
 +
| {{User:Trang Oul/Sandbox/Template:Range||1|1}}
 +
| {{User:Trang Oul/Sandbox/Template:Range||1|1|signed=1}}
 +
|-
 +
| <code><nowiki>{{Range||0|0}}</nowiki></code>
 +
| {{User:Trang Oul/Sandbox/Template:Range||0|0}}
 +
| {{User:Trang Oul/Sandbox/Template:Range||0|0|signed=1}}
 +
|-
 +
| <code><nowiki>{{Range||-1|-1}}</nowiki></code>
 +
| {{User:Trang Oul/Sandbox/Template:Range||-1|-1}}
 +
| {{User:Trang Oul/Sandbox/Template:Range||-1|-1|signed=1}}
 +
|}
 +
 
 +
==== Different boundaries ====
 +
 
 +
{| class="wikitable"
 +
! Input
 +
! Unsigned
 +
! Signed
 +
|-
 +
| <code><nowiki>{{Range||1|2}}</nowiki></code>
 +
| {{User:Trang Oul/Sandbox/Template:Range||1|2}}
 +
| {{User:Trang Oul/Sandbox/Template:Range||1|2|signed=1}}
 +
|-
 +
| <code><nowiki>{{Range||0|2}}</nowiki></code>
 +
| {{User:Trang Oul/Sandbox/Template:Range||0|2}}
 +
| {{User:Trang Oul/Sandbox/Template:Range||0|2|signed=1}}
 +
|-
 +
| <code><nowiki>{{Range||-1|2}}</nowiki></code>
 +
| {{User:Trang Oul/Sandbox/Template:Range||-1|2}}
 +
| {{User:Trang Oul/Sandbox/Template:Range||-1|2|signed=1}}
 +
|-
 +
| <code><nowiki>{{Range||-1|0}}</nowiki></code>
 +
| {{User:Trang Oul/Sandbox/Template:Range||-1|0}}
 +
| {{User:Trang Oul/Sandbox/Template:Range||-1|0|signed=1}}
 +
|-
 +
| <code><nowiki>{{Range||-2|-1}}</nowiki></code>
 +
| {{User:Trang Oul/Sandbox/Template:Range||-2|-1}}
 +
| {{User:Trang Oul/Sandbox/Template:Range||-2|-1|signed=1}}
 +
|}
 +
 
 +
=== Arithmetic transformations ===
 +
 
 +
The <code>left</code> and <code>right</code> parameters allow arithmetic expressions to be applied to the supplied values. They can be used independently or together.
 +
 
 +
==== Left parameter ====
 +
 
 +
The <code>left</code> parameter inserts an expression before the value.
 +
 
 +
Example: calculate the reciprocal of a value.
 +
 
 +
<code><nowiki>{{Range|4|left=1/}}</nowiki></code>
 +
 
 +
Result: {{User:Trang Oul/Sandbox/Template:Range|4|left=1/}}
 +
 
 +
==== Right parameter ====
 +
 
 +
The <code>right</code> parameter inserts an expression after the value.
 +
 
 +
Example: divide a value by 25 to convert frames into seconds.
 +
 
 +
<code><nowiki>{{Range|75|right=/25}}</nowiki></code>
 +
 
 +
Result: {{User:Trang Oul/Sandbox/Template:Range|75|right=/25}}
 +
 
 +
==== Both parameters ====
 +
 
 +
Both parameters can be combined to construct more complex expressions.
 +
 
 +
Example: subtract 10 from the value and divide the result by 25.
 +
 
 +
<code><nowiki>{{Range|75|left=(|right=-10)/25}}</nowiki></code>
 +
 
 +
Result: {{User:Trang Oul/Sandbox/Template:Range|75|left=(|right=-10)/25}}
 +
 
 +
Example: multiply the value by 2, subtract 10, and divide the result by 25.
 +
 
 +
<code><nowiki>{{Range|75|left=(2*|right=-10)/25}}</nowiki></code>
 +
 
 +
Result: {{User:Trang Oul/Sandbox/Template:Range|75|left=(2*|right=-10)/25}}
 +
 
 +
==== Transforming a range ====
 +
 
 +
Arithmetic transformations are applied independently to both range boundaries.
 +
 
 +
Example: convert a duration of 50–75 frames into seconds, assuming 25 frames per second.
 +
 
 +
<code><nowiki>{{Range||50|75|right=/25}}</nowiki></code>
 +
 
 +
Result: {{User:Trang Oul/Sandbox/Template:Range||50|75|right=/25}}
 +
 
 +
The result is 2–3 seconds.
 +
 
 +
Example: convert a duration of 40–90 frames into seconds and round both boundaries to two decimal places.
 +
 
 +
<code><nowiki>{{Range||40|90|right=/25 round 2}}</nowiki></code>
 +
 
 +
Result: {{User:Trang Oul/Sandbox/Template:Range||40|90|right=/25 round 2}}
 +
 
 +
==== Signed output ====
 +
 
 +
The <code>signed</code> parameter can also be combined with arithmetic transformations.
 +
 
 +
Example: calculate the per-level bonus for bonuses ranging from 4 to 12, using a factor of 1/8 per bonus point.
 +
 
 +
<code><nowiki>{{Range||4|12|right=/8|signed=1}}</nowiki></code>
 +
 
 +
Result: {{User:Trang Oul/Sandbox/Template:Range||4|12|right=/8|signed=1}}
 +
</noinclude><includeonly>{{#if: {{{1|}}}
 
| {{#ifexpr: {{{signed|0}}}
 
| {{#ifexpr: {{{signed|0}}}
−
| {{User:Trang Oul/Sandbox/Template:Signed number|{{{1}}}|signed=1}}
+
| {{User:Trang Oul/Sandbox/Template:Signed number|{{#if: {{{left|}}}{{{right|}}} | {{#expr: {{{left|}}} ({{{1}}}) {{{right|}}} }} | {{{1}}} }}|signed=1}}
−
| {{{1}}}
+
| {{#if: {{{left|}}}{{{right|}}} | {{#expr: {{{left|}}} ({{{1}}}) {{{right|}}} }} | {{{1}}} }}
 
}}
 
}}
−
| {{#ifexpr: {{{2}}} = {{{3}}}
+
| {{#ifeq: {{{2}}} | {{{3}}}
 
| {{#ifexpr: {{{signed|0}}}
 
| {{#ifexpr: {{{signed|0}}}
−
| {{User:Trang Oul/Sandbox/Template:Signed number|{{{2}}}|signed=1}}
+
| {{User:Trang Oul/Sandbox/Template:Signed number|{{#if: {{{left|}}}{{{right|}}} | {{#expr: {{{left|}}} ({{{2}}}) {{{right|}}} }} | {{{2}}} }}|signed=1}}
−
| {{{2}}}
+
| {{#if: {{{left|}}}{{{right|}}} | {{#expr: {{{left|}}} ({{{2}}}) {{{right|}}} }} | {{{2}}} }}
 
}}
 
}}
 
| {{#ifexpr: {{{signed|0}}}
 
| {{#ifexpr: {{{signed|0}}}
−
| {{User:Trang Oul/Sandbox/Template:Range/Signed|{{{2}}}|{{{3}}}}}
+
| {{User:Trang Oul/Sandbox/Template:Range/Signed|{{#if: {{{left|}}}{{{right|}}} | {{#expr: {{{left|}}} ({{{2}}}) {{{right|}}} }} | {{{2}}} }}|{{#if: {{{left|}}}{{{right|}}} | {{#expr: {{{left|}}} ({{{3}}}) {{{right|}}} }} | {{{3}}} }}}}
−
| {{User:Trang Oul/Sandbox/Template:Range/Unsigned|{{{2}}}|{{{3}}}}}
+
| {{User:Trang Oul/Sandbox/Template:Range/Unsigned|{{#if: {{{left|}}}{{{right|}}} | {{#expr: {{{left|}}} ({{{2}}}) {{{right|}}} }} | {{{2}}} }}|{{#if: {{{left|}}}{{{right|}}} | {{#expr: {{{left|}}} ({{{3}}}) {{{right|}}} }} | {{{3}}} }}}}
 
}}
 
}}
 
}}
 
}}
 
}}</includeonly>
 
}}</includeonly>

Latest revision as of 20:30, 4 November 2026

Usage

{{Range|value|min|max|left=|right=|signed=0}}

The template displays a number or a range of numbers, with optional arithmetic transformations and signed formatting.

Parameters

Parameter Description Default
1 (value) A single value to display. Takes precedence over min and max when provided.
2 (min) The lower bound of the range.
3 (max) The upper bound of the range.
left An optional arithmetic expression placed before each value. Uses the syntax supported by #expr.
right An optional arithmetic expression placed after each value. Uses the syntax supported by #expr.
signed Set to 1 to display explicit positive signs and use signed range formatting. 0

Behavior

  • When value is provided, the template displays a single value.
  • Otherwise, min and max define the range.
  • When min and max are equal, the template displays a single value instead of a range.
  • When either left or right is provided, the resulting arithmetic expression is evaluated for the value or for both range boundaries.
  • When signed=1, positive values are displayed with an explicit + sign.

Examples

Single values

The first positional parameter specifies a single value.

Input Unsigned Signed
{{Range|1}} 1 +1
{{Range|0}} 0 0
{{Range|-1}} -1 -1

Ranges

The second and third positional parameters specify the minimum and maximum values, respectively.

Equal boundaries

When both boundaries are equal, a single value is displayed.

Input Unsigned Signed
{{Range||1|1}} 1 +1
{{Range||0|0}} 0 0
{{Range||-1|-1}} -1 -1

Different boundaries

Input Unsigned Signed
{{Range||1|2}} (1-2) +(1-2)
{{Range||0|2}} (0-2) +(0-2)
{{Range||-1|2}} ((-1)-2) ((-1)-(+2))
{{Range||-1|0}} ((-1)-0) -(0-1)
{{Range||-2|-1}} ((-2)-(-1)) -(1-2)

Arithmetic transformations

The left and right parameters allow arithmetic expressions to be applied to the supplied values. They can be used independently or together.

Left parameter

The left parameter inserts an expression before the value.

Example: calculate the reciprocal of a value.

{{Range|4|left=1/}}

Result: 0.25

Right parameter

The right parameter inserts an expression after the value.

Example: divide a value by 25 to convert frames into seconds.

{{Range|75|right=/25}}

Result: 3

Both parameters

Both parameters can be combined to construct more complex expressions.

Example: subtract 10 from the value and divide the result by 25.

{{Range|75|left=(|right=-10)/25}}

Result: 2.6

Example: multiply the value by 2, subtract 10, and divide the result by 25.

{{Range|75|left=(2*|right=-10)/25}}

Result: 5.6

Transforming a range

Arithmetic transformations are applied independently to both range boundaries.

Example: convert a duration of 50–75 frames into seconds, assuming 25 frames per second.

{{Range||50|75|right=/25}}

Result: (2-3)

The result is 2–3 seconds.

Example: convert a duration of 40–90 frames into seconds and round both boundaries to two decimal places.

{{Range||40|90|right=/25 round 2}}

Result: (1.6-3.6)

Signed output

The signed parameter can also be combined with arithmetic transformations.

Example: calculate the per-level bonus for bonuses ranging from 4 to 12, using a factor of 1/8 per bonus point.

{{Range||4|12|right=/8|signed=1}}

Result: +(0.5-1.5)