Difference between revisions of "User:Trang Oul/Sandbox/Template:Range/Signed"
< User:Trang Oul | Sandbox | Template:Range
Jump to navigation
Jump to search
| Line 1: | Line 1: | ||
<noinclude> | <noinclude> | ||
| − | Usage | + | == Usage == |
| + | <code><nowiki>{{Range/Signed|min|max}}</nowiki></code> | ||
| − | + | == 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 == | ||
| + | {| 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({{{ | + | | -({{#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. |