This site is supported by donations to The OEIS Foundation.
Template:Sgn
From OeisWiki
The following documentation is located at Template:Sgn/doc. [<Edit> Template:Sgn/doc]
[⧼Purge⧽ Template:Sgn]
[⧼Purge⧽ Template:Sgn]
The {{sgn}} mathematical function template for the signum function returns the sign of a number, i.e. -1 for negative real numbers, 0 for zero and +1 for positive real numbers, otherwise returns an error message.
Contents
Usage
- {{sgn|a real number}}
Valid input
An unformatted real number.
Examples
Examples with valid input
Code Result Comment {{sgn|6}} 1 {{sgn|-0}} 0 {{sgn|0}} 0 {{sgn|+0}} 0 {{sgn|-6}} -1 {{sgn|-6.9e-45}} -1 {{sgn|-6.9E+45}} -1 {{sgn| {{formatnum: 6,500|R}} }} 1 (Cf. Formatted numbers)
Examples with invalid input (returns error message)
Code Result Comment {{sgn|6,500}} Sgn error: Argument is not a real number (Cf. Formatted numbers) {{sgn}} Sgn error: Argument is not a real number {{sgn|blob}} Sgn error: Argument is not a real number {{sgn|6 blobs}} Sgn error: Argument is not a real number
Code
{{ifnum| {{{1|NAN}}} | {{#ifexpr: ({{{1}}}) = 0 | 0 | {{#ifexpr: abs ({{{1}}}) = ({{{1}}}) | 1 | -1 }} }} | {{error|Sgn error: Argument is not a real number }} }}