User:Trang Oul/Sandbox/Template:Range

From Basin Wiki
Jump to navigation Jump to search

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)