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

From Basin Wiki
Jump to navigation Jump to search
 
Line 1: Line 1:
 
<noinclude>
 
<noinclude>
 
== Usage ==
 
== Usage ==
 +
 
<code><nowiki>{{Range/Signed|min|max}}</nowiki></code>
 
<code><nowiki>{{Range/Signed|min|max}}</nowiki></code>
  
−
== Description ==
+
== Parameters ==
−
This template formats a range using signed arithmetic. It handles three cases depending on whether the boundaries are positive, negative, or have different signs.
+
 
 +
{| class="wikitable"
 +
! Parameter
 +
! Description
 +
! Default
 +
|-
 +
| <code>1</code> (<code>min</code>)
 +
| The lower bound of the range.
 +
|
 +
|-
 +
| <code>2</code> (<code>max</code>)
 +
| The upper bound of the range.
 +
|
 +
|}
 +
 
 +
== Behavior ==
 +
 
 +
This template formats a range using the two bounds <code>min</code> and <code>max</code>. It expects <code>min</code> to be less than or equal to <code>max</code>.
  
−
* **Both boundaries are non-negative:** Displays the difference as a positive expression.
+
* '''Non-negative range (<code>min</code> ≥ 0):''' Encloses the range in parentheses and prefixes it with a leading <code>+</code> sign. Both boundaries retain their original parameter order.
−
* **Both boundaries are non-positive:** Displays the difference between their absolute values, with the larger absolute value first.
+
* '''Non-positive range (<code>max</code> ≤ 0):''' Displays the absolute values of both boundaries in reverse parameter order (<code>max</code> before <code>min</code>), enclosing the range in parentheses and prefixing it with a leading <code>-</code> sign.
−
* **Mixed signs:** Displays the original boundaries as a subtraction, preserving their signs.
+
* '''Mixed-sign range (otherwise):''' Encloses the range and each boundary in parentheses, preserving the original parameter order and marking the positive maximum with a leading <code>+</code> sign.
  
 
== Examples ==
 
== Examples ==
 +
 
{| class="wikitable"
 
{| class="wikitable"
−
! Code
+
! Input
 
! Result
 
! Result
 
! Description
 
! Description
Line 22: Line 41:
 
| <code><nowiki>{{Range/Signed|0|30}}</nowiki></code>
 
| <code><nowiki>{{Range/Signed|0|30}}</nowiki></code>
 
| {{User:Trang Oul/Sandbox/Template:Range/Signed|0|30}}
 
| {{User:Trang Oul/Sandbox/Template:Range/Signed|0|30}}
−
| Starts at zero.
+
| Minimum is zero and maximum is positive.
 +
|-
 +
| <code><nowiki>{{Range/Signed|-30|10}}</nowiki></code>
 +
| {{User:Trang Oul/Sandbox/Template:Range/Signed|-30|10}}
 +
| Minimum is negative and maximum is positive.
 +
|-
 +
| <code><nowiki>{{Range/Signed|-30|0}}</nowiki></code>
 +
| {{User:Trang Oul/Sandbox/Template:Range/Signed|-30|0}}
 +
| Minimum is negative and maximum is zero.
 
|-
 
|-
 
| <code><nowiki>{{Range/Signed|-30|-10}}</nowiki></code>
 
| <code><nowiki>{{Range/Signed|-30|-10}}</nowiki></code>
 
| {{User:Trang Oul/Sandbox/Template:Range/Signed|-30|-10}}
 
| {{User:Trang Oul/Sandbox/Template:Range/Signed|-30|-10}}
−
| Both boundaries are negative; absolute values are ordered from smaller to larger.
+
| Both boundaries are negative.
−
|-
 
−
| <code><nowiki>{{Range/Signed|-10|0}}</nowiki></code>
 
−
| {{User:Trang Oul/Sandbox/Template:Range/Signed|-10|0}}
 
−
| Ends at zero.
 
−
|-
 
−
| <code><nowiki>{{Range/Signed|-30|10}}</nowiki></code>
 
−
| {{User:Trang Oul/Sandbox/Template:Range/Signed|-30|10}}
 
−
| Mixed signs.
 
 
|}
 
|}
 
</noinclude><includeonly>{{#ifexpr: {{{1}}} >= 0
 
</noinclude><includeonly>{{#ifexpr: {{{1}}} >= 0
−
  | +({{{1}}}-{{{2}}})
+
| +({{{1}}}-{{{2}}})
−
  | {{#ifexpr: {{{2}}} <= 0
+
| {{#ifexpr: {{{2}}} <= 0
−
      | -({{#expr: abs({{{2}}}) }}-{{#expr: abs({{{1}}}) }})
+
  | -({{#expr: abs({{{2}}}) }}-{{#expr: abs({{{1}}}) }})
−
      | (({{{1}}})-(+{{{2}}}))
+
  | (({{{1}}})-(+{{{2}}}))
−
    }}
+
  }}
 
}}</includeonly>
 
}}</includeonly>

Latest revision as of 20:30, 4 November 2026

Usage

{{Range/Signed|min|max}}

Parameters

Parameter Description Default
1 (min) The lower bound of the range.
2 (max) The upper bound of the range.

Behavior

This template formats a range using the two bounds min and max. It expects min to be less than or equal to max.

  • Non-negative range (min ≥ 0): Encloses the range in parentheses and prefixes it with a leading + sign. Both boundaries retain their original parameter order.
  • Non-positive range (max ≤ 0): Displays the absolute values of both boundaries in reverse parameter order (max before min), enclosing the range in parentheses and prefixing it with a leading - sign.
  • Mixed-sign range (otherwise): Encloses the range and each boundary in parentheses, preserving the original parameter order and marking the positive maximum with a leading + sign.

Examples

Input Result Description
{{Range/Signed|10|30}} +(10-30) Both boundaries are positive.
{{Range/Signed|0|30}} +(0-30) Minimum is zero and maximum is positive.
{{Range/Signed|-30|10}} ((-30)-(+10)) Minimum is negative and maximum is positive.
{{Range/Signed|-30|0}} -(0-30) Minimum is negative and maximum is zero.
{{Range/Signed|-30|-10}} -(10-30) Both boundaries are negative.