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: <code><nowiki>{{Range/Signed|min|max}}</nowiki></code>
+
== Usage ==
 +
<code><nowiki>{{Range/Signed|min|max}}</nowiki></code>
  
−
Examples:
+
== Description ==
−
* ++: {{User:Trang Oul/Sandbox/Template:Range/Signed|1|2}}
+
This template formats a range using signed arithmetic. It handles three cases depending on whether the boundaries are positive, negative, or have different signs.
−
* 0+: {{User:Trang Oul/Sandbox/Template:Range/Signed|0|2}}
+
 
−
* -+: {{User:Trang Oul/Sandbox/Template:Range/Signed|-1|2}}
+
* **Both boundaries are non-negative:** Displays the difference as a positive expression.
−
* -0: {{User:Trang Oul/Sandbox/Template:Range/Signed|-1|0}}
+
* **Both boundaries are non-positive:** Displays the difference between their absolute values, with the larger absolute value first.
−
* --: {{User:Trang Oul/Sandbox/Template:Range/Signed|-2|-1}}
+
* **Mixed signs:** Displays the original boundaries as a subtraction, preserving their signs.
 +
 
 +
== Examples ==
 +
{| class="wikitable"
 +
! Code
 +
! Result
 +
! Description
 +
|-
 +
| <code><nowiki>{{Range/Signed|10|30}}</nowiki></code>
 +
| {{User:Trang Oul/Sandbox/Template:Range/Signed|10|30}}
 +
| Both boundaries are positive.
 +
|-
 +
| <code><nowiki>{{Range/Signed|0|30}}</nowiki></code>
 +
| {{User:Trang Oul/Sandbox/Template:Range/Signed|0|30}}
 +
| Starts at zero.
 +
|-
 +
| <code><nowiki>{{Range/Signed|-30|-10}}</nowiki></code>
 +
| {{User:Trang Oul/Sandbox/Template:Range/Signed|-30|-10}}
 +
| Both boundaries are negative; absolute values are ordered from smaller to larger.
 +
|-
 +
| <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({{{1}}}) }}-{{#expr: abs({{{2}}}) }})
+
       | -({{#expr: abs({{{2}}}) }}-{{#expr: abs({{{1}}}) }})
 
       | (({{{1}}})-(+{{{2}}}))
 
       | (({{{1}}})-(+{{{2}}}))
 
     }}
 
     }}
 
}}</includeonly>
 
}}</includeonly>

Revision as of 19:51, 4 November 2026

Usage

{{Range/Signed|min|max}}

Description

This template formats a range using signed arithmetic. It handles three cases depending on whether the boundaries are positive, negative, or have different signs.

  • **Both boundaries are non-negative:** Displays the difference as a positive expression.
  • **Both boundaries are non-positive:** Displays the difference between their absolute values, with the larger absolute value first.
  • **Mixed signs:** Displays the original boundaries as a subtraction, preserving their signs.

Examples

Code Result Description
{{Range/Signed|10|30}} +(10-30) Both boundaries are positive.
{{Range/Signed|0|30}} +(0-30) Starts at zero.
{{Range/Signed|-30|-10}} -(10-30) Both boundaries are negative; absolute values are ordered from smaller to larger.
{{Range/Signed|-10|0}} -(0-10) Ends at zero.
{{Range/Signed|-30|10}} ((-30)-(+10)) Mixed signs.