This site is supported by donations to The OEIS Foundation.

Template:Sgn/doc

From OeisWiki
Jump to: navigation, search

This documentation subpage contains instructions, categories, or other information for Template:Sgn. [<Edit> Template:Sgn]

[⧼Purge⧽ Template:Sgn/doc]

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.

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 }} 
}}

See also

  • {{abs}} (or the abs operator) to obtain the absolute value of a real number
  • {{sgn}} (note that the sgn operator is not supported) to obtain the sign of a real number